feat(rules): detect explicit error discard pattern (, _ =) #45

Closed
opened 2026-05-25 13:42:24 +02:00 by michael · 2 comments
Owner

Goal

fragjan should detect explicit error discards via the _, _ = or , _ =
pattern in Lua assignments. This is the canonical way errors get silently
dropped in DAW code.

Pattern

local u, _ = mod.build_usage(roots)   -- error discarded
local ok, _ = pcall(fn)               -- error discarded

Approach

The pattern primitive with contains on , _ = covers the common case.
False positives are possible (legitimate single-value ignores) but rare
enough to start with warn severity.

Acceptance criteria

  • Rule detects , _ = assignments
  • Severity: warn
  • Added to daw-code pack
## Goal fragjan should detect explicit error discards via the `_, _ =` or `, _ =` pattern in Lua assignments. This is the canonical way errors get silently dropped in DAW code. ## Pattern ```lua local u, _ = mod.build_usage(roots) -- error discarded local ok, _ = pcall(fn) -- error discarded ``` ## Approach The pattern primitive with `contains` on `, _ =` covers the common case. False positives are possible (legitimate single-value ignores) but rare enough to start with warn severity. ## Acceptance criteria - [ ] Rule detects `, _ =` assignments - [ ] Severity: warn - [ ] Added to daw-code pack
Author
Owner

Additional cases in core/detect.lua:

detect_name() discards fs.read_file errors three times (main.lua, hugo.toml,
config.toml, theme.toml) with local content, _ = ...

detect_version() discards fs.read_file error the same way.

Additional cases in core/detect.lua: detect_name() discards fs.read_file errors three times (main.lua, hugo.toml, config.toml, theme.toml) with local content, _ = ... detect_version() discards fs.read_file error the same way.
Author
Owner

Implemented: no-error-discard rule added to daw-lua-code pack.

Rule uses linepattern primitive, contains match on ", _ =", skip_comments: true.
Severity: warn as specified. exclude_if_contains available if false positives emerge.

Implemented: no-error-discard rule added to daw-lua-code pack. Rule uses linepattern primitive, contains match on ", _ =", skip_comments: true. Severity: warn as specified. exclude_if_contains available if false positives emerge.
michael 2026-05-26 15:34:45 +02:00
michael added this to the Basic Version milestone 2026-05-30 16:05:00 +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#45
No description provided.