@voidh4x0r/slopgate 0.1.5 → 0.1.8

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,40 @@ 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.8] - 2026-11-22
13
+
14
+ ### Fixed
15
+ - `py/noop-test` now looks up only the local helper called by the test’s last statement. The name→node map is a light single walk; `hasAssertion` runs once per called helper and is cached. Test-heavy files no longer scan every function body, and the full CPython benchmark returns to ≈10.98 s (from 11.72 s).
16
+ - Unknown rule ids in `.slopgate.json` are now configuration errors (exit 2, MCP tool error), matching `--rule py/nope` and the README exit-code table. `--quiet` no longer hides the message.
17
+
18
+ ### Changed
19
+ - 252 tests, including the `bad-rule-config` CLI case, the engine rejection test, and helper-lookup coverage.
20
+ - Benchmark findings 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
+ - Performance-guard recommendation for the large CPython corpus tightened from 10% to 5%.
22
+
23
+ ## [0.1.7] - 2026-11-22
24
+
25
+ ### Fixed
26
+ - `py/noop-test` builds its local-helper index lazily, only when a test actually lacks an assertion. This removes the unconditional full-tree walk introduced in 0.1.6 and restores the rule’s scan cost (≈10.4 s → 9.9 s for `--rule py/noop-test` on the full CPython corpus).
27
+ - `py/swallowed-exception` checks whether a comment is a real explanation before applying future-work noise. “The caller retries later, so we ignore this error” demotes, while “refactor this later” stays high.
28
+
29
+ ### Added
30
+ - Benchmark performance guard: `--max-regression <percent>` compares per-corpus `durationMs` with the previous results file, ignores corpora under 100 ms, and exits 1 on a regression. Intended for same-machine runs.
31
+
32
+ ### Changed
33
+ - 250 tests, including the `future-words` fixture and performance-guard unit tests.
34
+ - Benchmark findings 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: []`.
35
+
36
+ ## [0.1.6] - 2026-11-22
37
+
38
+ ### Fixed
39
+ - `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.
40
+ - `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.
41
+
42
+ ### Changed
43
+ - 245 tests, including sixth-round regression fixtures for `noise`, `py-named-helper` and `py-delegated`.
44
+ - 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: []`.
45
+
12
46
  ## [0.1.5] - 2026-11-22
13
47
 
14
48
  ### 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.5 · 4 files · 39ms
17
+ slopgate 0.1.8 · 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.5 . --fail-on high
207
+ - run: npx --yes @voidh4x0r/slopgate@0.1.8 . --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.5 . --format github --fail-on high
215
+ - run: npx --yes @voidh4x0r/slopgate@0.1.8 . --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.
@@ -265,7 +265,7 @@ We would rather miss a finding than teach you to ignore the tool. That is also w
265
265
  `slopgate` parses with tree-sitter compiled to WebAssembly and reuses one parser per language. Scanning never spawns a subprocess. `--diff` and the MCP `scan_diff` tool invoke `git`, so those two paths need git on `PATH` and a sandbox that permits child processes:
266
266
 
267
267
  - 20 files / ~3k lines: **~125 ms** end to end (Windows laptop, cold start)
268
- - 1,845 files / 991,705 lines (CPython standard library): **~12 s** in the benchmark run
268
+ - 1,845 files / 991,705 lines (CPython standard library): **~11 s** in the benchmark run
269
269
  - 3 grammar files load once in **~35 ms**
270
270
  - Python: ~12 ms per 35 KB file
271
271
 
@@ -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 # 241 tests; the tests themselves make no network or child-process calls
300
+ npm test # 252 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/engine.js CHANGED
@@ -49,8 +49,9 @@ export async function scanProject(options) {
49
49
  const warnings = [];
50
50
  const { config } = options;
51
51
  for (const ruleId of Object.keys(config.rules)) {
52
- if (!RULE_BY_ID.has(ruleId))
53
- warnings.push(`unknown rule in config: ${ruleId}`);
52
+ if (!RULE_BY_ID.has(ruleId)) {
53
+ throw new Error(`unknown rule in config: ${ruleId} (run \`slopgate rules\` to list the ${ALL_RULES.length} rule ids)`);
54
+ }
54
55
  }
55
56
  const deps = await loadProjectDeps(root);
56
57
  deps.ignoredModules = new Set(config.ignoreModules);
@@ -111,6 +111,52 @@ function bodyCallsSelf(body) {
111
111
  });
112
112
  return found;
113
113
  }
