@voidh4x0r/slopgate 0.1.3 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -9,6 +9,34 @@ All notable changes to this project are documented here. The format follows [Kee
9
9
  - Go and Rust grammars.
10
10
  - VS Code diagnostics.
11
11
 
12
+ ## [0.1.5] - 2026-11-22
13
+
14
+ ### Fixed
15
+ - `ts/noop-test` reports a single test-callback parameter passed to a helper (`(t) => runSuite(t)`) as medium (“assertions may be delegated”) instead of high. Multi-parameter table-driven callbacks are not treated as delegation.
16
+ - `ts/unreachable` skips erased `type`, `interface` and `declare` declarations after a terminator; `enum`, classes, `let`/`const` and initialised `var` still report.
17
+ - `py/swallowed-exception` no longer treats `cleanup`/`refactor`/`next sprint` as blanket noise; only TODO/FIXME/XXX/HACK tags are noise. Comments on the `except` line now count, and inline comments no longer pollute the exception type, so broad handlers keep the “comment explains why” message.
18
+ - `ts/stub-function` reports object-literal arrow properties that throw “Not implemented” at medium confidence, matching class methods.
19
+
20
+ ### Changed
21
+ - 241 tests, including fifth-round regression fixtures for `delegated-assert`, `ts-type-after-return`, `cleanup-word`, `comment-placement` and the conservative `wording` cases.
22
+ - Benchmark unchanged at **29 high-confidence findings across 991,705 lines of CPython, 96.6% labeled precision (28/29), 14/14 seeded defects, 0 high findings on 601 JavaScript files**; `staleLabels: []`, `unlabeledHigh: []`.
23
+ - Docs record the accepted above-`try` wording conservatism (a bare “known bug” stays high by design).
24
+
25
+ ## [0.1.4] - 2026-11-22
26
+
27
+ ### Fixed
28
+ - `ts/noop-test` recognises the Tape/TAP assertion API again (`t.equal`, `t.deepEqual`, `t.strictEqual`, `t.doesNotThrow`, …), fixing a regression introduced in 0.1.1; a framework matrix test now pins the accepted assertion families.
29
+ - `ts/unreachable` no longer reports hoisted `function`/generator declarations or bare `var` statements after a `return`; `let`/`const` and initialised `var` are still reported.
30
+ - `ts/stub-function` reports class-method `throw new Error("Not implemented")` at medium confidence; standalone/exported throw-stubs remain high.
31
+ - `py/stub-body` skips `dummy_multiprocessing/`-style prefixed directories when the module docstring identifies a no-op shim, while `dummy_data/` remains reported.
32
+ - `py/swallowed-exception` only accepts standalone explanatory comments; a trailing comment on a preceding code line no longer demotes. Above-`try` comments need paired failure/intent wording (or a strong phrase such as "harmless"), and TODO/FIXME/refactor comments do not count. Inline comments on the handler line still count.
33
+ - `ts/dead-branch` now has the same nearby-comment demotion as `py/dead-branch`.
34
+
35
+ ### Changed
36
+ - 228 tests, including fourth-round regression fixtures for `tape-assert`, `hoisted-fn`, `assert-forms`, `above-heuristic`, `above-trailing`, `between-asymmetry` and `dummy-dir-shim`.
37
+ - Benchmark unchanged at **29 high-confidence findings across 991,705 lines of CPython, 96.6% labeled precision (28/29), 14/14 seeded defects, 0 high findings on 601 JavaScript files**; `staleLabels: []`, `unlabeledHigh: []`.
38
+ - Docs now state that the nine JS packages do not exercise Tape/TAP or bundled output, and record the Electron-asar corpus findings as the motivation for the 0.2.0 JS corpus expansion.
39
+
12
40
  ## [0.1.3] - 2026-11-22
13
41
 
14
42
  ### Fixed
package/README.md CHANGED
@@ -14,7 +14,7 @@ AI writes code that *looks* right. `slopgate` finds the parts that only look rig
14
14
  ```console
15
15
  $ npx @voidh4x0r/slopgate .
16
16
 
17
- slopgate 0.1.3 · 4 files · 39ms
17
+ slopgate 0.1.5 · 4 files · 39ms
18
18
 
19
19
  app.py
20
20
  4:1 error high py/phantom-import `helper` is imported but not declared in any manifest and not present in this repository
@@ -72,7 +72,7 @@ Measured on **1,115,177 lines** of real code — the CPython standard library (a
72
72
  | High-confidence findings | **29** (0.03 per 1,000 lines), in 18 of 1,845 CPython files |
73
73
  | Labeled precision of high-confidence findings | **96.6%** (28/29 manually reviewed) |
74
74
  | Recall on 14 seeded defects | **14/14** |
75
- | High-confidence findings on 601 JavaScript files (`eslint`, `express`, `execa`, `semver`, `chalk`, `commander`, `debug`, `yargs`, `glob`) | **0** |
75
+ | High-confidence findings on 601 JavaScript files (`eslint`, `express`, `execa`, `semver`, `chalk`, `commander`, `debug`, `yargs`, `glob`) | **0** (these packages contain no Tape/TAP suites or bundled output — see the [coverage note](docs/benchmark.md#what-the-javascript-half-does-not-cover)) |
76
76
 
77
77
  The labels, the corpus definition and the harness are in [`benchmark/`](https://github.com/VoidH4x0r/slopgate/tree/main/benchmark) and [`docs/benchmark.md`](https://github.com/VoidH4x0r/slopgate/blob/main/docs/benchmark.md); `node scripts/benchmark.mjs` reproduces the numbers. We publish the false positives instead of hiding them.
78
78
 
@@ -204,7 +204,7 @@ jobs:
204
204
  - uses: actions/checkout@v4
205
205
  - uses: actions/setup-node@v4
206
206
  with: { node-version: 22 }
207
- - run: npx --yes @voidh4x0r/slopgate@0.1.3 . --fail-on high
207
+ - run: npx --yes @voidh4x0r/slopgate@0.1.5 . --fail-on high
208
208
  ```
209
209
 
210
210
  For GitHub code scanning, use `--format sarif` and upload with `github/codeql-action/upload-sarif`.
@@ -212,7 +212,7 @@ For GitHub code scanning, use `--format sarif` and upload with `github/codeql-ac
212
212
  For inline pull-request annotations **without** code scanning, use `--format github`, which emits [workflow commands](https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions):
213
213
 
214
214
  ```yaml
215
- - run: npx --yes @voidh4x0r/slopgate@0.1.3 . --format github --fail-on high
215
+ - run: npx --yes @voidh4x0r/slopgate@0.1.5 . --format github --fail-on high
216
216
  ```
217
217
 
218
218
  Each finding becomes an `error` / `warning` / `notice` annotation on the exact line, followed by a summary notice.
@@ -279,6 +279,7 @@ We would rather miss a finding than teach you to ignore the tool. That is also w
279
279
 
280
280
  - `.gitignore` is not read. Generated trees are skipped only through the built-in ignore list and your own `exclude` patterns.
281
281
  - Symbolic links are skipped, but they are **not** counted in `stats.skipped`. Files larger than 1 MB, empty files, excluded files and unreadable files are counted.
282
+ - Bundled/minified files are only skipped when named `*.min.js` / `*.min.mjs`; exclude hashed chunk directories with your own `exclude` patterns.
282
283
  - Modules that only exist on a non-CPython host (Jython's `java.*`, Emscripten's `js` / `pyodide`) are reported unless you add them to `ignoreModules`.
283
284
  - A path whose name matches a subcommand (`rules/`, `init/`, `scan/`) is parsed as the subcommand; write `./rules` to scan that directory.
284
285
 
@@ -296,7 +297,7 @@ Issues and pull requests are welcome. Start with [CONTRIBUTING.md](https://githu
296
297
  git clone https://github.com/VoidH4x0r/slopgate
297
298
  cd slopgate
298
299
  npm install
299
- npm test # 193 tests; the tests themselves make no network or child-process calls
300
+ npm test # 241 tests; the tests themselves make no network or child-process calls
300
301
  npm run typecheck
301
302
  npm run verify # all release gates in one command
302
303
  ```
@@ -40,6 +40,8 @@ export declare function isNoopModulePath(file: string): boolean;
40
40
  export declare function looksLikeTestModule(file: string): boolean;
41
41
  /** Text of the function's leading docstring, if it has one. */
42
42
  export declare function docstringOf(fn: AstNode): string | undefined;
43
+ /** Text of the module's leading docstring, if it has one. */
44
+ export declare function moduleDocstring(root: AstNode): string | undefined;
43
45
  /** True when the function's body starts with a docstring. */
44
46
  export declare function hasDocstring(fn: AstNode): boolean;
45
47
  /** True when the node sits inside `if __name__ == "__main__":`. */
@@ -66,6 +66,7 @@ export function collectCommentRanges(root) {
66
66
  return descendantsOfType(root, ['comment', 'line_comment', 'block_comment']).map((node) => ({
67
67
  startLine: node.startPosition.row + 1,
68
68
  endLine: node.endPosition.row + 1,
69
+ startColumn: node.startPosition.column + 1,
69
70
  }));
70
71
  }
71
72
  /**
@@ -139,6 +140,14 @@ export function docstringOf(fn) {
139
140
  const value = first.namedChildren[0];
140
141
  return value?.type === 'string' ? value.text : undefined;
141
142
  }
143
+ /** Text of the module's leading docstring, if it has one. */
144
+ export function moduleDocstring(root) {
145
+ const first = root.namedChildren.find((child) => !isComment(child));
146
+ if (first?.type !== 'expression_statement')
147
+ return undefined;
148
+ const value = first.namedChildren[0];
149
+ return value?.type === 'string' ? value.text : undefined;
150
+ }
142
151
  /** True when the function's body starts with a docstring. */
143
152
  export function hasDocstring(fn) {
144
153
  const body = fn.childForFieldName('body');
@@ -1,6 +1,6 @@
1
1
  import { normalizePythonName } from "../deps.js";
2
2
  import { IMPLICIT_MODULES, IMPORT_TO_DISTRIBUTION, PYTHON_STDLIB } from "../data/python-stdlib.js";
3
- import { ancestorOfType, collapseWhitespace, descendantsOfType, endOf, hasCommentBetween, hasDocstring, docstringOf, insideCleanupFunction, insideMainGuard, isComment, isNoopModulePath, isStubFile, isTestPath, looksLikeTestModule, snippetOf, startOf, statementsOf, truncate, walk, } from "./helpers.js";
3
+ import { ancestorOfType, collapseWhitespace, descendantsOfType, endOf, hasCommentBetween, hasDocstring, docstringOf, insideCleanupFunction, insideMainGuard, isComment, isNoopModulePath, isStubFile, isTestPath, looksLikeTestModule, moduleDocstring, snippetOf, startOf, statementsOf, truncate, walk, } from "./helpers.js";
4
4
  const TERMINATORS = new Set([
5
5
  'return_statement',
6
6
  'raise_statement',
@@ -401,7 +401,7 @@ const stubBody = {
401
401
  if (isTestPath(ctx.file))
402
402
  return [];
403
403
  // Type stubs and deliberate no-op shims are made of `pass`/`...`.
404
- if (isStubFile(ctx.file) || isNoopModulePath(ctx.file))
404
+ if (isStubFile(ctx.file) || isNoopModulePath(ctx.file) || isDocumentedNoopDirectory(ctx))
405
405
  return [];
406
406
  const drafts = [];
407
407
  for (const fn of descendantsOfType(ctx.root, ['function_definition'])) {
@@ -452,16 +452,54 @@ const stubBody = {
452
452
  return drafts;
453
453
  },
454
454
  };
455
- /** A comment that actually explains why an error is safe to ignore. */
456
- const EXPLANATION_WORDS = /error|fail|ignore|abort|expected|safe|best effort|intentional|throw|except|swallow|\bok\b/i;
457
- function explanatoryCommentBetween(ctx, fromLine, toLine) {
455
+ /** A comment that explains why a failure is safe to ignore. */
456
+ const FAILURE_WORDS = /error|fail|throw|exception|invalid|log|raise/i;
457
+ const INTENT_WORDS = /ignor\w*|abort|skip|safe|accept|fallback|best effort|tolerate|\bok\b|fine/i;
458
+ const STRONG_EXPLANATION = /harmless|benign|intentional|by design|safe to ignore|expected (?:error|failure|exception|behaviou?r)/i;
459
+ /** Comments that describe future work, not why an error is safe to ignore. */
460
+ const NOISE_COMMENT = /\b(TODO|FIXME|XXX|HACK)\b/i;
461
+ function isExplanationText(text) {
462
+ return STRONG_EXPLANATION.test(text) || (FAILURE_WORDS.test(text) && INTENT_WORDS.test(text));
463
+ }
464
+ function overlaps(comment, fromLine, toLine) {
465
+ return comment.startLine <= toLine && comment.endLine >= fromLine;
466
+ }
467
+ /** A comment is standalone when only whitespace precedes its marker. */
468
+ function isStandaloneComment(ctx, comment) {
469
+ const line = ctx.lines[comment.startLine - 1] ?? '';
470
+ return line.slice(0, Math.max(0, comment.startColumn - 1)).trim().length === 0;
471
+ }
472
+ function commentText(ctx, comment) {
473
+ return ctx.lines.slice(comment.startLine - 1, comment.endLine).join(' ');
474
+ }
475
+ function explanationCommentBetween(ctx, fromLine, toLine) {
476
+ return ctx.comments.some((comment) => overlaps(comment, fromLine, toLine) &&
477
+ isStandaloneComment(ctx, comment) &&
478
+ isExplanationText(commentText(ctx, comment)));
479
+ }
480
+ function supportingCommentBetween(ctx, fromLine, toLine, handlerStartLine) {
458
481
  return ctx.comments.some((comment) => {
459
- if (comment.startLine > toLine || comment.endLine < fromLine)
482
+ if (!overlaps(comment, fromLine, toLine))
483
+ return false;
484
+ const text = commentText(ctx, comment);
485
+ if (NOISE_COMMENT.test(text))
460
486
  return false;
461
- const text = ctx.lines.slice(comment.startLine - 1, comment.endLine).join(' ');
462
- return EXPLANATION_WORDS.test(text);
487
+ // A comment on the `pass` line is unambiguously about that handler, so it
488
+ // may be inline. Comments before the handler must start their own line:
489
+ // a trailing comment on a previous statement often describes that
490
+ // statement, not the exception.
491
+ return isStandaloneComment(ctx, comment) || comment.startLine >= handlerStartLine;
463
492
  });
464
493
  }
494
+ const NOOP_DIR_PREFIX = /^(dummy|noop|no_op|no-op)[-_]/;
495
+ const NOOP_MODULE_DOC = /dummy implementation|deliberate(?:ly)? no-?op|single-threaded|faux implementation|stand-?in|shim module/i;
496
+ /** A prefixed directory is only a shim when its module docstring says so. */
497
+ function isDocumentedNoopDirectory(ctx) {
498
+ const dirs = ctx.file.toLowerCase().split('/').slice(0, -1);
499
+ if (!dirs.some((dir) => NOOP_DIR_PREFIX.test(dir)))
500
+ return false;
501
+ return NOOP_MODULE_DOC.test(moduleDocstring(ctx.root) ?? '');
502
+ }
465
503
  const swallowedException = {
466
504
  meta: {
467
505
  id: 'py/swallowed-exception',
@@ -485,7 +523,7 @@ const swallowedException = {
485
523
  const tryBody = tryNode.namedChildren.find((child) => child.type === 'block');
486
524
  // A comment immediately above `try` often explains the failure policy.
487
525
  const aboveStart = Math.max(1, tryNode.startPosition.row);
488
- const above = explanatoryCommentBetween(ctx, aboveStart, tryNode.startPosition.row + 1);
526
+ const above = explanationCommentBetween(ctx, aboveStart, tryNode.startPosition.row + 1);
489
527
  /** 0-based end row of the previous region, or -1 when there is no try body. */
490
528
  let previousEndRow = tryBody ? tryBody.endPosition.row : -1;
491
529
  for (const clause of tryNode.namedChildren) {
@@ -509,14 +547,15 @@ const swallowedException = {
509
547
  if (!silent)
510
548
  continue;
511
549
  const typeText = clause.namedChildren
512
- .filter((child) => child.type !== 'block')
550
+ .filter((child) => child.type !== 'block' && !isComment(child))
513
551
  .map((child) => collapseWhitespace(child.text))
514
552
  .join(' ')
515
553
  .trim();
516
554
  // Optional-dependency idiom: swallowing a missing import is the point.
517
555
  if (/ImportError|ModuleNotFoundError/.test(typeText))
518
556
  continue;
519
- const commented = above || hasCommentBetween(ctx, betweenStart, handlerEndRow + 1);
557
+ const commented = above ||
558
+ supportingCommentBetween(ctx, betweenStart, handlerEndRow + 1, clause.startPosition.row + 1);
520
559
  const bare = typeText.length === 0;
521
560
  const broad = bare || /^(\(?\s*)?(Exception|BaseException)(\s*\))?$/.test(typeText);
522
561
  const cleanup = insideCleanupFunction(clause);
@@ -128,6 +128,23 @@ const T_ASSERTION_MEMBERS = new Set([
128
128
  'pass',
129
129
  'fail',
130
130
  'assert',
131
+ // Tape / TAP. The `t.` prefix is required, so these cannot match arbitrary
132
+ // `.equal` calls from other libraries.
133
+ 'equal',
134
+ 'equals',
135
+ 'notEqual',
136
+ 'deepEqual',
137
+ 'notDeepEqual',
138
+ 'looseEqual',
139
+ 'notLooseEqual',
140
+ 'deepLooseEqual',
141
+ 'notDeepLooseEqual',
142
+ 'strictEqual',
143
+ 'notStrictEqual',
144
+ 'error',
145
+ 'notOk',
146
+ 'doesNotThrow',
147
+ 'notMatch',
131
148
  ]);
132
149
  /**
133
150
  * Test whether a call is an assertion. The full callee path matters:
@@ -183,6 +200,53 @@ function hasAssertion(body, aliases) {
183
200
  });
184
201
  return found;
185
202
  }
203
+ function parameterName(node) {
204
+ if (!node)
205
+ return undefined;
206
+ if (node.type === 'identifier')
207
+ return node.text;
208
+ const pattern = node.childForFieldName('pattern');
209
+ if (pattern)
210
+ return parameterName(pattern);
211
+ const first = node.namedChildren.find((child) => child.type === 'identifier');
212
+ return first?.text;
213
+ }
214
+ function firstParameterName(callback) {
215
+ const params = callback.childForFieldName('parameters');
216
+ if (!params)
217
+ return undefined;
218
+ if (params.type === 'identifier')
219
+ return params.text;
220
+ // A callback with several parameters is usually a table-driven test
221
+ // (`(a, b) => add(a, b)`), not a framework context being delegated.
222
+ if (params.namedChildren.length !== 1)
223
+ return undefined;
224
+ return parameterName(params.namedChildren[0]);
225
+ }
226
+ /**
227
+ * Tape/TAP often delegates assertions to a local helper that receives `t`:
228
+ * `test('x', (t) => { runSuite(t); t.end(); })`. The helper may assert, so
229
+ * this is a medium-confidence "cannot verify" rather than a guaranteed no-op.
230
+ */
231
+ function delegatedHelper(body, callback) {
232
+ const param = firstParameterName(callback);
233
+ if (!param)
234
+ return undefined;
235
+ let helper;
236
+ walk(body, (node) => {
237
+ if (helper)
238
+ return false;
239
+ if (node.type !== 'call_expression')
240
+ return true;
241
+ const args = node.childForFieldName('arguments');
242
+ if (!args?.namedChildren.some((arg) => arg.type === 'identifier' && arg.text === param)) {
243
+ return true;
244
+ }
245
+ helper = collapseWhitespace(node.childForFieldName('function')?.text ?? '') || 'a helper';
246
+ return false;
247
+ });
248
+ return helper;
249
+ }
186
250
  const phantomImport = {
187
251
  meta: {
188
252
  id: 'ts/phantom-import',
@@ -308,14 +372,21 @@ const noopTest = {
308
372
  if (!body)
309
373
  continue;
310
374
  const label = args.namedChildren[0]?.type === 'string' ? truncate(args.namedChildren[0].text, 60) : undefined;
375
+ const delegated = delegatedHelper(body, callback);
311
376
  if (body.type !== 'statement_block') {
312
377
  if (!hasAssertion(body, aliases)) {
313
378
  drafts.push({
314
- message: 'test makes no assertions',
379
+ message: delegated ? 'test delegates its assertions to a helper' : 'test makes no assertions',
315
380
  start: startOf(call),
316
381
  end: endOf(body),
317
382
  snippet: snippetOf(ctx, call),
318
- evidence: [`test: ${label ?? '(anonymous)'}`, 'the test body only calls code without checking a result'],
383
+ confidence: delegated ? 'medium' : 'high',
384
+ evidence: [
385
+ `test: ${label ?? '(anonymous)'}`,
386
+ ...(delegated
387
+ ? [`first parameter is passed to \`${delegated}\`; the helper may assert`]
388
+ : ['the test body only calls code without checking a result']),
389
+ ],
319
390
  help: 'Every test should be able to fail. Add an assertion that depends on the behaviour under test.',
320
391
  });
321
392
  }
@@ -335,11 +406,18 @@ const noopTest = {
335
406
  }
336
407
  if (!hasAssertion(body, aliases)) {
337
408
  drafts.push({
338
- message: 'test makes no assertions',
409
+ message: delegated ? 'test delegates its assertions to a helper' : 'test makes no assertions',
339
410
  start: startOf(call),
340
411
  end: endOf(body),
341
412
  snippet: snippetOf(ctx, call),
342
- evidence: [`test: ${label ?? '(anonymous)'}`, `statements: ${statements.length}`, 'no expect() / assert() found'],
413
+ confidence: delegated ? 'medium' : 'high',
414
+ evidence: [
415
+ `test: ${label ?? '(anonymous)'}`,
416
+ `statements: ${statements.length}`,
417
+ ...(delegated
418
+ ? [`first parameter is passed to \`${delegated}\`; the helper may assert`]
419
+ : ['no expect() / assert() found']),
420
+ ],
343
421
  help: 'Every test should be able to fail. Add an assertion that depends on the behaviour under test.',
344
422
  });
345
423
  }
@@ -463,9 +541,10 @@ const stubFunction = {
463
541
  end: endOf(body),
464
542
  snippet: snippetOf(ctx, node),
465
543
  // An empty body is a weak signal in JavaScript: callbacks and dispatch
466
- // tables legitimately do nothing. Only an explicit "not implemented"
467
- // throw is evidence of an abandoned implementation.
468
- confidence: form === 'empty body' ? 'medium' : 'high',
544
+ // tables legitimately do nothing. A class method that throws
545
+ // "not implemented" is also the standard way to declare an interface
546
+ // member for subclasses, so only standalone functions keep high.
547
+ confidence: form === 'empty body' || node.type === 'method_definition' ? 'medium' : 'high',
469
548
  evidence: [`body: ${form}`],
470
549
  help: 'Implement it, or throw an error with a message so callers fail loudly instead of silently doing nothing.',
471
550
  });
@@ -482,7 +561,11 @@ const stubFunction = {
482
561
  start: startOf(node),
483
562
  end: endOf(body),
484
563
  snippet: snippetOf(ctx, node),
485
- evidence: ['body: throws "not implemented"'],
564
+ confidence: node.parent?.type === 'pair' ? 'medium' : 'high',
565
+ evidence: [
566
+ 'body: throws "not implemented"',
567
+ ...(node.parent?.type === 'pair' ? ['object-literal property: interface stubs often throw here'] : []),
568
+ ],
486
569
  help: 'Implement it, or throw an error with a message so callers fail loudly.',
487
570
  });
488
571
  }
@@ -559,6 +642,8 @@ const deadBranch = {
559
642
  continue;
560
643
  if (isTrue && node.type === 'while_statement')
561
644
  continue;
645
+ // A nearby comment usually marks a deliberate disabled branch.
646
+ const commented = hasCommentBetween(ctx, Math.max(1, node.startPosition.row), node.endPosition.row + 1);
562
647
  drafts.push({
563
648
  message: isFalse
564
649
  ? `\`${node.type === 'while_statement' ? 'while' : 'if'} (${text})\` is dead code`
@@ -566,14 +651,37 @@ const deadBranch = {
566
651
  start: startOf(node),
567
652
  end: endOf(condition),
568
653
  snippet: snippetOf(ctx, node),
569
- confidence: isFalse ? 'high' : 'medium',
570
- evidence: [`condition: ${text}`],
654
+ confidence: isFalse && !commented ? 'high' : 'medium',
655
+ evidence: [
656
+ `condition: ${text}`,
657
+ ...(commented ? ['a nearby comment suggests this is a deliberate switch'] : []),
658
+ ],
571
659
  help: 'Replace the constant with the flag or configuration value it is standing in for.',
572
660
  });
573
661
  }
574
662
  return drafts;
575
663
  },
576
664
  };
665
+ /**
666
+ * Function declarations and bare `var` statements are hoisted: they are usable
667
+ * before a `return` even when written after it. Type aliases, interfaces and
668
+ * `declare` statements are erased at compile time, so they have no runtime
669
+ * position either. `let`/`const`, enums, classes and initialised `var`
670
+ * statements execute at their position and remain genuinely dead.
671
+ */
672
+ function isErasedOrHoisted(statement) {
673
+ if (statement.type === 'function_declaration' ||
674
+ statement.type === 'generator_function_declaration' ||
675
+ statement.type === 'type_alias_declaration' ||
676
+ statement.type === 'interface_declaration' ||
677
+ statement.type === 'ambient_declaration') {
678
+ return true;
679
+ }
680
+ if (statement.type !== 'variable_declaration')
681
+ return false;
682
+ const declarators = statement.namedChildren.filter((child) => child.type === 'variable_declarator');
683
+ return declarators.length > 0 && declarators.every((declarator) => !declarator.childForFieldName('value'));
684
+ }
577
685
  const unreachable = {
578
686
  meta: {
579
687
  id: 'ts/unreachable',
@@ -596,8 +704,10 @@ const unreachable = {
596
704
  if (index === -1)
597
705
  continue;
598
706
  const terminator = statements[index];
599
- const firstUnreachable = statements[index + 1];
600
- if (!terminator || !firstUnreachable)
707
+ if (!terminator)
708
+ continue;
709
+ const firstUnreachable = statements.slice(index + 1).find((statement) => !isErasedOrHoisted(statement));
710
+ if (!firstUnreachable)
601
711
  continue;
602
712
  const count = statements.length - index - 1;
603
713
  const keyword = terminator.type.replace('_statement', '');
package/dist/types.d.ts CHANGED
@@ -15,6 +15,8 @@ export interface Position {
15
15
  export interface CommentRange {
16
16
  startLine: number;
17
17
  endLine: number;
18
+ /** 1-based column of the comment marker, for standalone-comment checks. */
19
+ startColumn: number;
18
20
  }
19
21
  export interface Finding {
20
22
  ruleId: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voidh4x0r/slopgate",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "The slop gate for AI-written code. Precision-first structural linting for Python and TypeScript.",
5
5
  "type": "module",
6
6
  "license": "MIT",