@voidh4x0r/slopgate 0.1.1 → 0.1.3
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 +34 -0
- package/README.md +8 -7
- package/dist/deps.js +5 -5
- package/dist/diff.js +5 -5
- package/dist/engine.js +3 -3
- package/dist/files.d.ts +4 -1
- package/dist/files.js +24 -17
- package/dist/mcp.js +6 -0
- package/dist/rules/helpers.d.ts +0 -5
- package/dist/rules/helpers.js +9 -6
- package/dist/rules/python.js +26 -5
- package/dist/rules/typescript.js +67 -6
- package/dist/types.d.ts +3 -1
- package/package.json +1 -1
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.3] - 2026-11-22
|
|
13
|
+
|
|
14
|
+
### Fixed
|
|
15
|
+
- MCP `scan_path` and `scan_diff` now return a tool error (`isError: true`) when zero files match, matching the CLI's exit 2 instead of reporting a clean run.
|
|
16
|
+
- `py/swallowed-exception` counts an explanatory comment immediately above `try` (keyword-filtered so a generic "parse the payload" comment does not hide a silent handler), and no longer includes a trailing comment on the last try-body line (off-by-one in the window start).
|
|
17
|
+
- `py/stub-body` skips `dummy_threading.py`-style modules again: exact no-op directories plus file stems starting `dummy_`/`noop_`/`_dummy_`; `dummy_data/` and `shims/` real stubs remain reported.
|
|
18
|
+
- `ts/noop-test` recognises renamed `node:assert` imports (namespace, default, named aliases and `require` bindings) as assertions.
|
|
19
|
+
- The extension language/dialect tables are merged into one map, so an extension cannot be present in one table and silently dropped from discovery.
|
|
20
|
+
- Added a docs test that fails when README or the demo artwork version disagrees with `package.json`; RELEASE now lists the docs update.
|
|
21
|
+
|
|
22
|
+
### Changed
|
|
23
|
+
- 193 tests, including third-round regression fixtures for `window`, `renamed-assert` and `dummy-variants`.
|
|
24
|
+
- Benchmark re-run: **29 high-confidence findings across 991,705 lines of CPython, 96.6% labeled precision (28/29), 14/14 seeded defects detected, 0 high findings on 601 JavaScript files.** One 0.1.2 label became stale after the comment-window change and was pruned; the file now has 18 labels covering 29 occurrences, with `staleLabels: []` and `unlabeledHigh: []`.
|
|
25
|
+
- Docs: MCP zero-file behaviour, the four comment placements, dummy naming variants, and renamed assert imports are documented.
|
|
26
|
+
|
|
27
|
+
## [0.1.2] - 2026-11-22
|
|
28
|
+
|
|
29
|
+
### Fixed
|
|
30
|
+
- `ts/noop-test` analyses `test.runIf(...)`, `test.skipIf(...)` and `test.for(...)` again; the 0.1.1 modifier whitelist skipped them entirely.
|
|
31
|
+
- Bare assertion helpers such as `assertEqual`, `assertNotNull` and `assertTruthy` count as assertions again.
|
|
32
|
+
- `py/swallowed-exception` scopes explanatory comments to the region between the end of the try body (or the previous handler) and the current handler. A comment inside the try body no longer hides a silent `except: pass`, and an earlier comment no longer excuses a later handler.
|
|
33
|
+
- `py/stub-body` skips only exact no-op path segments (`dummy`, `_dummy`, `noop`, `no_op`, `no-op`); `dummy_data/` and genuinely unfinished `shims/` code are reported again.
|
|
34
|
+
- Imports under `sys.version_info` / `platform.python_version()` / `six.PY2` guards are ignored, matching the existing `sys.platform` handling.
|
|
35
|
+
- `stats.byLanguage` reports `javascript` for `.js`/`.jsx`/`.mjs`/`.cjs` instead of counting them as `tsx`.
|
|
36
|
+
- The release workflow skips npm publish and GitHub release with a warning when `NPM_TOKEN` is missing instead of failing the tag run.
|
|
37
|
+
- The unified-diff parser no longer leaves an empty line-set entry for a deletion-only hunk.
|
|
38
|
+
- Internal cleanup: the pyproject parser no longer shadows the outer `names` variable.
|
|
39
|
+
|
|
40
|
+
### Changed
|
|
41
|
+
- 179 tests, including second-round regression fixtures for `assert-helpers`, `try-comment`, `noop-overmatch`, `pyproject-edge` and `test-call-forms`.
|
|
42
|
+
- Benchmark re-run: **29 high-confidence findings across 991,705 lines of CPython, 96.6% labeled precision (28/29), 14/14 seeded defects detected, 0 high findings across 601 JavaScript files.** 19 labels cover 29 high-finding occurrences; stale and unlabeled findings are zero. The corrected comment window surfaced one previously labeled-tp finding in `idlelib/debugger.py`, which was re-added to the labels.
|
|
43
|
+
- JSON consumers see a new `byLanguage.javascript` bucket; `.js`/`.jsx` counts no longer inflate `tsx`.
|
|
44
|
+
- Docs: symlink counting clarified, host-only module limitation added, README CI snippet pins the release version, benchmark digest marked as a 64-bit truncation.
|
|
45
|
+
|
|
12
46
|
## [0.1.1] - 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.
|
|
17
|
+
slopgate 0.1.3 · 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
|
|
@@ -69,8 +69,8 @@ Measured on **1,115,177 lines** of real code — the CPython standard library (a
|
|
|
69
69
|
|
|
70
70
|
| Metric | Result |
|
|
71
71
|
| --- | --- |
|
|
72
|
-
| High-confidence findings | **
|
|
73
|
-
| Labeled precision of high-confidence findings | **96.
|
|
72
|
+
| High-confidence findings | **29** (0.03 per 1,000 lines), in 18 of 1,845 CPython files |
|
|
73
|
+
| Labeled precision of high-confidence findings | **96.6%** (28/29 manually reviewed) |
|
|
74
74
|
| Recall on 14 seeded defects | **14/14** |
|
|
75
75
|
| High-confidence findings on 601 JavaScript files (`eslint`, `express`, `execa`, `semver`, `chalk`, `commander`, `debug`, `yargs`, `glob`) | **0** |
|
|
76
76
|
|
|
@@ -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@
|
|
207
|
+
- run: npx --yes @voidh4x0r/slopgate@0.1.3 . --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@
|
|
215
|
+
- run: npx --yes @voidh4x0r/slopgate@0.1.3 . --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.
|
|
@@ -278,7 +278,8 @@ We would rather miss a finding than teach you to ignore the tool. That is also w
|
|
|
278
278
|
## Known limitations
|
|
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
|
-
- Symbolic links are skipped,
|
|
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
|
+
- Modules that only exist on a non-CPython host (Jython's `java.*`, Emscripten's `js` / `pyodide`) are reported unless you add them to `ignoreModules`.
|
|
282
283
|
- A path whose name matches a subcommand (`rules/`, `init/`, `scan/`) is parsed as the subcommand; write `./rules` to scan that directory.
|
|
283
284
|
|
|
284
285
|
## When **not** to use it
|
|
@@ -295,7 +296,7 @@ Issues and pull requests are welcome. Start with [CONTRIBUTING.md](https://githu
|
|
|
295
296
|
git clone https://github.com/VoidH4x0r/slopgate
|
|
296
297
|
cd slopgate
|
|
297
298
|
npm install
|
|
298
|
-
npm test #
|
|
299
|
+
npm test # 193 tests; the tests themselves make no network or child-process calls
|
|
299
300
|
npm run typecheck
|
|
300
301
|
npm run verify # all release gates in one command
|
|
301
302
|
```
|
package/dist/deps.js
CHANGED
|
@@ -149,7 +149,7 @@ export function parsePythonManifestText(fileName, text) {
|
|
|
149
149
|
return names;
|
|
150
150
|
}
|
|
151
151
|
if (base === 'pyproject.toml') {
|
|
152
|
-
const
|
|
152
|
+
const collected = [];
|
|
153
153
|
const groups = new Map();
|
|
154
154
|
let section = '';
|
|
155
155
|
let pending;
|
|
@@ -162,7 +162,7 @@ export function parsePythonManifestText(fileName, text) {
|
|
|
162
162
|
groups.set(key, group);
|
|
163
163
|
}
|
|
164
164
|
else {
|
|
165
|
-
|
|
165
|
+
collected.push(...entries.requirements);
|
|
166
166
|
}
|
|
167
167
|
};
|
|
168
168
|
for (const rawLine of text.split(/\r?\n/)) {
|
|
@@ -197,7 +197,7 @@ export function parsePythonManifestText(fileName, text) {
|
|
|
197
197
|
POETRY_GROUP.test(section)) {
|
|
198
198
|
const key = tomlKey(line);
|
|
199
199
|
if (key && key.toLowerCase() !== 'python')
|
|
200
|
-
|
|
200
|
+
collected.push(normalizePythonName(key));
|
|
201
201
|
}
|
|
202
202
|
}
|
|
203
203
|
// Resolve PEP 735 include-group references (with cycle protection).
|
|
@@ -216,8 +216,8 @@ export function parsePythonManifestText(fileName, text) {
|
|
|
216
216
|
};
|
|
217
217
|
for (const name of groups.keys())
|
|
218
218
|
resolveGroup(name, new Set());
|
|
219
|
-
|
|
220
|
-
return [...new Set(
|
|
219
|
+
collected.push(...resolved);
|
|
220
|
+
return [...new Set(collected)];
|
|
221
221
|
}
|
|
222
222
|
if (base === 'setup.py') {
|
|
223
223
|
const blocks = [...text.matchAll(/install_requires\s*=\s*\[([\s\S]*?)\]/g)];
|
package/dist/diff.js
CHANGED
|
@@ -104,6 +104,10 @@ export function parseUnifiedDiff(stdout) {
|
|
|
104
104
|
continue; // ""
|
|
105
105
|
if (line.startsWith('+')) {
|
|
106
106
|
if (newRemaining > 0) {
|
|
107
|
+
if (!store && currentFile) {
|
|
108
|
+
store = new Set();
|
|
109
|
+
set.lines.set(currentFile, store);
|
|
110
|
+
}
|
|
107
111
|
store?.add(newLine);
|
|
108
112
|
newLine += 1;
|
|
109
113
|
newRemaining -= 1;
|
|
@@ -161,11 +165,7 @@ export function parseUnifiedDiff(stdout) {
|
|
|
161
165
|
newLine = Number.parseInt(hunk[3], 10);
|
|
162
166
|
if (!Number.isFinite(newLine))
|
|
163
167
|
continue;
|
|
164
|
-
store = set.lines.get(currentFile);
|
|
165
|
-
if (!store) {
|
|
166
|
-
store = new Set();
|
|
167
|
-
set.lines.set(currentFile, store);
|
|
168
|
-
}
|
|
168
|
+
store = currentFile ? set.lines.get(currentFile) : undefined;
|
|
169
169
|
}
|
|
170
170
|
return set;
|
|
171
171
|
}
|
package/dist/engine.js
CHANGED
|
@@ -68,7 +68,7 @@ export async function scanProject(options) {
|
|
|
68
68
|
return false;
|
|
69
69
|
return true;
|
|
70
70
|
});
|
|
71
|
-
const byLanguage = { python: 0, typescript: 0, tsx: 0 };
|
|
71
|
+
const byLanguage = { python: 0, javascript: 0, typescript: 0, tsx: 0 };
|
|
72
72
|
const findings = [];
|
|
73
73
|
const seen = new Set();
|
|
74
74
|
let suppressedCount = 0;
|
|
@@ -90,7 +90,7 @@ export async function scanProject(options) {
|
|
|
90
90
|
// Editors on Windows write a UTF-8 BOM; it must not shift line/column
|
|
91
91
|
// numbers in findings.
|
|
92
92
|
const source = buffer.toString('utf8').replace(/^\uFEFF/, '');
|
|
93
|
-
byLanguage[file.
|
|
93
|
+
byLanguage[file.dialect] += 1;
|
|
94
94
|
const parser = await getParser(file.language);
|
|
95
95
|
const tree = parser.parse(source);
|
|
96
96
|
if (!tree) {
|
|
@@ -159,7 +159,7 @@ export async function scanProject(options) {
|
|
|
159
159
|
a.start.column - b.start.column ||
|
|
160
160
|
a.ruleId.localeCompare(b.ruleId));
|
|
161
161
|
const stats = {
|
|
162
|
-
files: byLanguage.python + byLanguage.typescript + byLanguage.tsx,
|
|
162
|
+
files: byLanguage.python + byLanguage.javascript + byLanguage.typescript + byLanguage.tsx,
|
|
163
163
|
byLanguage,
|
|
164
164
|
skipped,
|
|
165
165
|
parseErrors,
|
package/dist/files.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { LanguageId } from './types.ts';
|
|
1
|
+
import type { LanguageId, SourceDialect } from './types.ts';
|
|
2
2
|
/** Directories that never contain code we want to lint. */
|
|
3
3
|
export declare const DEFAULT_IGNORE_DIRS: ReadonlySet<string>;
|
|
4
4
|
export declare const DEFAULT_INCLUDE: readonly string[];
|
|
@@ -8,6 +8,8 @@ export interface SourceFile {
|
|
|
8
8
|
/** Repository-relative path with forward slashes. */
|
|
9
9
|
rel: string;
|
|
10
10
|
language: LanguageId;
|
|
11
|
+
/** Human-facing dialect: `.js` is javascript even though it parses as tsx. */
|
|
12
|
+
dialect: SourceDialect;
|
|
11
13
|
size: number;
|
|
12
14
|
}
|
|
13
15
|
export interface DiscoverOptions {
|
|
@@ -30,4 +32,5 @@ export declare function toPosix(p: string): string;
|
|
|
30
32
|
export declare function globToRegExp(glob: string): RegExp;
|
|
31
33
|
export declare function matchesAny(relPath: string, patterns: readonly RegExp[]): boolean;
|
|
32
34
|
export declare function languageFor(fileName: string): LanguageId | undefined;
|
|
35
|
+
export declare function dialectFor(fileName: string): SourceDialect | undefined;
|
|
33
36
|
export declare function discoverFiles(options: DiscoverOptions): Promise<DiscoverResult>;
|
package/dist/files.js
CHANGED
|
@@ -17,18 +17,18 @@ export const DEFAULT_INCLUDE = [
|
|
|
17
17
|
'**/*.ts', '**/*.mts', '**/*.cts', '**/*.tsx',
|
|
18
18
|
'**/*.js', '**/*.mjs', '**/*.cjs', '**/*.jsx',
|
|
19
19
|
];
|
|
20
|
-
const
|
|
21
|
-
'.py': 'python',
|
|
22
|
-
'.pyi': 'python',
|
|
23
|
-
'.ts': 'typescript',
|
|
24
|
-
'.mts': 'typescript',
|
|
25
|
-
'.cts': 'typescript',
|
|
26
|
-
'.tsx': 'tsx',
|
|
27
|
-
'.jsx': 'tsx',
|
|
20
|
+
const EXTENSIONS = {
|
|
21
|
+
'.py': { language: 'python', dialect: 'python' },
|
|
22
|
+
'.pyi': { language: 'python', dialect: 'python' },
|
|
23
|
+
'.ts': { language: 'typescript', dialect: 'typescript' },
|
|
24
|
+
'.mts': { language: 'typescript', dialect: 'typescript' },
|
|
25
|
+
'.cts': { language: 'typescript', dialect: 'typescript' },
|
|
26
|
+
'.tsx': { language: 'tsx', dialect: 'tsx' },
|
|
28
27
|
// JSX is legal in .js, and the tsx grammar is a superset of plain JS.
|
|
29
|
-
'.js': 'tsx',
|
|
30
|
-
'.
|
|
31
|
-
'.
|
|
28
|
+
'.js': { language: 'tsx', dialect: 'javascript' },
|
|
29
|
+
'.jsx': { language: 'tsx', dialect: 'javascript' },
|
|
30
|
+
'.mjs': { language: 'tsx', dialect: 'javascript' },
|
|
31
|
+
'.cjs': { language: 'tsx', dialect: 'javascript' },
|
|
32
32
|
};
|
|
33
33
|
const MAX_FILE_BYTES = 1024 * 1024;
|
|
34
34
|
export function toPosix(p) {
|
|
@@ -125,8 +125,13 @@ export function languageFor(fileName) {
|
|
|
125
125
|
if (fileName.endsWith('.d.ts') || fileName.endsWith('.d.mts') || fileName.endsWith('.d.cts')) {
|
|
126
126
|
return undefined;
|
|
127
127
|
}
|
|
128
|
-
|
|
129
|
-
|
|
128
|
+
return EXTENSIONS[path.extname(fileName).toLowerCase()]?.language;
|
|
129
|
+
}
|
|
130
|
+
export function dialectFor(fileName) {
|
|
131
|
+
if (fileName.endsWith('.d.ts') || fileName.endsWith('.d.mts') || fileName.endsWith('.d.cts')) {
|
|
132
|
+
return undefined;
|
|
133
|
+
}
|
|
134
|
+
return EXTENSIONS[path.extname(fileName).toLowerCase()]?.dialect;
|
|
130
135
|
}
|
|
131
136
|
export async function discoverFiles(options) {
|
|
132
137
|
const root = path.resolve(options.root);
|
|
@@ -147,13 +152,14 @@ export async function discoverFiles(options) {
|
|
|
147
152
|
if (rootInfo.isFile()) {
|
|
148
153
|
const name = path.basename(root);
|
|
149
154
|
const language = languageFor(name);
|
|
150
|
-
|
|
155
|
+
const dialect = dialectFor(name);
|
|
156
|
+
if (!language || !dialect || !matchesAny(name, includeRe) || matchesAny(name, excludeRe)) {
|
|
151
157
|
return { files, skipped: 1 };
|
|
152
158
|
}
|
|
153
159
|
if (rootInfo.size > maxBytes || rootInfo.size === 0) {
|
|
154
160
|
return { files, skipped: 1 };
|
|
155
161
|
}
|
|
156
|
-
files.push({ abs: root, rel: name, language, size: rootInfo.size });
|
|
162
|
+
files.push({ abs: root, rel: name, language, dialect, size: rootInfo.size });
|
|
157
163
|
return { files, skipped };
|
|
158
164
|
}
|
|
159
165
|
async function walk(dir) {
|
|
@@ -186,7 +192,8 @@ export async function discoverFiles(options) {
|
|
|
186
192
|
continue;
|
|
187
193
|
}
|
|
188
194
|
const language = languageFor(entry.name);
|
|
189
|
-
|
|
195
|
+
const dialect = dialectFor(entry.name);
|
|
196
|
+
if (!language || !dialect || !matchesAny(rel, includeRe)) {
|
|
190
197
|
continue;
|
|
191
198
|
}
|
|
192
199
|
if (entry.name.endsWith('.min.js') || entry.name.endsWith('.min.mjs')) {
|
|
@@ -205,7 +212,7 @@ export async function discoverFiles(options) {
|
|
|
205
212
|
skipped += 1;
|
|
206
213
|
continue;
|
|
207
214
|
}
|
|
208
|
-
files.push({ abs, rel, language, size: info.size });
|
|
215
|
+
files.push({ abs, rel, language, dialect, size: info.size });
|
|
209
216
|
}
|
|
210
217
|
}
|
|
211
218
|
await walk(root);
|
package/dist/mcp.js
CHANGED
|
@@ -121,12 +121,18 @@ export function createMcpServer(deps) {
|
|
|
121
121
|
return textResult(`Refusing to scan outside the repository root: ${target}`, true);
|
|
122
122
|
}
|
|
123
123
|
const result = await deps.scan(target);
|
|
124
|
+
if (result.stats.files === 0) {
|
|
125
|
+
return textResult(`No files matched under ${target} (check include/exclude patterns)`, true);
|
|
126
|
+
}
|
|
124
127
|
const visible = result.findings.filter((finding) => meetsConfidence(finding.confidence, confidence));
|
|
125
128
|
return textResult(formatFindings(visible, result, deps.version, max));
|
|
126
129
|
}
|
|
127
130
|
if (name === 'scan_diff') {
|
|
128
131
|
const base = typeof params.base === 'string' && params.base.length > 0 ? params.base : 'HEAD';
|
|
129
132
|
const result = await deps.scan(deps.root);
|
|
133
|
+
if (result.stats.files === 0) {
|
|
134
|
+
return textResult('No files matched in the repository (check include/exclude patterns)', true);
|
|
135
|
+
}
|
|
130
136
|
const set = await deps.diff(deps.root, base);
|
|
131
137
|
const inDiff = result.findings.filter((finding) => isInDiff(finding, set) && meetsConfidence(finding.confidence, confidence));
|
|
132
138
|
const preamble = `Diff since ${base}: ${inDiff.length} finding(s) on changed lines.`;
|
package/dist/rules/helpers.d.ts
CHANGED
|
@@ -35,11 +35,6 @@ export declare function truncate(value: string, max: number): string;
|
|
|
35
35
|
export declare function isTestPath(file: string): boolean;
|
|
36
36
|
/** Type stubs declare every function with `...`; stub rules must not fire. */
|
|
37
37
|
export declare function isStubFile(file: string): boolean;
|
|
38
|
-
/**
|
|
39
|
-
* Modules whose whole purpose is to provide no-op stand-ins (CPython's
|
|
40
|
-
* `multiprocessing/dummy`, single-threaded shims). Their empty bodies are the
|
|
41
|
-
* implementation, not an unfinished one.
|
|
42
|
-
*/
|
|
43
38
|
export declare function isNoopModulePath(file: string): boolean;
|
|
44
39
|
/** True when the file name follows a test-module convention. */
|
|
45
40
|
export declare function looksLikeTestModule(file: string): boolean;
|
package/dist/rules/helpers.js
CHANGED
|
@@ -111,14 +111,17 @@ export function isStubFile(file) {
|
|
|
111
111
|
}
|
|
112
112
|
/**
|
|
113
113
|
* Modules whose whole purpose is to provide no-op stand-ins (CPython's
|
|
114
|
-
* `multiprocessing/dummy`,
|
|
115
|
-
*
|
|
114
|
+
* `multiprocessing/dummy`, `dummy_threading.py`). Directory names must match
|
|
115
|
+
* exactly; file names may use the `dummy_`/`noop_` convention. `dummy_data/`
|
|
116
|
+
* is a normal package and `shims/` can contain unfinished code.
|
|
116
117
|
*/
|
|
118
|
+
const NOOP_DIRS = new Set(['dummy', '_dummy', 'noop', 'no_op', 'no-op']);
|
|
117
119
|
export function isNoopModulePath(file) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
120
|
+
const parts = file.toLowerCase().split('/');
|
|
121
|
+
if (parts.slice(0, -1).some((part) => NOOP_DIRS.has(part)))
|
|
122
|
+
return true;
|
|
123
|
+
const stem = (parts[parts.length - 1] ?? '').replace(/\.pyi?$/, '');
|
|
124
|
+
return /^_?(dummy|noop|no_op|no-op)(_|$)/.test(stem);
|
|
122
125
|
}
|
|
123
126
|
/** True when the file name follows a test-module convention. */
|
|
124
127
|
export function looksLikeTestModule(file) {
|
package/dist/rules/python.js
CHANGED
|
@@ -186,14 +186,15 @@ function insideAbstractMethod(node) {
|
|
|
186
186
|
}
|
|
187
187
|
return false;
|
|
188
188
|
}
|
|
189
|
-
/**
|
|
189
|
+
/** Platform/version guards make the import conditional on the host. */
|
|
190
190
|
function insidePlatformGuard(node) {
|
|
191
191
|
let current = node.parent;
|
|
192
192
|
while (current) {
|
|
193
193
|
if (current.type === 'if_statement') {
|
|
194
194
|
const condition = current.childForFieldName('condition')?.text ?? '';
|
|
195
|
-
if (/sys\.platform|platform\.system\s*\(/.test(condition))
|
|
195
|
+
if (/sys\.platform|platform\.system\s*\(|sys\.version_info|platform\.python_version\s*\(|six\.PY2|\bPY2\b/.test(condition)) {
|
|
196
196
|
return true;
|
|
197
|
+
}
|
|
197
198
|
}
|
|
198
199
|
current = current.parent;
|
|
199
200
|
}
|
|
@@ -451,6 +452,16 @@ const stubBody = {
|
|
|
451
452
|
return drafts;
|
|
452
453
|
},
|
|
453
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) {
|
|
458
|
+
return ctx.comments.some((comment) => {
|
|
459
|
+
if (comment.startLine > toLine || comment.endLine < fromLine)
|
|
460
|
+
return false;
|
|
461
|
+
const text = ctx.lines.slice(comment.startLine - 1, comment.endLine).join(' ');
|
|
462
|
+
return EXPLANATION_WORDS.test(text);
|
|
463
|
+
});
|
|
464
|
+
}
|
|
454
465
|
const swallowedException = {
|
|
455
466
|
meta: {
|
|
456
467
|
id: 'py/swallowed-exception',
|
|
@@ -471,12 +482,24 @@ const swallowedException = {
|
|
|
471
482
|
// `try: ... except X: pass else: fail()` is an assertion idiom, not a bug.
|
|
472
483
|
if (tryNode.namedChildren.some((child) => child.type === 'else_clause'))
|
|
473
484
|
continue;
|
|
485
|
+
const tryBody = tryNode.namedChildren.find((child) => child.type === 'block');
|
|
486
|
+
// A comment immediately above `try` often explains the failure policy.
|
|
487
|
+
const aboveStart = Math.max(1, tryNode.startPosition.row);
|
|
488
|
+
const above = explanatoryCommentBetween(ctx, aboveStart, tryNode.startPosition.row + 1);
|
|
489
|
+
/** 0-based end row of the previous region, or -1 when there is no try body. */
|
|
490
|
+
let previousEndRow = tryBody ? tryBody.endPosition.row : -1;
|
|
474
491
|
for (const clause of tryNode.namedChildren) {
|
|
475
492
|
if (clause.type !== 'except_clause' && clause.type !== 'except_group_clause')
|
|
476
493
|
continue;
|
|
477
494
|
const body = clause.namedChildren.filter((child) => child.type === 'block').pop();
|
|
478
495
|
if (!body)
|
|
479
496
|
continue;
|
|
497
|
+
// Comments between the try body (or the previous handler) and this
|
|
498
|
+
// handler can explain this handler; comments inside the try body
|
|
499
|
+
// cannot. Advance the cursor for every handler, silent or not.
|
|
500
|
+
const handlerEndRow = body.endPosition.row;
|
|
501
|
+
const betweenStart = previousEndRow >= 0 ? previousEndRow + 2 : clause.startPosition.row + 1;
|
|
502
|
+
previousEndRow = handlerEndRow;
|
|
480
503
|
const statements = statementsOf(body);
|
|
481
504
|
const silent = statements.length === 0 ||
|
|
482
505
|
(statements.length === 1 &&
|
|
@@ -493,9 +516,7 @@ const swallowedException = {
|
|
|
493
516
|
// Optional-dependency idiom: swallowing a missing import is the point.
|
|
494
517
|
if (/ImportError|ModuleNotFoundError/.test(typeText))
|
|
495
518
|
continue;
|
|
496
|
-
|
|
497
|
-
// and the `except`, so the window starts at the whole statement.
|
|
498
|
-
const commented = hasCommentBetween(ctx, tryNode.startPosition.row + 1, body.endPosition.row + 1);
|
|
519
|
+
const commented = above || hasCommentBetween(ctx, betweenStart, handlerEndRow + 1);
|
|
499
520
|
const bare = typeText.length === 0;
|
|
500
521
|
const broad = bare || /^(\(?\s*)?(Exception|BaseException)(\s*\))?$/.test(typeText);
|
|
501
522
|
const cleanup = insideCleanupFunction(clause);
|
package/dist/rules/typescript.js
CHANGED
|
@@ -65,7 +65,57 @@ function matchesAlias(specifier, aliases) {
|
|
|
65
65
|
return specifier === clean || specifier.startsWith(`${clean}/`);
|
|
66
66
|
});
|
|
67
67
|
}
|
|
68
|
-
const
|
|
68
|
+
const NODE_ASSERT_SPECIFIERS = new Set(['node:assert', 'node:assert/strict']);
|
|
69
|
+
function addAssertBinding(aliases, part) {
|
|
70
|
+
const match = /^\s*(?:type\s+)?([A-Za-z_$][\w$]*)(?:\s+as\s+([A-Za-z_$][\w$]*))?\s*$/.exec(part);
|
|
71
|
+
if (match?.[1])
|
|
72
|
+
aliases.add(match[2] ?? match[1]);
|
|
73
|
+
}
|
|
74
|
+
/** Local names bound to `node:assert` / `node:assert/strict`. */
|
|
75
|
+
function assertAliases(root) {
|
|
76
|
+
const aliases = new Set();
|
|
77
|
+
for (const node of descendantsOfType(root, ['import_statement'])) {
|
|
78
|
+
const specifier = sourceString(node);
|
|
79
|
+
if (!specifier || !NODE_ASSERT_SPECIFIERS.has(specifier))
|
|
80
|
+
continue;
|
|
81
|
+
const text = node.text;
|
|
82
|
+
const namespace = /import\s+\*\s+as\s+([A-Za-z_$][\w$]*)/.exec(text);
|
|
83
|
+
if (namespace?.[1])
|
|
84
|
+
aliases.add(namespace[1]);
|
|
85
|
+
const defaultImport = /import\s+([A-Za-z_$][\w$]*)\s*(?:,|from)/.exec(text);
|
|
86
|
+
if (defaultImport?.[1])
|
|
87
|
+
aliases.add(defaultImport[1]);
|
|
88
|
+
const named = /\{([^}]*)\}/.exec(text);
|
|
89
|
+
if (named?.[1]) {
|
|
90
|
+
for (const part of named[1].split(','))
|
|
91
|
+
addAssertBinding(aliases, part);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
for (const call of descendantsOfType(root, ['call_expression'])) {
|
|
95
|
+
const fn = call.childForFieldName('function');
|
|
96
|
+
if (!fn || collapseWhitespace(fn.text) !== 'require')
|
|
97
|
+
continue;
|
|
98
|
+
const args = call.childForFieldName('arguments');
|
|
99
|
+
const specifier = stringLiteralValue(args?.namedChildren[0]);
|
|
100
|
+
if (!specifier || !NODE_ASSERT_SPECIFIERS.has(specifier))
|
|
101
|
+
continue;
|
|
102
|
+
const declarator = ancestorOfType(call, ['variable_declarator']);
|
|
103
|
+
const name = declarator?.childForFieldName('name')?.text;
|
|
104
|
+
if (!name)
|
|
105
|
+
continue;
|
|
106
|
+
if (/^[A-Za-z_$][\w$]*$/.test(name)) {
|
|
107
|
+
aliases.add(name);
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
const pattern = /\{([^}]*)\}/.exec(name);
|
|
111
|
+
if (pattern?.[1]) {
|
|
112
|
+
for (const part of pattern[1].split(','))
|
|
113
|
+
addAssertBinding(aliases, part);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return aliases;
|
|
118
|
+
}
|
|
69
119
|
const T_ASSERTION_MEMBERS = new Set([
|
|
70
120
|
'ok',
|
|
71
121
|
'is',
|
|
@@ -84,12 +134,19 @@ const T_ASSERTION_MEMBERS = new Set([
|
|
|
84
134
|
* `assert.strictEqual` ends in `strictEqual`, which the old last-segment
|
|
85
135
|
* regex missed, so node:assert-based tests were reported as assertion-free.
|
|
86
136
|
*/
|
|
87
|
-
function isAssertionCallee(text) {
|
|
137
|
+
function isAssertionCallee(text, aliases) {
|
|
88
138
|
if (text.length === 0)
|
|
89
139
|
return false;
|
|
140
|
+
// Renamed imports: nodeAssert.strictEqual, strictAssert.equal, eq(...).
|
|
141
|
+
const root = text.split(/[.(]/)[0] ?? '';
|
|
142
|
+
if (aliases.has(root))
|
|
143
|
+
return true;
|
|
90
144
|
// node:assert and node:assert/strict: assert(...) plus every method.
|
|
91
145
|
if (text === 'assert' || text.startsWith('assert.'))
|
|
92
146
|
return true;
|
|
147
|
+
// Bare helpers such as assertEqual/assertNotNull/assertTruthy.
|
|
148
|
+
if (/^assert[A-Z][A-Za-z0-9_$]*$/.test(text))
|
|
149
|
+
return true;
|
|
93
150
|
// Jest/Vitest/Chai: expect(x).toBe(y), expect(x).not.toEqual(y), expect.soft(...)
|
|
94
151
|
if (text === 'expect' || text === 'expectTypeOf')
|
|
95
152
|
return true;
|
|
@@ -109,7 +166,7 @@ function isAssertionCallee(text) {
|
|
|
109
166
|
}
|
|
110
167
|
return false;
|
|
111
168
|
}
|
|
112
|
-
function hasAssertion(body) {
|
|
169
|
+
function hasAssertion(body, aliases) {
|
|
113
170
|
let found = false;
|
|
114
171
|
walk(body, (node) => {
|
|
115
172
|
if (found)
|
|
@@ -117,7 +174,7 @@ function hasAssertion(body) {
|
|
|
117
174
|
if (node.type === 'call_expression') {
|
|
118
175
|
const fn = node.childForFieldName('function') ?? node.namedChildren[0];
|
|
119
176
|
const text = collapseWhitespace(fn?.text ?? '');
|
|
120
|
-
if (isAssertionCallee(text)) {
|
|
177
|
+
if (isAssertionCallee(text, aliases)) {
|
|
121
178
|
found = true;
|
|
122
179
|
return false;
|
|
123
180
|
}
|
|
@@ -197,9 +254,12 @@ const TEST_MODIFIERS = new Set([
|
|
|
197
254
|
'concurrent',
|
|
198
255
|
'sequential',
|
|
199
256
|
'each',
|
|
257
|
+
'for',
|
|
200
258
|
'fails',
|
|
201
259
|
'failing',
|
|
202
260
|
'serial',
|
|
261
|
+
'runIf',
|
|
262
|
+
'skipIf',
|
|
203
263
|
]);
|
|
204
264
|
/**
|
|
205
265
|
* `test(...)` / `it(...)` and their modifiers (`test.only`, `test.each(...)`).
|
|
@@ -231,6 +291,7 @@ const noopTest = {
|
|
|
231
291
|
if (ctx.language === 'python')
|
|
232
292
|
return [];
|
|
233
293
|
const drafts = [];
|
|
294
|
+
const aliases = assertAliases(ctx.root);
|
|
234
295
|
for (const call of descendantsOfType(ctx.root, ['call_expression'])) {
|
|
235
296
|
const fn = call.childForFieldName('function');
|
|
236
297
|
if (!fn || !isTestCall(fn))
|
|
@@ -248,7 +309,7 @@ const noopTest = {
|
|
|
248
309
|
continue;
|
|
249
310
|
const label = args.namedChildren[0]?.type === 'string' ? truncate(args.namedChildren[0].text, 60) : undefined;
|
|
250
311
|
if (body.type !== 'statement_block') {
|
|
251
|
-
if (!hasAssertion(body)) {
|
|
312
|
+
if (!hasAssertion(body, aliases)) {
|
|
252
313
|
drafts.push({
|
|
253
314
|
message: 'test makes no assertions',
|
|
254
315
|
start: startOf(call),
|
|
@@ -272,7 +333,7 @@ const noopTest = {
|
|
|
272
333
|
});
|
|
273
334
|
continue;
|
|
274
335
|
}
|
|
275
|
-
if (!hasAssertion(body)) {
|
|
336
|
+
if (!hasAssertion(body, aliases)) {
|
|
276
337
|
drafts.push({
|
|
277
338
|
message: 'test makes no assertions',
|
|
278
339
|
start: startOf(call),
|
package/dist/types.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { AstNode } from './ast.ts';
|
|
2
2
|
/** Tree-sitter grammars we ship. */
|
|
3
3
|
export type LanguageId = 'python' | 'typescript' | 'tsx';
|
|
4
|
+
/** Human-facing source dialect, independent of the grammar used to parse it. */
|
|
5
|
+
export type SourceDialect = 'python' | 'javascript' | 'typescript' | 'tsx';
|
|
4
6
|
/** How sure we are that a finding is worth a human's time. */
|
|
5
7
|
export type Confidence = 'high' | 'medium' | 'low';
|
|
6
8
|
export type Severity = 'error' | 'warning' | 'info';
|
|
@@ -88,7 +90,7 @@ export interface Rule {
|
|
|
88
90
|
}
|
|
89
91
|
export interface ScanStats {
|
|
90
92
|
files: number;
|
|
91
|
-
byLanguage: Record<
|
|
93
|
+
byLanguage: Record<SourceDialect, number>;
|
|
92
94
|
skipped: number;
|
|
93
95
|
parseErrors: number;
|
|
94
96
|
durationMs: number;
|