@voidh4x0r/slopgate 0.1.3 → 0.1.4
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 +15 -0
- package/README.md +6 -5
- package/dist/rules/helpers.d.ts +2 -0
- package/dist/rules/helpers.js +9 -0
- package/dist/rules/python.js +49 -10
- package/dist/rules/typescript.js +46 -7
- package/dist/types.d.ts +2 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -9,6 +9,21 @@ 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.4] - 2026-11-22
|
|
13
|
+
|
|
14
|
+
### Fixed
|
|
15
|
+
- `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.
|
|
16
|
+
- `ts/unreachable` no longer reports hoisted `function`/generator declarations or bare `var` statements after a `return`; `let`/`const` and initialised `var` are still reported.
|
|
17
|
+
- `ts/stub-function` reports class-method `throw new Error("Not implemented")` at medium confidence; standalone/exported throw-stubs remain high.
|
|
18
|
+
- `py/stub-body` skips `dummy_multiprocessing/`-style prefixed directories when the module docstring identifies a no-op shim, while `dummy_data/` remains reported.
|
|
19
|
+
- `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.
|
|
20
|
+
- `ts/dead-branch` now has the same nearby-comment demotion as `py/dead-branch`.
|
|
21
|
+
|
|
22
|
+
### Changed
|
|
23
|
+
- 228 tests, including fourth-round regression fixtures for `tape-assert`, `hoisted-fn`, `assert-forms`, `above-heuristic`, `above-trailing`, `between-asymmetry` and `dummy-dir-shim`.
|
|
24
|
+
- 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: []`.
|
|
25
|
+
- 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.
|
|
26
|
+
|
|
12
27
|
## [0.1.3] - 2026-11-22
|
|
13
28
|
|
|
14
29
|
### 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.
|
|
17
|
+
slopgate 0.1.4 · 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.
|
|
207
|
+
- run: npx --yes @voidh4x0r/slopgate@0.1.4 . --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.
|
|
215
|
+
- run: npx --yes @voidh4x0r/slopgate@0.1.4 . --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 #
|
|
300
|
+
npm test # 228 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
|
```
|
package/dist/rules/helpers.d.ts
CHANGED
|
@@ -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__":`. */
|
package/dist/rules/helpers.js
CHANGED
|
@@ -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');
|
package/dist/rules/python.js
CHANGED
|
@@ -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
|
|
456
|
-
const
|
|
457
|
-
|
|
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 = /(?:^|\s)(TODO|FIXME|XXX|HACK)\b|refactor|cleanup|next sprint/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
|
|
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
|
-
|
|
462
|
-
|
|
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 =
|
|
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) {
|
|
@@ -516,7 +554,8 @@ const swallowedException = {
|
|
|
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 ||
|
|
557
|
+
const commented = above ||
|
|
558
|
+
supportingCommentBetween(ctx, betweenStart, handlerEndRow + 1, body.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);
|
package/dist/rules/typescript.js
CHANGED
|
@@ -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:
|
|
@@ -463,9 +480,10 @@ const stubFunction = {
|
|
|
463
480
|
end: endOf(body),
|
|
464
481
|
snippet: snippetOf(ctx, node),
|
|
465
482
|
// An empty body is a weak signal in JavaScript: callbacks and dispatch
|
|
466
|
-
// tables legitimately do nothing.
|
|
467
|
-
//
|
|
468
|
-
|
|
483
|
+
// tables legitimately do nothing. A class method that throws
|
|
484
|
+
// "not implemented" is also the standard way to declare an interface
|
|
485
|
+
// member for subclasses, so only standalone functions keep high.
|
|
486
|
+
confidence: form === 'empty body' || node.type === 'method_definition' ? 'medium' : 'high',
|
|
469
487
|
evidence: [`body: ${form}`],
|
|
470
488
|
help: 'Implement it, or throw an error with a message so callers fail loudly instead of silently doing nothing.',
|
|
471
489
|
});
|
|
@@ -559,6 +577,8 @@ const deadBranch = {
|
|
|
559
577
|
continue;
|
|
560
578
|
if (isTrue && node.type === 'while_statement')
|
|
561
579
|
continue;
|
|
580
|
+
// A nearby comment usually marks a deliberate disabled branch.
|
|
581
|
+
const commented = hasCommentBetween(ctx, Math.max(1, node.startPosition.row), node.endPosition.row + 1);
|
|
562
582
|
drafts.push({
|
|
563
583
|
message: isFalse
|
|
564
584
|
? `\`${node.type === 'while_statement' ? 'while' : 'if'} (${text})\` is dead code`
|
|
@@ -566,14 +586,31 @@ const deadBranch = {
|
|
|
566
586
|
start: startOf(node),
|
|
567
587
|
end: endOf(condition),
|
|
568
588
|
snippet: snippetOf(ctx, node),
|
|
569
|
-
confidence: isFalse ? 'high' : 'medium',
|
|
570
|
-
evidence: [
|
|
589
|
+
confidence: isFalse && !commented ? 'high' : 'medium',
|
|
590
|
+
evidence: [
|
|
591
|
+
`condition: ${text}`,
|
|
592
|
+
...(commented ? ['a nearby comment suggests this is a deliberate switch'] : []),
|
|
593
|
+
],
|
|
571
594
|
help: 'Replace the constant with the flag or configuration value it is standing in for.',
|
|
572
595
|
});
|
|
573
596
|
}
|
|
574
597
|
return drafts;
|
|
575
598
|
},
|
|
576
599
|
};
|
|
600
|
+
/**
|
|
601
|
+
* Function declarations and bare `var` statements are hoisted: they are usable
|
|
602
|
+
* before a `return` even when written after it. `let`/`const` and initialised
|
|
603
|
+
* `var` statements execute at their position, so they remain genuinely dead.
|
|
604
|
+
*/
|
|
605
|
+
function isHoistedDeclaration(statement) {
|
|
606
|
+
if (statement.type === 'function_declaration' || statement.type === 'generator_function_declaration') {
|
|
607
|
+
return true;
|
|
608
|
+
}
|
|
609
|
+
if (statement.type !== 'variable_declaration')
|
|
610
|
+
return false;
|
|
611
|
+
const declarators = statement.namedChildren.filter((child) => child.type === 'variable_declarator');
|
|
612
|
+
return declarators.length > 0 && declarators.every((declarator) => !declarator.childForFieldName('value'));
|
|
613
|
+
}
|
|
577
614
|
const unreachable = {
|
|
578
615
|
meta: {
|
|
579
616
|
id: 'ts/unreachable',
|
|
@@ -596,8 +633,10 @@ const unreachable = {
|
|
|
596
633
|
if (index === -1)
|
|
597
634
|
continue;
|
|
598
635
|
const terminator = statements[index];
|
|
599
|
-
|
|
600
|
-
|
|
636
|
+
if (!terminator)
|
|
637
|
+
continue;
|
|
638
|
+
const firstUnreachable = statements.slice(index + 1).find((statement) => !isHoistedDeclaration(statement));
|
|
639
|
+
if (!firstUnreachable)
|
|
601
640
|
continue;
|
|
602
641
|
const count = statements.length - index - 1;
|
|
603
642
|
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;
|