@voidh4x0r/slopgate 0.1.4 → 0.1.6
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 +23 -0
- package/README.md +4 -4
- package/dist/rules/python.js +37 -4
- package/dist/rules/typescript.js +81 -10
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -9,6 +9,29 @@ 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.6] - 2026-11-22
|
|
13
|
+
|
|
14
|
+
### Fixed
|
|
15
|
+
- `py/swallowed-exception` treats future-work wording (`later`, `next sprint/release/iteration`, `someday`, `eventually`) as noise again, while a real cleanup explanation without future wording still demotes.
|
|
16
|
+
- `py/noop-test` recognises a test whose last statement calls a module-local helper containing an assertion, reporting it at medium confidence. This matches the TypeScript delegated-helper behaviour; the lexical assertion-name list remains for `verify(...)`-style helpers.
|
|
17
|
+
|
|
18
|
+
### Changed
|
|
19
|
+
- 245 tests, including sixth-round regression fixtures for `noise`, `py-named-helper` and `py-delegated`.
|
|
20
|
+
- 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: []`.
|
|
21
|
+
|
|
22
|
+
## [0.1.5] - 2026-11-22
|
|
23
|
+
|
|
24
|
+
### Fixed
|
|
25
|
+
- `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.
|
|
26
|
+
- `ts/unreachable` skips erased `type`, `interface` and `declare` declarations after a terminator; `enum`, classes, `let`/`const` and initialised `var` still report.
|
|
27
|
+
- `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.
|
|
28
|
+
- `ts/stub-function` reports object-literal arrow properties that throw “Not implemented” at medium confidence, matching class methods.
|
|
29
|
+
|
|
30
|
+
### Changed
|
|
31
|
+
- 241 tests, including fifth-round regression fixtures for `delegated-assert`, `ts-type-after-return`, `cleanup-word`, `comment-placement` and the conservative `wording` cases.
|
|
32
|
+
- 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: []`.
|
|
33
|
+
- Docs record the accepted above-`try` wording conservatism (a bare “known bug” stays high by design).
|
|
34
|
+
|
|
12
35
|
## [0.1.4] - 2026-11-22
|
|
13
36
|
|
|
14
37
|
### 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.6 · 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
|
|
@@ -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.6 . --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.6 . --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.
|
|
@@ -297,7 +297,7 @@ Issues and pull requests are welcome. Start with [CONTRIBUTING.md](https://githu
|
|
|
297
297
|
git clone https://github.com/VoidH4x0r/slopgate
|
|
298
298
|
cd slopgate
|
|
299
299
|
npm install
|
|
300
|
-
npm test #
|
|
300
|
+
npm test # 245 tests; the tests themselves make no network or child-process calls
|
|
301
301
|
npm run typecheck
|
|
302
302
|
npm run verify # all release gates in one command
|
|
303
303
|
```
|
package/dist/rules/python.js
CHANGED
|
@@ -111,6 +111,34 @@ function bodyCallsSelf(body) {
|
|
|
111
111
|
});
|
|
112
112
|
return found;
|
|
113
113
|
}
|
|
114
|
+
/** Module-local helpers whose bodies contain an assertion. */
|
|
115
|
+
function localAssertionHelpers(root) {
|
|
116
|
+
const helpers = new Map();
|
|
117
|
+
for (const fn of descendantsOfType(root, ['function_definition'])) {
|
|
118
|
+
if (fn.parent?.type === 'class_definition')
|
|
119
|
+
continue;
|
|
120
|
+
const name = fn.childForFieldName('name')?.text;
|
|
121
|
+
if (!name || testFunctionName(fn))
|
|
122
|
+
continue;
|
|
123
|
+
const body = fn.childForFieldName('body');
|
|
124
|
+
if (body && hasAssertion(body))
|
|
125
|
+
helpers.set(name, fn);
|
|
126
|
+
}
|
|
127
|
+
return helpers;
|
|
128
|
+
}
|
|
129
|
+
/** The last statement calling a local helper can carry the assertions. */
|
|
130
|
+
function delegatesToLocalHelper(statements, helpers) {
|
|
131
|
+
const last = statements[statements.length - 1];
|
|
132
|
+
if (!last)
|
|
133
|
+
return undefined;
|
|
134
|
+
const call = last.type === 'expression_statement' || last.type === 'return_statement'
|
|
135
|
+
? last.namedChildren[0]
|
|
136
|
+
: undefined;
|
|
137
|
+
if (call?.type !== 'call')
|
|
138
|
+
return undefined;
|
|
139
|
+
const name = collapseWhitespace(call.childForFieldName('function')?.text ?? '');
|
|
140
|
+
return /^[A-Za-z_]\w*$/.test(name) && helpers.has(name) ? name : undefined;
|
|
141
|
+
}
|
|
114
142
|
function placeholderForm(block) {
|
|
115
143
|
const statements = statementsOf(block);
|
|
116
144
|
const afterDocstring = statements[0]?.type === 'expression_statement' &&
|
|
@@ -269,6 +297,7 @@ const noopTest = {
|
|
|
269
297
|
if (isStubFile(ctx.file))
|
|
270
298
|
return [];
|
|
271
299
|
const drafts = [];
|
|
300
|
+
const helpers = localAssertionHelpers(ctx.root);
|
|
272
301
|
for (const fn of descendantsOfType(ctx.root, ['function_definition'])) {
|
|
273
302
|
const name = testFunctionName(fn);
|
|
274
303
|
if (!name)
|
|
@@ -305,6 +334,7 @@ const noopTest = {
|
|
|
305
334
|
}
|
|
306
335
|
if (!hasAssertion(body)) {
|
|
307
336
|
const delegatesToSelf = bodyCallsSelf(body);
|
|
337
|
+
const delegatedTo = delegatesToLocalHelper(statements, helpers);
|
|
308
338
|
const parameters = fn.childForFieldName('parameters');
|
|
309
339
|
const parameterCount = parameters
|
|
310
340
|
? parameters.namedChildren.filter((child) => child.type !== 'comment').length
|
|
@@ -324,7 +354,7 @@ const noopTest = {
|
|
|
324
354
|
const camelCase = !name.startsWith('test_');
|
|
325
355
|
const likelyHelper = !inClass && (parameterCount >= 2 || helperDecorator || (camelCase && parameterCount >= 1));
|
|
326
356
|
// unittest-style methods routinely delegate assertions to helpers.
|
|
327
|
-
const confidence = inClass || delegatesToSelf || likelyHelper ? 'medium' : 'high';
|
|
357
|
+
const confidence = inClass || delegatesToSelf || delegatedTo !== undefined || likelyHelper ? 'medium' : 'high';
|
|
328
358
|
drafts.push({
|
|
329
359
|
message: `test \`${name}\` makes no assertions`,
|
|
330
360
|
start: startOf(fn),
|
|
@@ -336,6 +366,9 @@ const noopTest = {
|
|
|
336
366
|
`statements: ${statements.length}`,
|
|
337
367
|
'no assert / raises / mock assertion found',
|
|
338
368
|
...(delegatesToSelf ? ['the body calls a self.* helper, which may contain the assertions'] : []),
|
|
369
|
+
...(delegatedTo
|
|
370
|
+
? [`last statement calls \`${delegatedTo}\`, whose body contains an assertion`]
|
|
371
|
+
: []),
|
|
339
372
|
...(inClass && !delegatesToSelf ? ['defined inside a test class, where helpers often hold the assertions'] : []),
|
|
340
373
|
...(likelyHelper ? ['takes several parameters or uses a helper decorator, so it may be a test helper'] : []),
|
|
341
374
|
],
|
|
@@ -457,7 +490,7 @@ const FAILURE_WORDS = /error|fail|throw|exception|invalid|log|raise/i;
|
|
|
457
490
|
const INTENT_WORDS = /ignor\w*|abort|skip|safe|accept|fallback|best effort|tolerate|\bok\b|fine/i;
|
|
458
491
|
const STRONG_EXPLANATION = /harmless|benign|intentional|by design|safe to ignore|expected (?:error|failure|exception|behaviou?r)/i;
|
|
459
492
|
/** Comments that describe future work, not why an error is safe to ignore. */
|
|
460
|
-
const NOISE_COMMENT =
|
|
493
|
+
const NOISE_COMMENT = /\b(TODO|FIXME|XXX|HACK)\b|\b(later|next (sprint|release|iteration)|someday|eventually)\b/i;
|
|
461
494
|
function isExplanationText(text) {
|
|
462
495
|
return STRONG_EXPLANATION.test(text) || (FAILURE_WORDS.test(text) && INTENT_WORDS.test(text));
|
|
463
496
|
}
|
|
@@ -547,7 +580,7 @@ const swallowedException = {
|
|
|
547
580
|
if (!silent)
|
|
548
581
|
continue;
|
|
549
582
|
const typeText = clause.namedChildren
|
|
550
|
-
.filter((child) => child.type !== 'block')
|
|
583
|
+
.filter((child) => child.type !== 'block' && !isComment(child))
|
|
551
584
|
.map((child) => collapseWhitespace(child.text))
|
|
552
585
|
.join(' ')
|
|
553
586
|
.trim();
|
|
@@ -555,7 +588,7 @@ const swallowedException = {
|
|
|
555
588
|
if (/ImportError|ModuleNotFoundError/.test(typeText))
|
|
556
589
|
continue;
|
|
557
590
|
const commented = above ||
|
|
558
|
-
supportingCommentBetween(ctx, betweenStart, handlerEndRow + 1,
|
|
591
|
+
supportingCommentBetween(ctx, betweenStart, handlerEndRow + 1, clause.startPosition.row + 1);
|
|
559
592
|
const bare = typeText.length === 0;
|
|
560
593
|
const broad = bare || /^(\(?\s*)?(Exception|BaseException)(\s*\))?$/.test(typeText);
|
|
561
594
|
const cleanup = insideCleanupFunction(clause);
|
package/dist/rules/typescript.js
CHANGED
|
@@ -200,6 +200,53 @@ function hasAssertion(body, aliases) {
|
|
|
200
200
|
});
|
|
201
201
|
return found;
|
|
202
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
|
+
}
|
|
203
250
|
const phantomImport = {
|
|
204
251
|
meta: {
|
|
205
252
|
id: 'ts/phantom-import',
|
|
@@ -325,14 +372,21 @@ const noopTest = {
|
|
|
325
372
|
if (!body)
|
|
326
373
|
continue;
|
|
327
374
|
const label = args.namedChildren[0]?.type === 'string' ? truncate(args.namedChildren[0].text, 60) : undefined;
|
|
375
|
+
const delegated = delegatedHelper(body, callback);
|
|
328
376
|
if (body.type !== 'statement_block') {
|
|
329
377
|
if (!hasAssertion(body, aliases)) {
|
|
330
378
|
drafts.push({
|
|
331
|
-
message: 'test makes no assertions',
|
|
379
|
+
message: delegated ? 'test delegates its assertions to a helper' : 'test makes no assertions',
|
|
332
380
|
start: startOf(call),
|
|
333
381
|
end: endOf(body),
|
|
334
382
|
snippet: snippetOf(ctx, call),
|
|
335
|
-
|
|
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
|
+
],
|
|
336
390
|
help: 'Every test should be able to fail. Add an assertion that depends on the behaviour under test.',
|
|
337
391
|
});
|
|
338
392
|
}
|
|
@@ -352,11 +406,18 @@ const noopTest = {
|
|
|
352
406
|
}
|
|
353
407
|
if (!hasAssertion(body, aliases)) {
|
|
354
408
|
drafts.push({
|
|
355
|
-
message: 'test makes no assertions',
|
|
409
|
+
message: delegated ? 'test delegates its assertions to a helper' : 'test makes no assertions',
|
|
356
410
|
start: startOf(call),
|
|
357
411
|
end: endOf(body),
|
|
358
412
|
snippet: snippetOf(ctx, call),
|
|
359
|
-
|
|
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
|
+
],
|
|
360
421
|
help: 'Every test should be able to fail. Add an assertion that depends on the behaviour under test.',
|
|
361
422
|
});
|
|
362
423
|
}
|
|
@@ -500,7 +561,11 @@ const stubFunction = {
|
|
|
500
561
|
start: startOf(node),
|
|
501
562
|
end: endOf(body),
|
|
502
563
|
snippet: snippetOf(ctx, node),
|
|
503
|
-
|
|
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
|
+
],
|
|
504
569
|
help: 'Implement it, or throw an error with a message so callers fail loudly.',
|
|
505
570
|
});
|
|
506
571
|
}
|
|
@@ -599,11 +664,17 @@ const deadBranch = {
|
|
|
599
664
|
};
|
|
600
665
|
/**
|
|
601
666
|
* Function declarations and bare `var` statements are hoisted: they are usable
|
|
602
|
-
* before a `return` even when written after it.
|
|
603
|
-
* `
|
|
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.
|
|
604
671
|
*/
|
|
605
|
-
function
|
|
606
|
-
if (statement.type === 'function_declaration' ||
|
|
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') {
|
|
607
678
|
return true;
|
|
608
679
|
}
|
|
609
680
|
if (statement.type !== 'variable_declaration')
|
|
@@ -635,7 +706,7 @@ const unreachable = {
|
|
|
635
706
|
const terminator = statements[index];
|
|
636
707
|
if (!terminator)
|
|
637
708
|
continue;
|
|
638
|
-
const firstUnreachable = statements.slice(index + 1).find((statement) => !
|
|
709
|
+
const firstUnreachable = statements.slice(index + 1).find((statement) => !isErasedOrHoisted(statement));
|
|
639
710
|
if (!firstUnreachable)
|
|
640
711
|
continue;
|
|
641
712
|
const count = statements.length - index - 1;
|