feat(pattern): add skip_comments parameter to pattern primitive #9

Closed
opened 2026-05-19 10:55:55 +02:00 by michael · 0 comments
Owner

Problem

The pattern primitive matches all lines including comments.
This causes false positives when a pattern appears in a comment
as documentation or example output rather than actual code.

Example: core/reporter.lua line 6 contains io.open in a comment
(-- [ERROR] src/foo.lua:42 -- io.open direkt aufgerufen) and
triggers the no-direct-io rule.

Solution

Add optional skip_comments parameter to the rule YAML (check section).
The primitive filters comment lines before matching when enabled.

Rule example:

check:
  primitive: daw.fragjan.check.pattern
  pattern: "io.open"
  skip_comments: true

Default is false -- existing rules are unaffected.
Comment detection is language-specific; first implementation covers
Lua (-- prefix) and Shell (# prefix), based on file extension.

Affected Files

  • var/modules/fragjan-check-pattern/init.lua -- skip_comments logic
  • var/rules/daw-code/rules/no-direct-io.yaml -- set skip_comments: true

Notes

skip_comments: false (default) keeps current behavior.
Rules that intentionally scan comments (e.g. version strings,
annotations) simply omit the parameter or set it to false.
Language detection via file extension is sufficient for now;
a comment_prefix override parameter can be added later if needed.

## Problem The pattern primitive matches all lines including comments. This causes false positives when a pattern appears in a comment as documentation or example output rather than actual code. Example: `core/reporter.lua` line 6 contains `io.open` in a comment (`-- [ERROR] src/foo.lua:42 -- io.open direkt aufgerufen`) and triggers the no-direct-io rule. ## Solution Add optional `skip_comments` parameter to the rule YAML (check section). The primitive filters comment lines before matching when enabled. Rule example: ```yaml check: primitive: daw.fragjan.check.pattern pattern: "io.open" skip_comments: true ``` Default is `false` -- existing rules are unaffected. Comment detection is language-specific; first implementation covers Lua (`--` prefix) and Shell (`#` prefix), based on file extension. ## Affected Files - `var/modules/fragjan-check-pattern/init.lua` -- skip_comments logic - `var/rules/daw-code/rules/no-direct-io.yaml` -- set skip_comments: true ## Notes `skip_comments: false` (default) keeps current behavior. Rules that intentionally scan comments (e.g. version strings, annotations) simply omit the parameter or set it to false. Language detection via file extension is sufficient for now; a `comment_prefix` override parameter can be added later if needed.
michael added this to the Basic Version milestone 2026-05-30 16:05:10 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
DAW/fragjan#9
No description provided.