Skip to content

Commit fc10806

Browse files
ZviBaratzSolomon
andauthored
fix(ego-lint): skip JSDoc block comments in R-WEB-06 document.* check (#150)
## Summary - Add `skip-comments: true` to R-WEB-06 (`\bdocument\.` pattern) so it no longer matches inside JSDoc `/** ... */` block comments or `//` single-line comments - No new infrastructure needed — `apply-patterns.py` already supports `skip-comments: true` with full block-comment state tracking ## Motivation Field testing forge (2026-03-22) surfaced a false positive: ``` lib/css/index.js:439: DOM APIs (document.*) are not available in GJS ``` Line 439 is a JSDoc comment: `* Parse document.` — the word appears as English prose in a vendored CSS parser (`reworkcss/css`), not as actual DOM API usage. The file contains zero real `document.*` calls, making this a pure false positive. ## Test Plan - Updated `tests/fixtures/web-apis/extension.js` with a JSDoc comment containing `document.` (lines 3–6) plus the existing real `document.querySelector()` call - Added `assert_output_count` assertion verifying R-WEB-06 fires **exactly once** (real call only, JSDoc skipped) - Baseline: 567 passed, 125 failed → after fix: 568 passed, 125 failed (+1 pass, 0 new failures) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Solomon <sol@nanoclaw.dev>
1 parent 715519f commit fc10806

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

rules/patterns.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
pattern: "\\bdocument\\."
6767
scope: ["*.js"]
6868
severity: blocking
69+
skip-comments: true
6970
message: "DOM APIs (document.*) are not available in GJS"
7071
category: web-apis
7172
fix: "GJS has no DOM. Use GObject/Clutter/St/GTK widgets instead."

tests/fixtures/web-apis/extension.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import {Extension} from 'resource:///org/gnome/shell/extensions/extension.js';
22

3+
/**
4+
* Parse document.querySelectorAll results into an array.
5+
* This is a JSDoc comment — document. here must NOT trigger R-WEB-06.
6+
*/
37
export default class WebApisExtension extends Extension {
48
enable() {
59
setTimeout(() => {}, 100);
610
const xhr = new XMLHttpRequest();
7-
document.querySelector('.foo');
11+
document.querySelector('.foo'); // real DOM call — MUST trigger R-WEB-06
812
clearTimeout(this._timer);
913
clearInterval(this._interval);
1014
}

tests/run-tests.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ assert_exit_code "exits with 1 (has failures)" 1
123123
assert_output_contains "fails on setTimeout" "\[FAIL\].*R-WEB-01"
124124
assert_output_contains "fails on XMLHttpRequest" "\[FAIL\].*R-WEB-04"
125125
assert_output_contains "fails on document.*" "\[FAIL\].*R-WEB-06"
126+
assert_output_count "R-WEB-06 fires exactly once (JSDoc comment skipped)" "\[FAIL\].*R-WEB-06" 1
126127
assert_output_contains "fails on clearTimeout" "\[FAIL\].*R-WEB-10"
127128
assert_output_contains "fails on clearInterval" "\[FAIL\].*R-WEB-11"
128129
echo ""

0 commit comments

Comments
 (0)