@voidh4x0r/slopgate 0.1.0 → 0.1.1
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 +25 -1
- package/README.md +62 -24
- package/dist/cli.js +26 -20
- package/dist/config.js +2 -1
- package/dist/data/python-stdlib.d.ts +5 -3
- package/dist/data/python-stdlib.js +22 -5
- package/dist/deps.js +149 -37
- package/dist/diff.js +46 -8
- package/dist/engine.js +9 -19
- package/dist/files.d.ts +2 -1
- package/dist/files.js +63 -17
- package/dist/parser.js +4 -0
- package/dist/reporters/sarif.js +6 -1
- package/dist/rules/helpers.d.ts +18 -8
- package/dist/rules/helpers.js +37 -22
- package/dist/rules/python.js +61 -20
- package/dist/rules/typescript.js +76 -10
- package/dist/types.d.ts +7 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -9,8 +9,32 @@ 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.1] - 2026-11-22
|
|
13
|
+
|
|
14
|
+
### Fixed
|
|
15
|
+
- `.pyi` type stubs and deliberate no-op shim modules (for example `multiprocessing/dummy`) are no longer reported as unfinished stubs.
|
|
16
|
+
- `pyproject.toml` parsing now understands `[project.optional-dependencies]`, `[dependency-groups]` (PEP 735, including `include-group`), `[tool.uv] dev-dependencies`, and every `[tool.poetry.group.<name>.dependencies]` group.
|
|
17
|
+
- Import-name to distribution-name mapping now covers `docx`, `pptx`, `grpc`, `git`, `nacl`, `jose`, `fitz`, `ldap`, `rest_framework` and others, and resolves dotted prefixes (`google.protobuf`) without mapping every `google.*` import to `protobuf`.
|
|
18
|
+
- `ts/noop-test` recognises `node:assert` method assertions (`assert.strictEqual`, `assert.ok`, `assert.deepStrictEqual`, `assert.match`, …), `t.ok`/`t.assert.*`, and no longer mistakes `test.valid.forEach(...)` for a test declaration.
|
|
19
|
+
- `py/swallowed-exception` counts explanatory comments between the `try` body and `except`; comment detection now uses real comment nodes instead of scanning for `#`/`//` in strings.
|
|
20
|
+
- `conftest.py`, `noxfile.py` and `docs/conf.py` are treated as test/build infrastructure, so their imports are demoted instead of failing CI.
|
|
21
|
+
- Imports under `sys.platform` / `platform.system()` guards are ignored (platform-specific modules).
|
|
22
|
+
- `confidence: "toString"` (or any other `Object.prototype` key) is rejected instead of silently hiding every finding.
|
|
23
|
+
- Scanning zero files exits 2 with a message instead of reporting a clean run.
|
|
24
|
+
- `--fail-on medium` (or `low`) no longer acts as a no-op when `--confidence` is higher: the display threshold is lowered so failing findings are visible.
|
|
25
|
+
- A `.js`/`.mjs`/`.cjs` file is parsed with the TSX grammar, so JSX in `.js` no longer forces every finding down to `medium`.
|
|
26
|
+
- The unified-diff parser tracks hunk state, so a content line such as `++ x;` can no longer be mistaken for a `+++` file header.
|
|
27
|
+
- A UTF-8 BOM is stripped before parsing, so line 1 columns are no longer off by one.
|
|
28
|
+
- Glob patterns support `{a,b}` alternatives (including nesting), so `**/*.{ts,tsx}` works.
|
|
29
|
+
- SARIF artifact URIs are percent-encoded (spaces, `#`, non-ASCII).
|
|
30
|
+
- `--write-baseline` records all current findings even when `--diff` is also set.
|
|
31
|
+
- A failed grammar load is no longer cached forever, and ignored directories no longer inflate `stats.skipped`.
|
|
32
|
+
- `slopgate init` pins the installed version instead of `@latest`, and reports relative paths consistently.
|
|
33
|
+
|
|
12
34
|
### Changed
|
|
13
|
-
-
|
|
35
|
+
- 166 tests, including regression fixtures for every fix above.
|
|
36
|
+
- Benchmark re-run after the fixes: **26 high-confidence findings across 991,705 lines of CPython, 96.2% labeled precision (25/26), 14/14 seeded defects detected, 0 high findings across 601 JavaScript files.** The labels now cover every high finding, stale labels are zero, and the results carry a corpus digest so the run can be verified without absolute paths.
|
|
37
|
+
- Docs now state that `--diff` and MCP `scan_diff` invoke `git` (and therefore need a sandbox that permits child processes), that labels are per fingerprint and come from a development set, and that the benchmark has no minimum-sample exclusion.
|
|
14
38
|
|
|
15
39
|
## [0.1.0] - 2026-11-22
|
|
16
40
|
|
package/README.md
CHANGED
|
@@ -8,13 +8,13 @@ AI writes code that *looks* right. `slopgate` finds the parts that only look rig
|
|
|
8
8
|
|
|
9
9
|
[](https://www.npmjs.com/package/@voidh4x0r/slopgate)
|
|
10
10
|
[](https://github.com/VoidH4x0r/slopgate/actions/workflows/ci.yml)
|
|
11
|
-
[](LICENSE)
|
|
12
|
-
[](https://github.com/VoidH4x0r/slopgate/blob/main/LICENSE)
|
|
12
|
+
[](https://github.com/VoidH4x0r/slopgate/blob/main/package.json)
|
|
13
13
|
|
|
14
14
|
```console
|
|
15
|
-
$ npx @voidh4x0r/slopgate
|
|
15
|
+
$ npx @voidh4x0r/slopgate .
|
|
16
16
|
|
|
17
|
-
slopgate 0.1.0 · 4 files ·
|
|
17
|
+
slopgate 0.1.0 · 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
|
|
@@ -40,21 +40,37 @@ tests/test_users.py
|
|
|
40
40
|
│ def test_get_user():
|
|
41
41
|
↳ Every test should be able to fail. Add an assertion that depends on the behaviour under test.
|
|
42
42
|
|
|
43
|
-
13 findings in 3 files · 4 files scanned in
|
|
43
|
+
13 findings in 3 files · 4 files scanned in 39ms
|
|
44
44
|
4 error · 9 warning · 0 info (13 high · 0 medium · 0 low confidence)
|
|
45
45
|
hidden: 1 below confidence threshold
|
|
46
46
|
```
|
|
47
47
|
|
|
48
48
|
No API keys. No telemetry. No network calls at runtime. One command, works offline, exits non-zero in CI.
|
|
49
49
|
|
|
50
|
+
## What it catches
|
|
51
|
+
|
|
52
|
+
Models are good at producing code that compiles, imports cleanly in the editor where the package happened to be installed, and passes tests that assert nothing. These failures are boring, repetitive, and invisible to a green CI run:
|
|
53
|
+
|
|
54
|
+
| What the model wrote | What it costs you |
|
|
55
|
+
| --- | --- |
|
|
56
|
+
| `import requests_v2` — the package does not exist | `ModuleNotFoundError` in CI, or a malicious package if that name is ever registered |
|
|
57
|
+
| `def test_create(): service.create()` — no assertion | A green test with zero coverage |
|
|
58
|
+
| `def sync(self): pass` — real signature, empty body | Callers get `None` and the failure surfaces three layers downstream |
|
|
59
|
+
| `except Exception: pass` | The error disappears; the incident does not |
|
|
60
|
+
| `return user` followed by 12 lines of code | Dead code that nobody notices until it rots |
|
|
61
|
+
|
|
62
|
+
`slopgate` is a **precision-first** linter for exactly this class of defect, for Python and TypeScript/JavaScript.
|
|
63
|
+
|
|
64
|
+
It is built for the people who review AI-generated pull requests: the reviewer who cannot read every line, the maintainer who needs CI to say "this is not finished", and the coding agent that should check itself before declaring done.
|
|
65
|
+
|
|
50
66
|
## Does it actually catch anything?
|
|
51
67
|
|
|
52
68
|
Measured on **1,115,177 lines** of real code — the CPython standard library (an adversarial corpus full of test helpers and intentional no-ops) plus nine popular JavaScript packages:
|
|
53
69
|
|
|
54
70
|
| Metric | Result |
|
|
55
71
|
| --- | --- |
|
|
56
|
-
| High-confidence findings | **
|
|
57
|
-
| Labeled precision of high-confidence findings | **
|
|
72
|
+
| High-confidence findings | **26** (0.03 per 1,000 lines), in 17 of 1,845 CPython files |
|
|
73
|
+
| Labeled precision of high-confidence findings | **96.2%** (25/26 manually reviewed) |
|
|
58
74
|
| Recall on 14 seeded defects | **14/14** |
|
|
59
75
|
| High-confidence findings on 601 JavaScript files (`eslint`, `express`, `execa`, `semver`, `chalk`, `commander`, `debug`, `yargs`, `glob`) | **0** |
|
|
60
76
|
|
|
@@ -62,20 +78,6 @@ The labels, the corpus definition and the harness are in [`benchmark/`](https://
|
|
|
62
78
|
|
|
63
79
|
---
|
|
64
80
|
|
|
65
|
-
## Why
|
|
66
|
-
|
|
67
|
-
Models are good at producing code that compiles, imports cleanly in the editor where the package happened to be installed, and passes tests that assert nothing. These failures are boring, repetitive, and invisible to a green CI run:
|
|
68
|
-
|
|
69
|
-
| What actually happened | What a normal linter sees |
|
|
70
|
-
| --- | --- |
|
|
71
|
-
| `import requests_v2` — the package does not exist | valid import |
|
|
72
|
-
| `def test_create(): service.create()` — no assertion | valid function call |
|
|
73
|
-
| `def sync(self): pass` — implemented signature, empty body | valid method |
|
|
74
|
-
| `except Exception: pass` — errors disappear | valid exception handler |
|
|
75
|
-
| `return user` followed by 12 lines of code | valid statements |
|
|
76
|
-
|
|
77
|
-
`slopgate` is a **precision-first** linter for exactly this class of defect, for Python and TypeScript/JavaScript.
|
|
78
|
-
|
|
79
81
|
## Why another linter
|
|
80
82
|
|
|
81
83
|
`ruff`, `eslint` and friends check *style and syntax*. They cannot tell you that a package is hallucinated, because that requires reading your manifests. They cannot tell you that a test is theatre, because that requires understanding what an assertion is.
|
|
@@ -103,6 +105,8 @@ npx @voidh4x0r/slopgate init # write .slopgate.json + a GitHub Act
|
|
|
103
105
|
|
|
104
106
|
Requires Node 20+. Python and TypeScript grammars are bundled — no Python or `tsc` needed at scan time.
|
|
105
107
|
|
|
108
|
+
The npm scope is `@voidh4x0r` because the unscoped name `slopgate` was rejected as too similar to the existing `slop-gate` package; the command is still `slopgate`.
|
|
109
|
+
|
|
106
110
|
## Usage
|
|
107
111
|
|
|
108
112
|
```bash
|
|
@@ -111,6 +115,7 @@ slopgate [path] [options]
|
|
|
111
115
|
--format pretty|json|sarif|github output format (default: pretty)
|
|
112
116
|
--confidence high|medium|low minimum confidence to report (default: high)
|
|
113
117
|
--fail-on high|medium|low|none minimum confidence that fails CI (default: high)
|
|
118
|
+
(a lower value also lowers what is displayed)
|
|
114
119
|
--baseline [path] ignore findings recorded in a file (default: .slopgate-baseline.json)
|
|
115
120
|
--write-baseline [path] record current findings, then exit 0
|
|
116
121
|
--diff [ref] only report findings on changed lines (default: HEAD)
|
|
@@ -121,6 +126,31 @@ slopgate [path] [options]
|
|
|
121
126
|
-h, --help / -V, --version
|
|
122
127
|
```
|
|
123
128
|
|
|
129
|
+
### Configuration
|
|
130
|
+
|
|
131
|
+
`slopgate` reads `.slopgate.json` (or `slopgate.config.json`) from the project root. Every key is optional:
|
|
132
|
+
|
|
133
|
+
```json
|
|
134
|
+
{
|
|
135
|
+
"include": ["src/**", "tests/**"],
|
|
136
|
+
"exclude": ["vendor/**", "migrations/**"],
|
|
137
|
+
"ignoreModules": ["my_private_pkg"],
|
|
138
|
+
"rules": {
|
|
139
|
+
"ts/swallowed-exception": "off",
|
|
140
|
+
"py/stub-body": "warning"
|
|
141
|
+
},
|
|
142
|
+
"confidence": "high",
|
|
143
|
+
"failOn": "high"
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
- `include` / `exclude` — globs relative to the project root; the defaults cover Python and TS/JS sources.
|
|
148
|
+
- `ignoreModules` — top-level modules to always treat as declared (dynamic imports, private packages).
|
|
149
|
+
- `rules` — `"off"` or an explicit severity (`"error"`, `"warning"`, `"info"`).
|
|
150
|
+
- `confidence` / `failOn` — same meaning as the CLI flags; CLI flags win.
|
|
151
|
+
|
|
152
|
+
`slopgate init` writes a minimal config plus a GitHub Actions workflow.
|
|
153
|
+
|
|
124
154
|
### Adopting it on an existing repository
|
|
125
155
|
|
|
126
156
|
This is the part most linters get wrong. A 200k-line repo has 900 findings on day one, so nobody turns it on.
|
|
@@ -187,6 +217,8 @@ For inline pull-request annotations **without** code scanning, use `--format git
|
|
|
187
217
|
|
|
188
218
|
Each finding becomes an `error` / `warning` / `notice` annotation on the exact line, followed by a summary notice.
|
|
189
219
|
|
|
220
|
+
Exit codes: `0` no findings at or above `--fail-on`, `1` findings at or above the threshold, `2` usage or configuration error (missing path, unknown rule id, invalid config, git failure, or zero files matched).
|
|
221
|
+
|
|
190
222
|
### Suppressing a finding
|
|
191
223
|
|
|
192
224
|
```python
|
|
@@ -211,7 +243,7 @@ try { ... } catch {}
|
|
|
211
243
|
| `py/phantom-import` · `ts/phantom-import` | import that no manifest declares and, for TS, that is not even installed |
|
|
212
244
|
| `py/noop-test` · `ts/noop-test` | `test_*` / `test()` / `it()` bodies with no assertion |
|
|
213
245
|
| `py/tautological-assert` · `ts/tautological-assert` | `assert True`, `expect(true).toBe(true)`, `x == x` |
|
|
214
|
-
| `py/stub-body` · `ts/stub-function` | body
|
|
246
|
+
| `py/stub-body` · `ts/stub-function` | function declarations and class methods whose body is only `pass`, `...`, `{}`, or `throw new Error("not implemented")` (empty arrow callbacks are not reported unless they throw) |
|
|
215
247
|
| `py/swallowed-exception` · `ts/swallowed-exception` | `except: pass`, `catch {}` (JS empty catch is medium by design) |
|
|
216
248
|
| `py/dead-branch` · `ts/dead-branch` | `if False:` / `if (false)`, and their always-true twins |
|
|
217
249
|
| `py/unreachable` · `ts/unreachable` | statements after `return` / `raise` / `throw` / `continue` |
|
|
@@ -230,7 +262,7 @@ We would rather miss a finding than teach you to ignore the tool. That is also w
|
|
|
230
262
|
|
|
231
263
|
## Performance
|
|
232
264
|
|
|
233
|
-
`slopgate` parses with tree-sitter compiled to WebAssembly
|
|
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:
|
|
234
266
|
|
|
235
267
|
- 20 files / ~3k lines: **~125 ms** end to end (Windows laptop, cold start)
|
|
236
268
|
- 1,845 files / 991,705 lines (CPython standard library): **~12 s** in the benchmark run
|
|
@@ -243,6 +275,12 @@ We would rather miss a finding than teach you to ignore the tool. That is also w
|
|
|
243
275
|
- [ ] v0.2 — duplicate-block detection, Go and Rust grammars, `--fix` for the safe subset
|
|
244
276
|
- [ ] v0.3 — published false-positive benchmark across popular repositories, VS Code diagnostics
|
|
245
277
|
|
|
278
|
+
## Known limitations
|
|
279
|
+
|
|
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, and files larger than 1 MB are ignored. `--format json` reports the count in `stats.skipped`.
|
|
282
|
+
- A path whose name matches a subcommand (`rules/`, `init/`, `scan/`) is parsed as the subcommand; write `./rules` to scan that directory.
|
|
283
|
+
|
|
246
284
|
## When **not** to use it
|
|
247
285
|
|
|
248
286
|
- You want style, formatting or type checking — use `ruff` / `eslint` / `tsc`.
|
|
@@ -257,7 +295,7 @@ Issues and pull requests are welcome. Start with [CONTRIBUTING.md](https://githu
|
|
|
257
295
|
git clone https://github.com/VoidH4x0r/slopgate
|
|
258
296
|
cd slopgate
|
|
259
297
|
npm install
|
|
260
|
-
npm test #
|
|
298
|
+
npm test # 166 tests; the tests themselves make no network or child-process calls
|
|
261
299
|
npm run typecheck
|
|
262
300
|
npm run verify # all release gates in one command
|
|
263
301
|
```
|
package/dist/cli.js
CHANGED
|
@@ -4,7 +4,7 @@ import * as path from 'node:path';
|
|
|
4
4
|
import process from 'node:process';
|
|
5
5
|
import { fileURLToPath } from 'node:url';
|
|
6
6
|
import { loadBaseline, partitionByBaseline, writeBaseline } from "./baseline.js";
|
|
7
|
-
import { loadConfig, meetsConfidence } from "./config.js";
|
|
7
|
+
import { confidenceRank, loadConfig, meetsConfidence } from "./config.js";
|
|
8
8
|
import { assertSafeRef, diffSince, findRepoRoot, isInDiffWithPrefix } from "./diff.js";
|
|
9
9
|
import { scanProject } from "./engine.js";
|
|
10
10
|
import { serveMcp } from "./mcp.js";
|
|
@@ -265,7 +265,7 @@ const INIT_CONFIG = {
|
|
|
265
265
|
confidence: 'high',
|
|
266
266
|
failOn: 'high',
|
|
267
267
|
};
|
|
268
|
-
const INIT_WORKFLOW = `name: slopgate
|
|
268
|
+
const INIT_WORKFLOW = (version) => `name: slopgate
|
|
269
269
|
|
|
270
270
|
on:
|
|
271
271
|
push:
|
|
@@ -285,26 +285,26 @@ jobs:
|
|
|
285
285
|
with:
|
|
286
286
|
node-version: 22
|
|
287
287
|
- name: Scan for AI slop
|
|
288
|
-
run: npx --yes @voidh4x0r/slopgate
|
|
288
|
+
run: npx --yes @voidh4x0r/slopgate@${version} . --fail-on high --format pretty
|
|
289
289
|
`;
|
|
290
|
-
async function runInit(options, io) {
|
|
290
|
+
async function runInit(options, io, version) {
|
|
291
291
|
const root = path.resolve(options.paths[0] ?? '.');
|
|
292
292
|
await mkdir(root, { recursive: true });
|
|
293
293
|
const configPath = path.join(root, '.slopgate.json');
|
|
294
294
|
const workflowPath = path.join(root, '.github', 'workflows', 'slopgate.yml');
|
|
295
295
|
if (!options.force && (await exists(configPath))) {
|
|
296
|
-
warn(io, options, `${configPath} already exists (use --force to overwrite)`);
|
|
296
|
+
warn(io, options, `${path.relative(process.cwd(), configPath)} already exists (use --force to overwrite)`);
|
|
297
297
|
}
|
|
298
298
|
else {
|
|
299
299
|
await writeFile(configPath, JSON.stringify(INIT_CONFIG, null, 2) + '\n', 'utf8');
|
|
300
300
|
writeOut(io, `created ${path.relative(process.cwd(), configPath)}`);
|
|
301
301
|
}
|
|
302
302
|
if (!options.force && (await exists(workflowPath))) {
|
|
303
|
-
warn(io, options, `${workflowPath} already exists (use --force to overwrite)`);
|
|
303
|
+
warn(io, options, `${path.relative(process.cwd(), workflowPath)} already exists (use --force to overwrite)`);
|
|
304
304
|
}
|
|
305
305
|
else {
|
|
306
306
|
await mkdir(path.dirname(workflowPath), { recursive: true });
|
|
307
|
-
await writeFile(workflowPath, INIT_WORKFLOW, 'utf8');
|
|
307
|
+
await writeFile(workflowPath, INIT_WORKFLOW(version), 'utf8');
|
|
308
308
|
writeOut(io, `created ${path.relative(process.cwd(), workflowPath)}`);
|
|
309
309
|
}
|
|
310
310
|
writeOut(io, 'next: npx @voidh4x0r/slopgate . --write-baseline, then commit the baseline');
|
|
@@ -354,11 +354,20 @@ async function runScan(options, io) {
|
|
|
354
354
|
config: merged,
|
|
355
355
|
...(options.rules.length > 0 ? { onlyRules: new Set(options.rules) } : {}),
|
|
356
356
|
});
|
|
357
|
-
if (result.stats.files === 0) {
|
|
358
|
-
warn(io, options, `no files matched under ${path.relative(process.cwd(), target) || '.'} (check include/exclude patterns)`);
|
|
359
|
-
}
|
|
360
357
|
for (const message of result.warnings)
|
|
361
358
|
warn(io, options, message);
|
|
359
|
+
if (result.stats.files === 0) {
|
|
360
|
+
throw new Error(`no files matched under ${path.relative(process.cwd(), target) || '.'} (check include/exclude patterns)`);
|
|
361
|
+
}
|
|
362
|
+
const baselinePath = path.resolve(projectRoot, options.baseline ?? DEFAULT_BASELINE);
|
|
363
|
+
const explicitWrite = options.writeBaseline;
|
|
364
|
+
if (explicitWrite) {
|
|
365
|
+
const writeTarget = path.resolve(projectRoot, explicitWrite);
|
|
366
|
+
// Record the current findings, not the diff-filtered subset.
|
|
367
|
+
await writeBaseline(writeTarget, result.findings);
|
|
368
|
+
writeOut(io, `wrote ${result.findings.length} findings to ${path.relative(process.cwd(), writeTarget)}`);
|
|
369
|
+
return 0;
|
|
370
|
+
}
|
|
362
371
|
let findings = result.findings;
|
|
363
372
|
let onlyDiff = 0;
|
|
364
373
|
if (options.diff !== undefined) {
|
|
@@ -370,20 +379,17 @@ async function runScan(options, io) {
|
|
|
370
379
|
findings = findings.filter((finding) => isInDiffWithPrefix(finding, set, prefix));
|
|
371
380
|
onlyDiff = before - findings.length;
|
|
372
381
|
}
|
|
373
|
-
const baselinePath = path.resolve(projectRoot, options.baseline ?? DEFAULT_BASELINE);
|
|
374
|
-
const explicitWrite = options.writeBaseline;
|
|
375
|
-
if (explicitWrite) {
|
|
376
|
-
const writeTarget = path.resolve(projectRoot, explicitWrite);
|
|
377
|
-
await writeBaseline(writeTarget, findings);
|
|
378
|
-
writeOut(io, `wrote ${findings.length} findings to ${path.relative(process.cwd(), writeTarget)}`);
|
|
379
|
-
return 0;
|
|
380
|
-
}
|
|
381
382
|
const baseline = (await loadBaseline(baselinePath)) ?? undefined;
|
|
382
383
|
if (baseline === undefined && options.baseline !== undefined) {
|
|
383
384
|
throw new Error(`baseline file not found: ${baselinePath}`);
|
|
384
385
|
}
|
|
385
386
|
const { fresh, known } = partitionByBaseline(findings, baseline);
|
|
386
|
-
|
|
387
|
+
// `--fail-on` below `--confidence` must lower the display threshold too,
|
|
388
|
+
// otherwise the setting can never fail CI (the findings are filtered out).
|
|
389
|
+
const displayConfidence = merged.failOn === 'none' || confidenceRank(merged.confidence) <= confidenceRank(merged.failOn)
|
|
390
|
+
? merged.confidence
|
|
391
|
+
: merged.failOn;
|
|
392
|
+
const visible = fresh.filter((finding) => meetsConfidence(finding.confidence, displayConfidence));
|
|
387
393
|
const hidden = fresh.length - visible.length;
|
|
388
394
|
const run = {
|
|
389
395
|
visible,
|
|
@@ -449,7 +455,7 @@ export async function main(argv, io = defaultIo()) {
|
|
|
449
455
|
case 'rules':
|
|
450
456
|
return await runRules(options, io);
|
|
451
457
|
case 'init':
|
|
452
|
-
return await runInit(options, io);
|
|
458
|
+
return await runInit(options, io, await readVersion());
|
|
453
459
|
case 'mcp':
|
|
454
460
|
return await runMcp(options);
|
|
455
461
|
case 'scan':
|
package/dist/config.js
CHANGED
|
@@ -54,7 +54,8 @@ export function normalizeConfig(raw) {
|
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
if (input.confidence !== undefined) {
|
|
57
|
-
if (typeof input.confidence !== 'string' ||
|
|
57
|
+
if (typeof input.confidence !== 'string' ||
|
|
58
|
+
!Object.hasOwn(CONFIDENCE_RANK, input.confidence)) {
|
|
58
59
|
throw new Error('config field "confidence" must be "high", "medium" or "low"');
|
|
59
60
|
}
|
|
60
61
|
config.confidence = input.confidence;
|
|
@@ -7,9 +7,11 @@
|
|
|
7
7
|
*/
|
|
8
8
|
export declare const PYTHON_STDLIB: ReadonlySet<string>;
|
|
9
9
|
/**
|
|
10
|
-
* Import
|
|
11
|
-
* from the name you put in a manifest.
|
|
12
|
-
*
|
|
10
|
+
* Import path -> distribution name, for packages whose import name differs
|
|
11
|
+
* from the name you put in a manifest. Keys are case-sensitive and may be
|
|
12
|
+
* dotted; the longest matching prefix wins (`google.protobuf` before `google`).
|
|
13
|
+
* Without this map the dependency check would produce false positives on very
|
|
14
|
+
* common packages.
|
|
13
15
|
*/
|
|
14
16
|
export declare const IMPORT_TO_DISTRIBUTION: Readonly<Record<string, string>>;
|
|
15
17
|
/**
|
|
@@ -41,9 +41,11 @@ export const PYTHON_STDLIB = new Set([
|
|
|
41
41
|
'zlib', 'zoneinfo',
|
|
42
42
|
]);
|
|
43
43
|
/**
|
|
44
|
-
* Import
|
|
45
|
-
* from the name you put in a manifest.
|
|
46
|
-
*
|
|
44
|
+
* Import path -> distribution name, for packages whose import name differs
|
|
45
|
+
* from the name you put in a manifest. Keys are case-sensitive and may be
|
|
46
|
+
* dotted; the longest matching prefix wins (`google.protobuf` before `google`).
|
|
47
|
+
* Without this map the dependency check would produce false positives on very
|
|
48
|
+
* common packages.
|
|
47
49
|
*/
|
|
48
50
|
export const IMPORT_TO_DISTRIBUTION = {
|
|
49
51
|
attr: 'attrs',
|
|
@@ -51,18 +53,33 @@ export const IMPORT_TO_DISTRIBUTION = {
|
|
|
51
53
|
cv2: 'opencv-python',
|
|
52
54
|
Crypto: 'pycryptodome',
|
|
53
55
|
dateutil: 'python-dateutil',
|
|
56
|
+
docx: 'python-docx',
|
|
54
57
|
dotenv: 'python-dotenv',
|
|
55
|
-
|
|
58
|
+
fitz: 'pymupdf',
|
|
59
|
+
git: 'gitpython',
|
|
60
|
+
grpc: 'grpcio',
|
|
61
|
+
'google.protobuf': 'protobuf',
|
|
62
|
+
googleapiclient: 'google-api-python-client',
|
|
63
|
+
jose: 'python-jose',
|
|
56
64
|
jwt: 'pyjwt',
|
|
65
|
+
ldap: 'python-ldap',
|
|
57
66
|
magic: 'python-magic',
|
|
58
67
|
MySQLdb: 'mysqlclient',
|
|
68
|
+
nacl: 'pynacl',
|
|
59
69
|
OpenSSL: 'pyopenssl',
|
|
60
70
|
PIL: 'pillow',
|
|
61
71
|
pkg_resources: 'setuptools',
|
|
72
|
+
pptx: 'python-pptx',
|
|
62
73
|
psycopg2: 'psycopg2-binary',
|
|
74
|
+
rest_framework: 'djangorestframework',
|
|
63
75
|
serial: 'pyserial',
|
|
64
|
-
sklearn: 'scikit-learn',
|
|
65
76
|
skimage: 'scikit-image',
|
|
77
|
+
sklearn: 'scikit-learn',
|
|
78
|
+
slugify: 'python-slugify',
|
|
79
|
+
socks: 'pysocks',
|
|
80
|
+
win32api: 'pywin32',
|
|
81
|
+
win32com: 'pywin32',
|
|
82
|
+
Xlib: 'python-xlib',
|
|
66
83
|
yaml: 'pyyaml',
|
|
67
84
|
zmq: 'pyzmq',
|
|
68
85
|
};
|
package/dist/deps.js
CHANGED
|
@@ -42,6 +42,99 @@ function quotedStrings(text) {
|
|
|
42
42
|
}
|
|
43
43
|
return out;
|
|
44
44
|
}
|
|
45
|
+
/** Split an array body on commas outside quotes and inline tables. */
|
|
46
|
+
function splitTopLevel(value) {
|
|
47
|
+
const parts = [];
|
|
48
|
+
let quote;
|
|
49
|
+
let depth = 0;
|
|
50
|
+
let start = 0;
|
|
51
|
+
for (let i = 0; i < value.length; i += 1) {
|
|
52
|
+
const ch = value[i];
|
|
53
|
+
if (quote) {
|
|
54
|
+
if (ch === quote && value[i - 1] !== '\\')
|
|
55
|
+
quote = undefined;
|
|
56
|
+
}
|
|
57
|
+
else if (ch === '"' || ch === "'") {
|
|
58
|
+
quote = ch;
|
|
59
|
+
}
|
|
60
|
+
else if (ch === '{') {
|
|
61
|
+
depth += 1;
|
|
62
|
+
}
|
|
63
|
+
else if (ch === '}') {
|
|
64
|
+
depth -= 1;
|
|
65
|
+
}
|
|
66
|
+
else if (ch === ',' && depth === 0) {
|
|
67
|
+
parts.push(value.slice(start, i));
|
|
68
|
+
start = i + 1;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
parts.push(value.slice(start));
|
|
72
|
+
return parts;
|
|
73
|
+
}
|
|
74
|
+
/** True when the (possibly multi-line) array body contains its closing `]`. */
|
|
75
|
+
function closesArray(value) {
|
|
76
|
+
let quote;
|
|
77
|
+
for (let i = 0; i < value.length; i += 1) {
|
|
78
|
+
const ch = value[i];
|
|
79
|
+
if (quote) {
|
|
80
|
+
if (ch === quote && value[i - 1] !== '\\')
|
|
81
|
+
quote = undefined;
|
|
82
|
+
}
|
|
83
|
+
else if (ch === '"' || ch === "'") {
|
|
84
|
+
quote = ch;
|
|
85
|
+
}
|
|
86
|
+
else if (ch === ']') {
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* PEP 621 / PEP 735 arrays contain requirement strings and
|
|
94
|
+
* `{ include-group = "name" }` tables. Taking the first quoted token of each
|
|
95
|
+
* entry avoids treating environment markers as package names.
|
|
96
|
+
*/
|
|
97
|
+
function arrayEntries(body) {
|
|
98
|
+
const requirements = [];
|
|
99
|
+
const includes = [];
|
|
100
|
+
for (const entry of splitTopLevel(body)) {
|
|
101
|
+
const trimmed = entry.trim();
|
|
102
|
+
if (trimmed.length === 0)
|
|
103
|
+
continue;
|
|
104
|
+
const include = /include-group\s*=\s*["']([^"']+)["']/.exec(trimmed);
|
|
105
|
+
if (include?.[1]) {
|
|
106
|
+
includes.push(include[1]);
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
const first = /^"([^"\\]*(?:\\.[^"\\]*)*)"|^'([^'\\]*(?:\\.[^'\\]*)*)'/.exec(trimmed);
|
|
110
|
+
const value = first?.[1] ?? first?.[2];
|
|
111
|
+
if (!value)
|
|
112
|
+
continue;
|
|
113
|
+
const name = requirementName(value);
|
|
114
|
+
if (name)
|
|
115
|
+
requirements.push(name);
|
|
116
|
+
}
|
|
117
|
+
return { requirements, includes };
|
|
118
|
+
}
|
|
119
|
+
const POETRY_GROUP = /^tool\.poetry\.group\.([^.]+)\.dependencies$/;
|
|
120
|
+
/** Key of a simple `key = value` / `key = [` line, including quoted keys. */
|
|
121
|
+
function tomlKey(line) {
|
|
122
|
+
const match = /^\s*(?:"([^"]+)"|'([^']+)'|([A-Za-z0-9_.-]+))\s*=/.exec(line);
|
|
123
|
+
return match?.[1] ?? match?.[2] ?? match?.[3];
|
|
124
|
+
}
|
|
125
|
+
function isPyprojectArraySection(section, key) {
|
|
126
|
+
if (section === 'project')
|
|
127
|
+
return key === 'dependencies';
|
|
128
|
+
if (section === 'project.optional-dependencies')
|
|
129
|
+
return true;
|
|
130
|
+
if (section === 'dependency-groups')
|
|
131
|
+
return true;
|
|
132
|
+
if (section === 'tool.uv')
|
|
133
|
+
return key === 'dev-dependencies';
|
|
134
|
+
if (section === 'build-system')
|
|
135
|
+
return key === 'requires';
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
45
138
|
/** Best-effort parse of the Python dependency declarations we can see. */
|
|
46
139
|
export function parsePythonManifestText(fileName, text) {
|
|
47
140
|
const names = [];
|
|
@@ -56,56 +149,75 @@ export function parsePythonManifestText(fileName, text) {
|
|
|
56
149
|
return names;
|
|
57
150
|
}
|
|
58
151
|
if (base === 'pyproject.toml') {
|
|
59
|
-
const
|
|
152
|
+
const names = [];
|
|
153
|
+
const groups = new Map();
|
|
60
154
|
let section = '';
|
|
61
|
-
let
|
|
62
|
-
|
|
155
|
+
let pending;
|
|
156
|
+
const collect = (targetSection, key, body) => {
|
|
157
|
+
const entries = arrayEntries(body);
|
|
158
|
+
if (targetSection === 'dependency-groups') {
|
|
159
|
+
const group = groups.get(key) ?? { requirements: [], includes: [] };
|
|
160
|
+
group.requirements.push(...entries.requirements);
|
|
161
|
+
group.includes.push(...entries.includes);
|
|
162
|
+
groups.set(key, group);
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
names.push(...entries.requirements);
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
for (const rawLine of text.split(/\r?\n/)) {
|
|
63
169
|
const line = stripTomlComments(rawLine);
|
|
170
|
+
if (pending) {
|
|
171
|
+
pending.buffer += '\n' + line;
|
|
172
|
+
if (closesArray(line)) {
|
|
173
|
+
collect(pending.section, pending.key, pending.buffer);
|
|
174
|
+
pending = undefined;
|
|
175
|
+
}
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
64
178
|
const sectionMatch = /^\s*\[([^\]]+)\]\s*$/.exec(line);
|
|
65
179
|
if (sectionMatch?.[1]) {
|
|
66
180
|
section = sectionMatch[1].trim();
|
|
67
181
|
continue;
|
|
68
182
|
}
|
|
69
|
-
|
|
70
|
-
for (const value of quotedStrings(line)) {
|
|
71
|
-
const name = requirementName(value);
|
|
72
|
-
if (name)
|
|
73
|
-
names.push(name);
|
|
74
|
-
}
|
|
75
|
-
if (line.includes(']'))
|
|
76
|
-
arrayRemaining = 0;
|
|
77
|
-
continue;
|
|
78
|
-
}
|
|
79
|
-
const arrayStart = /^\s*(dependencies|requires)\s*=\s*\[(.*)$/.exec(line);
|
|
183
|
+
const arrayStart = /^\s*(?:"([^"]+)"|'([^']+)'|([A-Za-z0-9_.-]+))\s*=\s*\[(.*)$/.exec(line);
|
|
80
184
|
if (arrayStart) {
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
if (
|
|
85
|
-
|
|
185
|
+
const key = arrayStart[1] ?? arrayStart[2] ?? arrayStart[3] ?? '';
|
|
186
|
+
const rest = arrayStart[4] ?? '';
|
|
187
|
+
if (isPyprojectArraySection(section, key)) {
|
|
188
|
+
if (closesArray(rest))
|
|
189
|
+
collect(section, key, rest);
|
|
190
|
+
else
|
|
191
|
+
pending = { section, key, buffer: rest };
|
|
86
192
|
}
|
|
87
|
-
if (!inline.includes(']'))
|
|
88
|
-
arrayRemaining = 1;
|
|
89
193
|
continue;
|
|
90
194
|
}
|
|
91
|
-
if (section === 'tool.poetry.dependencies' ||
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
if (section === 'build-system') {
|
|
98
|
-
const requires = /^\s*requires\s*=\s*\[(.*)/.exec(line);
|
|
99
|
-
if (requires?.[1] !== undefined) {
|
|
100
|
-
for (const value of quotedStrings(requires[1])) {
|
|
101
|
-
const name = requirementName(value);
|
|
102
|
-
if (name)
|
|
103
|
-
names.push(name);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
195
|
+
if (section === 'tool.poetry.dependencies' ||
|
|
196
|
+
section === 'tool.poetry.dev-dependencies' ||
|
|
197
|
+
POETRY_GROUP.test(section)) {
|
|
198
|
+
const key = tomlKey(line);
|
|
199
|
+
if (key && key.toLowerCase() !== 'python')
|
|
200
|
+
names.push(normalizePythonName(key));
|
|
106
201
|
}
|
|
107
202
|
}
|
|
108
|
-
|
|
203
|
+
// Resolve PEP 735 include-group references (with cycle protection).
|
|
204
|
+
const resolved = new Set();
|
|
205
|
+
const resolveGroup = (name, seen) => {
|
|
206
|
+
if (seen.has(name))
|
|
207
|
+
return;
|
|
208
|
+
seen.add(name);
|
|
209
|
+
const group = groups.get(name);
|
|
210
|
+
if (!group)
|
|
211
|
+
return;
|
|
212
|
+
for (const requirement of group.requirements)
|
|
213
|
+
resolved.add(requirement);
|
|
214
|
+
for (const include of group.includes)
|
|
215
|
+
resolveGroup(include, seen);
|
|
216
|
+
};
|
|
217
|
+
for (const name of groups.keys())
|
|
218
|
+
resolveGroup(name, new Set());
|
|
219
|
+
names.push(...resolved);
|
|
220
|
+
return [...new Set(names)];
|
|
109
221
|
}
|
|
110
222
|
if (base === 'setup.py') {
|
|
111
223
|
const blocks = [...text.matchAll(/install_requires\s*=\s*\[([\s\S]*?)\]/g)];
|