feat(primitive): linemultipattern -- match multiple patterns on same line #101

Closed
opened 2026-05-30 18:03:38 +02:00 by michael · 0 comments
Owner

Goal

Add a new primitive daw.fragjan.check.linemultipattern that checks
whether a single line contains multiple patterns simultaneously.

Background

During implementation of DAW/fragjan#77 (detect daw.common reimplementations),
the need for a multi-pattern line check became apparent.

Example: detect io.popen("sha256sum ...") -- both io.popen and sha256
must appear on the same line. Neither pattern nor linepattern supports this:

  • pattern uses plain string search (no wildcard across tokens)
  • linepattern supports only one pattern per check

A new slim primitive that does exactly one thing well is the right solution.

Proposed API

check(target, params) -> result, nil | nil, err
target = { type = "file", path = "...", content = "..." }
params = {
  patterns             = { "io.popen", "sha256" },  -- all must match on same line
  skip_comments        = true,                       -- optional, default false
  normalize_whitespace = false,                      -- optional, default false
}
result = {
  status  = "pass"|"warn",
  metrics = { match_count = N, matches = { {line=N, text="..."}, ... } }
}

Use Cases

  • no-raw-sha256-popen: line contains io.popen AND sha256
  • Any future rule requiring co-occurrence of two tokens on one line

Acceptance Criteria

  • Primitive implemented as daw.fragjan.check.linemultipattern
  • All patterns must match on the same line (AND semantics)
  • skip_comments supported
  • normalize_whitespace supported
  • Registered via daw_register
  • no-raw-sha256-popen rule updated to use new primitive
  • Tested against DAW/fragjan#77 test file
## Goal Add a new primitive `daw.fragjan.check.linemultipattern` that checks whether a single line contains multiple patterns simultaneously. ## Background During implementation of DAW/fragjan#77 (detect daw.common reimplementations), the need for a multi-pattern line check became apparent. Example: detect `io.popen("sha256sum ...")` -- both `io.popen` and `sha256` must appear on the same line. Neither `pattern` nor `linepattern` supports this: - `pattern` uses plain string search (no wildcard across tokens) - `linepattern` supports only one pattern per check A new slim primitive that does exactly one thing well is the right solution. ## Proposed API ``` check(target, params) -> result, nil | nil, err target = { type = "file", path = "...", content = "..." } params = { patterns = { "io.popen", "sha256" }, -- all must match on same line skip_comments = true, -- optional, default false normalize_whitespace = false, -- optional, default false } result = { status = "pass"|"warn", metrics = { match_count = N, matches = { {line=N, text="..."}, ... } } } ``` ## Use Cases - `no-raw-sha256-popen`: line contains `io.popen` AND `sha256` - Any future rule requiring co-occurrence of two tokens on one line ## Acceptance Criteria - [ ] Primitive implemented as `daw.fragjan.check.linemultipattern` - [ ] All patterns must match on the same line (AND semantics) - [ ] `skip_comments` supported - [ ] `normalize_whitespace` supported - [ ] Registered via `daw_register` - [ ] `no-raw-sha256-popen` rule updated to use new primitive - [ ] Tested against DAW/fragjan#77 test file
michael added this to the Basic Version milestone 2026-05-30 21:18: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#101
No description provided.