114
+ /** Lightweight name → node index; assertion checks happen on demand. */
115
+ function localFunctionDefinitions(root) {
116
+ const definitions = 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
+ definitions.set(name, fn);
124
+ }
125
+ return definitions;
126
+ }
127
+ /** Name of the bare local call in the test's last statement, if any. */
128
+ function lastLocalCallName(statements) {
129
+ const last = statements[statements.length - 1];
130
+ if (!last)
131
+ return undefined;
132
+ const call = last.type === 'expression_statement' || last.type === 'return_statement'
133
+ ? last.namedChildren[0]
134
+ : undefined;
135
+ if (call?.type !== 'call')
136
+ return undefined;
137
+ const name = collapseWhitespace(call.childForFieldName('function')?.text ?? '');
138
+ return /^[A-Za-z_]\w*$/.test(name) ? name : undefined;
139
+ }
140
+ /**
141
+ * Only check the helper the last statement actually calls. The definition map
142
+ * is built on first hit and each helper's assertion result is cached, so a
143
+ * test-heavy file does not run `hasAssertion` over every function.
144
+ */
145
+ function delegatesToLocalHelper(statements, definitions, assertionCache) {
146
+ const name = lastLocalCallName(statements);
147
+ if (!name)
148
+ return undefined;
149
+ const helper = definitions().get(name);
150
+ if (!helper)
151
+ return undefined;
152
+ let asserts = assertionCache.get(name);
153
+ if (asserts === undefined) {
154
+ const body = helper.childForFieldName('body');
155
+ asserts = body !== null && hasAssertion(body);
156
+ assertionCache.set(name, asserts);
157
+ }
158
+ return asserts ? name : undefined;
159
+ }
114
160
  function placeholderForm(block) {
115
161
  const statements = statementsOf(block);
116
162
  const afterDocstring = statements[0]?.type === 'expression_statement' &&
@@ -269,6 +315,14 @@ const noopTest = {
269
315
  if (isStubFile(ctx.file))
270
316
  return [];
271
317
  const drafts = [];
318
+ // A test-dense file may have thousands of assertion-free tests. Build the
319
+ // name index once, and only assert-check the helper actually called.
320
+ let definitionIndex;
321
+ const definitions = () => {
322
+ definitionIndex ??= localFunctionDefinitions(ctx.root);
323
+ return definitionIndex;
324
+ };
325
+ const helperAssertions = new Map();
272
326
  for (const fn of descendantsOfType(ctx.root, ['function_definition'])) {
273
327
  const name = testFunctionName(fn);
274
328
  if (!name)
@@ -305,6 +359,7 @@ const noopTest = {
305
359
  }
306
360
  if (!hasAssertion(body)) {
307
361
  const delegatesToSelf = bodyCallsSelf(body);
362
+ const delegatedTo = delegatesToLocalHelper(statements, definitions, helperAssertions);
308
363
  const parameters = fn.childForFieldName('parameters');
309
364
  const parameterCount = parameters
310
365
  ? parameters.namedChildren.filter((child) => child.type !== 'comment').length
@@ -324,7 +379,7 @@ const noopTest = {
324
379
  const camelCase = !name.startsWith('test_');
325
380
  const likelyHelper = !inClass && (parameterCount >= 2 || helperDecorator || (camelCase && parameterCount >= 1));
326
381
  // unittest-style methods routinely delegate assertions to helpers.
327
- const confidence = inClass || delegatesToSelf || likelyHelper ? 'medium' : 'high';
382
+ const confidence = inClass || delegatesToSelf || delegatedTo !== undefined || likelyHelper ? 'medium' : 'high';
328
383
  drafts.push({
329
384
  message: `test \`${name}\` makes no assertions`,
330
385
  start: startOf(fn),
@@ -336,6 +391,9 @@ const noopTest = {
336
391
  `statements: ${statements.length}`,
337
392
  'no assert / raises / mock assertion found',
338
393
  ...(delegatesToSelf ? ['the body calls a self.* helper, which may contain the assertions'] : []),
394
+ ...(delegatedTo
395
+ ? [`last statement calls \`${delegatedTo}\`, whose body contains an assertion`]
396
+ : []),
339
397
  ...(inClass && !delegatesToSelf ? ['defined inside a test class, where helpers often hold the assertions'] : []),
340
398
  ...(likelyHelper ? ['takes several parameters or uses a helper decorator, so it may be a test helper'] : []),
341
399
  ],
@@ -457,7 +515,7 @@ const FAILURE_WORDS = /error|fail|throw|exception|invalid|log|raise/i;
457
515
  const INTENT_WORDS = /ignor\w*|abort|skip|safe|accept|fallback|best effort|tolerate|\bok\b|fine/i;
458
516
  const STRONG_EXPLANATION = /harmless|benign|intentional|by design|safe to ignore|expected (?:error|failure|exception|behaviou?r)/i;
459
517
  /** Comments that describe future work, not why an error is safe to ignore. */
460
- const NOISE_COMMENT = /\b(TODO|FIXME|XXX|HACK)\b/i;
518
+ const NOISE_COMMENT = /\b(TODO|FIXME|XXX|HACK)\b|\b(later|next (sprint|release|iteration)|someday|eventually)\b/i;
461
519
  function isExplanationText(text) {
462
520
  return STRONG_EXPLANATION.test(text) || (FAILURE_WORDS.test(text) && INTENT_WORDS.test(text));
463
521
  }
@@ -481,14 +539,15 @@ function supportingCommentBetween(ctx, fromLine, toLine, handlerStartLine) {
481
539
  return ctx.comments.some((comment) => {
482
540
  if (!overlaps(comment, fromLine, toLine))
483
541
  return false;
484
- const text = commentText(ctx, comment);
485
- if (NOISE_COMMENT.test(text))
542
+ const positioned = isStandaloneComment(ctx, comment) || comment.startLine >= handlerStartLine;
543
+ if (!positioned)
486
544
  return false;
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;
545
+ const text = commentText(ctx, comment);
546
+ // A stated explanation wins over future-work wording: "the caller retries
547
+ // later, so we ignore this error" is an explanation, not a TODO.
548
+ if (isExplanationText(text))
549
+ return true;
550
+ return !NOISE_COMMENT.test(text);
492
551
  });
493
552
  }
494
553
  const NOOP_DIR_PREFIX = /^(dummy|noop|no_op|no-op)[-_]/;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voidh4x0r/slopgate",
3
- "version": "0.1.5",
3
+ "version": "0.1.8",
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",