@blundergoat/gruff-ts 0.1.1 → 0.2.0
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 +31 -19
- package/README.md +26 -26
- package/docs/configuration.md +39 -1
- package/docs/dashboard.md +7 -0
- package/docs/output-formats.md +1 -1
- package/docs/releasing.md +11 -10
- package/docs/reports-and-ci.md +5 -2
- package/package.json +1 -1
- package/scripts/bump-version.sh +19 -3
- package/scripts/preflight-checks.sh +4 -41
- package/src/analyser.ts +4 -4
- package/src/blocks.ts +62 -8
- package/src/cli-program.ts +106 -42
- package/src/config-load-error.ts +18 -0
- package/src/config-preservation.ts +64 -0
- package/src/config.ts +154 -26
- package/src/constants.ts +10 -2
- package/src/dashboard.ts +1 -1
- package/src/dead-code-rules.ts +60 -14
- package/src/doc-rules.ts +3 -3
- package/src/findings-helpers.ts +17 -0
- package/src/init-config.ts +91 -31
- package/src/line-rules.ts +58 -4
- package/src/naming-pushers.ts +7 -1
- package/src/pillar-summary.ts +129 -0
- package/src/report-html.ts +404 -0
- package/src/report-renderers.ts +163 -408
- package/src/rule-list.ts +64 -1
- package/src/rules.ts +22 -21
- package/src/safety-rules.ts +6 -1
- package/src/scoring.ts +38 -6
- package/src/test-block-rules.ts +43 -1
- package/src/test-fixtures.ts +13 -5
- package/src/types.ts +31 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,28 +1,40 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## v0.2.0 - 2026-05-28
|
|
4
|
+
|
|
5
|
+
Cross-format Pillars table, per-command gating defaults, JSON schema bumps (`v1` → `v2`), exported-doc rule split, a rule-precision sweep, config schema-versioning, and a code-review sweep against PR #4 feedback. Cut as a pre-1.0 minor bump because the cumulative rule-emission changes (new exported-doc surface, tightened naming/test-quality exemptions, schemaVersion requirement) materially shift findings for downstream consumers.
|
|
6
|
+
|
|
7
|
+
- **Per-command gating + schemaVersion contract** - `analyse` and `summary` default `--fail-on` flips from `error` to `advisory`; CI gates using the defaults go from "fail on errors only" to "fail on anything." New `minimumSeverity:` block in `.gruff-ts.yaml` pins per-command thresholds (`analyse / summary / report`) with precedence CLI flag > config > binary default; `dashboard` is rejected as a key because it has no `--fail-on` flag. `.gruff-ts.yaml` now requires `schemaVersion: gruff-ts.config.v0.1` at the top - pre-1.0 hard break, no transitional shim. Run `npx gruff-ts init --force` to migrate; the regenerated config preserves `paths.ignore` and `minimumSeverity`. (ADR-004, `src/config.ts`, `src/cli-program.ts`)
|
|
8
|
+
- **Cross-format Pillars table** - Canonical 7-column table (`Pillar | Grade | Score | Findings | Advisory | Warning | Error`) renders byte-aligned across `text`, `json`, `html`, and `markdown`, sorted `findings DESC` then `pillar ASC`. Clean pillars render as `A/100` rows so the column layout stays stable run-to-run; cross-port consumers can diff byte-for-byte. (`src/pillar-summary.ts`, `src/report-renderers.ts`, `src/report-html.ts`)
|
|
9
|
+
- **JSON schema bumps `v1` → `v2`** - `summary --format=json` emits `gruff.summary.v2`; the flat `{pillar, count}` per-pillar array is replaced with a richer shape carrying `grade`, `score`, `penalty`, `applicable`, `findings`, `advisory`, `warning`, `error`. `analyse` / `report --format=json` emit `gruff.analysis.v2`; `score.pillars[]` entries gain a `penalty: number` field, and the SARIF `runs[0].properties.gruffSchemaVersion` plus the JSON `schemaVersion` tag move in lockstep. Downstream consumers must gate on the `schemaVersion` field before decoding.
|
|
10
|
+
- **Public-API doc gate** - `docs.missing-function-doc` (advisory) is split into `docs.missing-exported-function-doc` (**warning**) and `docs.missing-internal-function-doc` (advisory). The warning variant fires on `export function`, `export const f = () => ...`, `export default function`, and locally-declared functions re-exported via `export { foo }` or `export default foo`; `export { foo } from "./other"` re-export-from clauses are correctly skipped via negative lookahead so a same-named local stays internal. Class methods of exported classes are intentionally treated as internal (advisory) by this release; enclosing-class scope tracking is deferred. Any `.gruff-ts.yaml` override targeting the old rule ID must be updated. (M04, `src/blocks.ts`, `src/doc-rules.ts`)
|
|
11
|
+
- **Summary readability + rule explain mode** - Per-severity grade breakdown under the composite (`Errors: A (0)`, `Warnings: D (276)`, `Advisory: F (1367)`) tells you whether an F composite is driven by errors or by a long tail of advisories; three grade pills in HTML. `summary` Top-N rule rows now show per-severity split and one-line descriptions: `- <ruleId>: <total> (<err> err / <warn> warn / <adv> adv) - <description>`; a `Tip:` line points at `summary --top=20` when `analyse` produces 50+ findings. `gruff-ts list-rules <ruleId>` accepts a positional argument and prints per-rule detail (text or JSON) with `Config keys:`, `Options:`, and `Allowlists:` blocks. Every tunable rule's `remediation` text now names its override knob (`rules.<id>.threshold`, `rules.<id>.severity`, allowlist keys) so the configuration surface is one greppable string away from any finding. (M05-M08)
|
|
12
|
+
- **Rule-precision sweep** - `naming.short-variable` exempts single-character `for (const X of Y)` bindings whose body is ≤ 10 lines (and only those; classic `for (let i = 0; ...)` and `for (const k in obj)` stay covered). `test-quality.loop-in-test` recognises fixture loops (literal-array iterable or `Object.entries|keys|values(literal)`, no conditional bodies, last meaningful statement is an assertion) and suppresses the finding for them. `waste.swallowed-catch` accepts six additional rationale comments: `/* ignore */`, `/* ignored */`, `/* cleanup */`, `/* teardown */`, `/* noop */`, `/* no-op */`. `waste.unreachable-code` no longer fires on the unconditional return after a braceless `if`/`while`/`for` with a multi-line predicate. Nine imperative-flag verbs added to default `booleanPrefixes` (`check`, `skip`, `enable`, `allow`, `include`, `exclude`, `with`, `without`, `omit`); `fn` and `cb` added to default `acceptedAbbreviations`. (M01-M03)
|
|
13
|
+
- **Severity-only rule overrides accepted** - `rules.<id>.severity: warning` now loads without requiring `threshold`, fixing the validator that previously blocked any severity tweak on rules with no `threshold` knob (security, naming, docs, etc.) even though `gruff-ts list-rules` advertised the override. Each field is independently optional. (`src/config.ts:assertRuleThresholdConfig`)
|
|
14
|
+
- **Graceful CLI config errors** - Malformed `.gruff-ts.yaml`, missing `--config <path>`, and syntax errors in `.gruff.json` produce a formatted `gruff-ts: config error\n ...\nSuggested fix: ...` message and exit code 2; raw `ENOENT` / `SyntaxError` no longer leak through as Node stack traces. `init --force` over pre-schemaVersion configs preserves `paths.ignore` and `minimumSeverity` via a new permissive reader (`src/config-preservation.ts`), so existing curated entries survive the schemaVersion migration. (`src/cli-program.ts:runWithConfigErrorHandling`, `src/config.ts:parseConfigFile`, `src/init-config.ts`)
|
|
15
|
+
- **Release tooling** - `scripts/bump-version.sh --check` verifies `CHANGELOG.md`'s most-recent version heading agrees with `package.json` / `package-lock.json` / `src/constants.ts`; the preflight gate's `Version consistency` step uses it. The awk regex skips non-version headings (e.g. `## [Unreleased]`-style entries from third-party Keep-a-Changelog projects).
|
|
16
|
+
- **Regression coverage** - FP-#12 through FP-#45 added to `src/false-positive-fixes.test.ts`, covering every rule-precision change above plus negative regression guards. The PR #4 review sweep added FP-#33b through FP-#33e for re-export detection, the C-style for / for-in regression cases under `naming-rules.test.ts`, the pre-schemaVersion preservation regression in `src/init-config.test.ts`, and the dedicated `src/config-preservation.test.ts` suite. M06 / M08 land their tests in `src/rule-catalogue.test.ts` and `src/cli-surfaces.test.ts` respectively; M10-M12 add parser-rejection tests in `src/project-config-rules.test.ts`. M09 (informational tier) was deleted as a no-signal milestone.
|
|
17
|
+
- **Cross-port harmony** - `minimumSeverity:` dimension aligns with the gruff family (`gruff-go` / `gruff-rs` / `gruff-py` / `gruff-php` should track). Off-switch value is `none` (not `never`) per the noun-position re-evaluation; the verb-shaped `failOn: never` was the prior cross-port draft, the noun-shaped `minimumSeverity: none` is the family-wide decision.
|
|
18
|
+
|
|
19
|
+
## v0.1.1 - 2026-05-24
|
|
4
20
|
|
|
5
21
|
Onboarding flow, machine-readable summaries, and a `waste` → `maintainability` pillar rename. Catalogue is now 119 rules across 11 pillars.
|
|
6
22
|
|
|
7
|
-
- **
|
|
8
|
-
- **
|
|
9
|
-
-
|
|
10
|
-
- **
|
|
11
|
-
- **
|
|
12
|
-
- **
|
|
13
|
-
- **
|
|
23
|
+
- **Pillar rename `waste` → `maintainability`** - The pillar tag attached to every finding from a `waste.*` rule changed; rule IDs themselves keep their `waste.` prefix (so `waste.console-log` still fires as `waste.console-log`, only its pillar attribute moves). Text/JSON/SARIF parsers, dashboard nav, and the `Pillar` TypeScript union in `src/types.ts` must update.
|
|
24
|
+
- **Removed rules and config keys** - `docs.todo-density` and `naming.abbreviation` (both opt-in advisories) removed, along with the now-unused `allowlists.abbreviationDenylist` config key; stale config entries are silently ignored so existing `.gruff-ts.yaml` files keep loading. Consumers relying on either rule for CI gating lose that signal.
|
|
25
|
+
- **`gruff-ts init`** - Writes the default `.gruff-ts.yaml`, refusing to overwrite any supported config name without `--force` (which preserves existing `paths.ignore` entries). `analyse`, `summary`, `report`, and `dashboard` auto-prompt for `init` when no config is found, gated by `--no-interaction`, `--silent`/`--quiet`, and TTY checks so it never fires in CI.
|
|
26
|
+
- **Machine-readable summaries** - `summary --format=json` emits the new `gruff.summary.v1` schema; `summary --top <n>` controls digest size; a baseline status line surfaces source and suppression count. `dashboard --project-root <path>` sets the default scan root.
|
|
27
|
+
- **Docs index + audit gate** - New `docs/README.md` index plus `ci-integration.md`, `dashboard.md`, `output-formats.md`, `rules.md`; CI now runs `npm audit --audit-level=moderate`.
|
|
28
|
+
- **CLI input rejection + async exits** - `summary` and `list-rules` reject unsupported `--format` values via Commander instead of coercing to `text`; CLI switched to `parseAsync` so async handler rejections exit with the correct code.
|
|
29
|
+
- **Top-offender + flag-knowledge fixes** - `summary --top <n>` controls file-offender count beyond 10. `gruff.analysis.v1` `score.topOffenders` is now the full sorted file list (was capped at 10); HTML report and `--format=hotspot` still cap their own output at 10 rows. `init --force` help text now reflects that it also overrides the refusal triggered by non-canonical configs (`.gruff.yaml`/`.yml`/`.json`). `--top` added to the known-CLI-flag list so comments documenting it no longer trip `docs.stale-comment`.
|
|
30
|
+
- **Doc filename normalisation** - `CONFIGURATION.md` → `configuration.md`, `RELEASING.md` → `releasing.md`, `REPORTS_AND_CI.md` → `reports-and-ci.md`.
|
|
14
31
|
|
|
15
|
-
##
|
|
32
|
+
## v0.1.0 - 2026-05-23
|
|
16
33
|
|
|
17
34
|
Initial public release of the `@blundergoat/gruff-ts` npm package.
|
|
18
35
|
|
|
19
|
-
- TypeScript/JavaScript code
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
-
|
|
23
|
-
|
|
24
|
-
- Output formats: `text`, `json`, `html`, `markdown`, `github`, `hotspot`,
|
|
25
|
-
`sarif`. Stable schemas: `gruff.analysis.v1`, `gruff.baseline.v1`,
|
|
26
|
-
`gruff.hotspot.v1`.
|
|
27
|
-
- Baselines via stable per-finding fingerprints, `--diff` for changed-file
|
|
28
|
-
scans, local dashboard on `127.0.0.1:8767`. Released under MIT.
|
|
36
|
+
- **TypeScript/JavaScript code-quality scanner** - 121 rules across 11 pillars: complexity, dead-code, design, documentation, maintainability, modernisation, naming, security, sensitive-data, size, test-quality.
|
|
37
|
+
- **CLI commands** - `analyse`, `summary`, `report`, `list-rules`, `dashboard`, `completion`.
|
|
38
|
+
- **Output formats** - `text`, `json`, `html`, `markdown`, `github`, `hotspot`, `sarif`. Stable schemas: `gruff.analysis.v1`, `gruff.baseline.v1`, `gruff.hotspot.v1`.
|
|
39
|
+
- **Baselines and diff scans** - Stable per-finding fingerprints; `--diff` for changed-file scans against the prior baseline. Local dashboard on `127.0.0.1:8767`.
|
|
40
|
+
- **License** - Released under MIT.
|
package/README.md
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
# gruff-ts
|
|
2
2
|
|
|
3
|
-
`gruff-ts` is an opinionated static
|
|
3
|
+
`gruff-ts` is an opinionated static analyser for TypeScript and JavaScript projects. The dependency-light Node.js CLI scans source, tests, package metadata, and common config files, then emits reports for terminals, CI annotations, SARIF consumers, static HTML, and a local dashboard. It is heuristic static analysis; run it beside `tsc`, ESLint, tests, dependency scanners, and code review, not instead of them.
|
|
4
4
|
|
|
5
5
|
## Status At A Glance
|
|
6
6
|
|
|
7
7
|
| Field | Value |
|
|
8
8
|
| --- | --- |
|
|
9
|
-
| Release line | Published `0.
|
|
9
|
+
| Release line | Published `0.2.0` package line |
|
|
10
10
|
| Runtime | Node.js `22+` |
|
|
11
11
|
| Package | `@blundergoat/gruff-ts` |
|
|
12
12
|
| Binary | `gruff-ts` |
|
|
13
13
|
| Rule catalogue | 119 rules across 11 pillars |
|
|
14
14
|
| Primary config | `.gruff-ts.yaml`; `.gruff.json`, `.gruff.yaml`, and `.gruff.yml` are fallback files |
|
|
15
|
-
| Analysis schema | `gruff.analysis.
|
|
15
|
+
| Analysis schema | `gruff.analysis.v2` |
|
|
16
16
|
| Baseline schema | `gruff.baseline.v1` |
|
|
17
17
|
| Severity gate | `--fail-on` with `none`, `advisory`, `warning`, `error` |
|
|
18
18
|
| Dashboard | `127.0.0.1:8767` by default |
|
|
@@ -31,8 +31,8 @@ Install as a project dev dependency:
|
|
|
31
31
|
|
|
32
32
|
```bash
|
|
33
33
|
npm install --save-dev @blundergoat/gruff-ts
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
npx gruff-ts init
|
|
35
|
+
npx gruff-ts summary
|
|
36
36
|
```
|
|
37
37
|
|
|
38
38
|
From this checkout:
|
|
@@ -46,25 +46,25 @@ npm install
|
|
|
46
46
|
|
|
47
47
|
```bash
|
|
48
48
|
# Create the project config.
|
|
49
|
-
|
|
49
|
+
npx gruff-ts init
|
|
50
50
|
|
|
51
51
|
# Review the current finding mix.
|
|
52
|
-
|
|
52
|
+
npx gruff-ts summary
|
|
53
53
|
|
|
54
54
|
# Explore without failing because of findings.
|
|
55
|
-
|
|
55
|
+
npx gruff-ts analyse . --fail-on=none
|
|
56
56
|
|
|
57
57
|
# Gate on warning and error findings.
|
|
58
|
-
|
|
58
|
+
npx gruff-ts analyse . --fail-on=warning
|
|
59
59
|
|
|
60
60
|
# Emit SARIF for code scanning.
|
|
61
|
-
|
|
61
|
+
npx gruff-ts analyse . --format=sarif --fail-on=none > gruff-ts.sarif
|
|
62
62
|
|
|
63
63
|
# Generate a fresh-start baseline.
|
|
64
|
-
|
|
64
|
+
npx gruff-ts analyse . --generate-baseline gruff-baseline.json --fail-on=none
|
|
65
65
|
|
|
66
66
|
# Start the local dashboard.
|
|
67
|
-
|
|
67
|
+
npx gruff-ts dashboard
|
|
68
68
|
```
|
|
69
69
|
|
|
70
70
|
Open `http://127.0.0.1:8767/` for the dashboard.
|
|
@@ -73,7 +73,7 @@ Open `http://127.0.0.1:8767/` for the dashboard.
|
|
|
73
73
|
|
|
74
74
|
| Command | Purpose |
|
|
75
75
|
| --- | --- |
|
|
76
|
-
| `analyse [paths...]` | Run the
|
|
76
|
+
| `analyse [paths...]` | Run the analyser and print findings. |
|
|
77
77
|
| `summary [paths...]` | Print compact score, pillar, rule, and file summaries. |
|
|
78
78
|
| `report [paths...]` | Render an HTML or JSON report to stdout or `--output`. |
|
|
79
79
|
| `init` | Write the default `.gruff-ts.yaml` to the current directory (`--force` to overwrite). |
|
|
@@ -91,7 +91,7 @@ Global console options match the broader gruff CLI surface: `--silent`, `--quiet
|
|
|
91
91
|
| Format | Use it for |
|
|
92
92
|
| --- | --- |
|
|
93
93
|
| `text` | Human terminal output. |
|
|
94
|
-
| `json` | Full `gruff.analysis.
|
|
94
|
+
| `json` | Full `gruff.analysis.v2` report. |
|
|
95
95
|
| `html` | Self-contained inspection report. |
|
|
96
96
|
| `markdown` | Pull-request or issue comment summary. |
|
|
97
97
|
| `github` | GitHub Actions workflow annotations. |
|
|
@@ -108,26 +108,26 @@ Global console options match the broader gruff CLI surface: `--silent`, `--quiet
|
|
|
108
108
|
| `1` | At least one finding met `--fail-on`. |
|
|
109
109
|
| `2` | Fatal diagnostic such as missing input, parse error, config error, diff failure, baseline failure, or invalid input. |
|
|
110
110
|
|
|
111
|
-
`analyse` defaults to `--fail-on
|
|
111
|
+
`analyse` and `summary` default to `--fail-on advisory`; `report` defaults to `--fail-on none`. The defaults can be overridden per-project by a `minimumSeverity:` block in `.gruff-ts.yaml`. CLI flag wins over config; config wins over the binary default. See ADR-004 and the Configuration section.
|
|
112
112
|
|
|
113
113
|
## CI Usage
|
|
114
114
|
|
|
115
115
|
Generic CI command:
|
|
116
116
|
|
|
117
117
|
```bash
|
|
118
|
-
|
|
118
|
+
npx gruff-ts analyse . --format=github --fail-on=warning
|
|
119
119
|
```
|
|
120
120
|
|
|
121
121
|
SARIF jobs can write an artifact for code scanning:
|
|
122
122
|
|
|
123
123
|
```bash
|
|
124
|
-
|
|
124
|
+
npx gruff-ts analyse . --format=sarif --fail-on=none > gruff-ts.sarif
|
|
125
125
|
```
|
|
126
126
|
|
|
127
127
|
Security-focused gates can bypass adoption baselines:
|
|
128
128
|
|
|
129
129
|
```bash
|
|
130
|
-
|
|
130
|
+
npx gruff-ts analyse . --no-baseline --fail-on=error
|
|
131
131
|
```
|
|
132
132
|
|
|
133
133
|
## Configuration
|
|
@@ -181,23 +181,23 @@ The v0.1 catalogue contains 119 rules:
|
|
|
181
181
|
| `size` | 4 |
|
|
182
182
|
| `test-quality` | 15 |
|
|
183
183
|
|
|
184
|
-
Use
|
|
184
|
+
Use `npx gruff-ts list-rules --format=json` for exact rule IDs, severities, confidence levels, remediation text, thresholds, and options.
|
|
185
185
|
|
|
186
186
|
## Baselines And Changed-Code Scans
|
|
187
187
|
|
|
188
188
|
Baselines suppress reviewed findings by stable fingerprint:
|
|
189
189
|
|
|
190
190
|
```bash
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
191
|
+
npx gruff-ts analyse . --generate-baseline gruff-baseline.json --fail-on=none
|
|
192
|
+
npx gruff-ts analyse . --baseline gruff-baseline.json --fail-on=warning
|
|
193
|
+
npx gruff-ts analyse . --no-baseline --fail-on=none
|
|
194
194
|
```
|
|
195
195
|
|
|
196
196
|
Changed-file scans use Git only when requested:
|
|
197
197
|
|
|
198
198
|
```bash
|
|
199
|
-
|
|
200
|
-
|
|
199
|
+
npx gruff-ts analyse . --diff=working-tree --format=github --fail-on=warning
|
|
200
|
+
npx gruff-ts analyse . --diff=staged --format=json --fail-on=none
|
|
201
201
|
```
|
|
202
202
|
|
|
203
203
|
`--diff` accepts `working-tree`, `staged`, `unstaged`, or a base ref. `report` renders raw inspection output and does not accept `--baseline`; use `analyse` when baseline suppression matters.
|
|
@@ -205,7 +205,7 @@ Changed-file scans use Git only when requested:
|
|
|
205
205
|
## Dashboard
|
|
206
206
|
|
|
207
207
|
```bash
|
|
208
|
-
|
|
208
|
+
npx gruff-ts dashboard --host 127.0.0.1 --port 8767 --project-root .
|
|
209
209
|
```
|
|
210
210
|
|
|
211
211
|
The dashboard serves a local iframe report and compact controls panel. It has no authentication; keep the default loopback bind unless the network is trusted. The `/scan` endpoint analyses filesystem paths from request parameters, so the bind address is the main safety boundary.
|
|
@@ -218,7 +218,7 @@ Default scans are local source inspections. `gruff-ts` parses supported source,
|
|
|
218
218
|
|
|
219
219
|
## Stability Contract
|
|
220
220
|
|
|
221
|
-
The `0.1.x` line treats rule IDs, finding fingerprints, baseline identity, `gruff.analysis.
|
|
221
|
+
The `0.1.x` line treats rule IDs, finding fingerprints, baseline identity, `gruff.analysis.v2`, `gruff.baseline.v1`, `gruff.hotspot.v1`, SARIF rendering, and CLI exit semantics as compatibility-sensitive. Breaking changes should be tagged as a future minor release and recorded in [`CHANGELOG.md`](CHANGELOG.md).
|
|
222
222
|
|
|
223
223
|
## How It Compares
|
|
224
224
|
|
package/docs/configuration.md
CHANGED
|
@@ -25,9 +25,47 @@ Skip config for a run:
|
|
|
25
25
|
gruff-ts analyse . --no-config
|
|
26
26
|
```
|
|
27
27
|
|
|
28
|
+
## Required schema version
|
|
29
|
+
|
|
30
|
+
Every `.gruff-ts.yaml` must declare `schemaVersion: gruff-ts.config.v0.1` at the
|
|
31
|
+
top. Loading throws if the field is missing or carries a different value. The
|
|
32
|
+
field is in a different namespace from the output schemas (`gruff.analysis.v2`,
|
|
33
|
+
`gruff.summary.v2`, etc.) - the config-input version travels independently of
|
|
34
|
+
the output-payload versions. See ADR-004.
|
|
35
|
+
|
|
36
|
+
## minimumSeverity (per-command gating defaults)
|
|
37
|
+
|
|
38
|
+
A top-level `minimumSeverity:` block sets the default `--fail-on` value per
|
|
39
|
+
command. The precedence chain is **CLI flag > config > binary default**.
|
|
40
|
+
|
|
41
|
+
```yaml
|
|
42
|
+
schemaVersion: gruff-ts.config.v0.1
|
|
43
|
+
minimumSeverity:
|
|
44
|
+
analyse: advisory
|
|
45
|
+
summary: advisory
|
|
46
|
+
report: none
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Valid values: `advisory | warning | error | none`. The validator rejects any
|
|
50
|
+
other value (including `never`, which was an early cross-port draft for the
|
|
51
|
+
off-switch before the family converged on `none`).
|
|
52
|
+
|
|
53
|
+
`dashboard` is intentionally **not** a valid key in this block. The dashboard
|
|
54
|
+
subcommand has no `--fail-on` flag today; setting `minimumSeverity.dashboard:`
|
|
55
|
+
would be a silent no-op CI footgun, so the validator rejects it with a clear
|
|
56
|
+
error.
|
|
57
|
+
|
|
58
|
+
Binary defaults are `analyse: advisory`, `summary: advisory`, `report: none`.
|
|
59
|
+
|
|
28
60
|
## Shape
|
|
29
61
|
|
|
30
62
|
```yaml
|
|
63
|
+
schemaVersion: gruff-ts.config.v0.1
|
|
64
|
+
minimumSeverity:
|
|
65
|
+
analyse: advisory
|
|
66
|
+
summary: advisory
|
|
67
|
+
report: none
|
|
68
|
+
|
|
31
69
|
paths:
|
|
32
70
|
ignore:
|
|
33
71
|
- "generated/**"
|
|
@@ -105,7 +143,7 @@ allowlists:
|
|
|
105
143
|
Prefer fixing false positives with a narrow config entry instead of disabling an
|
|
106
144
|
entire sensitive-data rule.
|
|
107
145
|
|
|
108
|
-
Naming allowlists tune the 0.
|
|
146
|
+
Naming allowlists tune the 0.2.0 naming pack without changing rule ids or
|
|
109
147
|
fingerprints:
|
|
110
148
|
|
|
111
149
|
| Key | Used by | Default behavior |
|
package/docs/dashboard.md
CHANGED
|
@@ -22,6 +22,13 @@ The dashboard has no authentication and should stay bound to loopback unless the
|
|
|
22
22
|
network is trusted. The `/scan` endpoint analyses filesystem paths from request
|
|
23
23
|
parameters, so the bind address is the safety boundary.
|
|
24
24
|
|
|
25
|
+
## Gating threshold (none)
|
|
26
|
+
|
|
27
|
+
`dashboard` has no `--fail-on` flag and does not participate in the
|
|
28
|
+
`minimumSeverity:` config block - setting `minimumSeverity.dashboard:` in
|
|
29
|
+
`.gruff-ts.yaml` is rejected at config load. Whether the dashboard should gate
|
|
30
|
+
is a deferred design question; raise it as an issue if your workflow needs it.
|
|
31
|
+
|
|
25
32
|
## Polyglot Repos
|
|
26
33
|
|
|
27
34
|
`gruff-ts` defaults to port `8767`, `gruff-rs` defaults to `8766`, and Go, PHP,
|
package/docs/output-formats.md
CHANGED
|
@@ -14,7 +14,7 @@ Use `text` for local terminal scans:
|
|
|
14
14
|
|
|
15
15
|
## JSON
|
|
16
16
|
|
|
17
|
-
Use `json` for automation. JSON reports use `gruff.analysis.
|
|
17
|
+
Use `json` for automation. JSON reports use `gruff.analysis.v2`.
|
|
18
18
|
|
|
19
19
|
```sh
|
|
20
20
|
./bin/gruff-ts analyse src --format=json --fail-on=none > gruff-ts.json
|
package/docs/releasing.md
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
# Releasing
|
|
2
2
|
|
|
3
|
-
This checklist prepares
|
|
4
|
-
|
|
3
|
+
This checklist prepares public `@blundergoat/gruff-ts@0.1.x` patch releases.
|
|
4
|
+
Current release line: `0.2.0`.
|
|
5
5
|
|
|
6
6
|
## Bump The Version
|
|
7
7
|
|
|
8
8
|
`scripts/bump-version.sh <semver>` updates `package.json`,
|
|
9
9
|
`package-lock.json`, and `src/constants.ts` together so the CLI `--version`
|
|
10
10
|
output and the published `@blundergoat/gruff-ts` package version cannot drift
|
|
11
|
-
apart. For
|
|
12
|
-
use `--check` instead of bumping unless the
|
|
11
|
+
apart. For a no-op release (e.g. fixes folded into the current dated version),
|
|
12
|
+
the version should already match; use `--check` instead of bumping unless the
|
|
13
|
+
release version changes.
|
|
13
14
|
|
|
14
15
|
```bash
|
|
15
16
|
scripts/bump-version.sh --check
|
|
16
|
-
scripts/bump-version.sh 0.1.
|
|
17
|
+
scripts/bump-version.sh 0.1.3
|
|
17
18
|
scripts/bump-version.sh --check
|
|
18
19
|
```
|
|
19
20
|
|
|
@@ -30,10 +31,10 @@ update `CHANGELOG.md` and run `npm run check`.
|
|
|
30
31
|
explicitly accepted `human-verification-pending` milestones.
|
|
31
32
|
- [ ] `LICENSE` is present and `package.json` `license` field matches.
|
|
32
33
|
- [ ] `npm run check` passes.
|
|
33
|
-
- [ ] `scripts/preflight-checks.sh` passes (checks version lockstep
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
- [ ] `scripts/preflight-checks.sh` passes (checks version lockstep, runs
|
|
35
|
+
`npm audit --audit-level=moderate`, `npm run check`, a full `gruff-ts`
|
|
36
|
+
self-scan, and `shellcheck` on `scripts/*.sh` when `shellcheck` is
|
|
37
|
+
installed).
|
|
37
38
|
- [ ] `npm pack --dry-run` shows only publishable runtime, docs, scripts, and
|
|
38
39
|
metadata files.
|
|
39
40
|
- [ ] Local smoke scan succeeds:
|
|
@@ -101,5 +102,5 @@ prompts before publishing.
|
|
|
101
102
|
- [ ] Run `gruff-ts summary . --fail-on=none`.
|
|
102
103
|
- [ ] Run `gruff-ts list-rules`.
|
|
103
104
|
- [ ] Verify `README.md` install instructions from a clean checkout.
|
|
104
|
-
- [ ] Tag the release in git (`git tag v0.
|
|
105
|
+
- [ ] Tag the release in git (`git tag v0.2.0 && git push --tags`) and create
|
|
105
106
|
or update public release notes from `CHANGELOG.md`.
|
package/docs/reports-and-ci.md
CHANGED
|
@@ -45,7 +45,7 @@ per-pillar counts, top rules, and top file offenders.
|
|
|
45
45
|
|
|
46
46
|
Schema strings:
|
|
47
47
|
|
|
48
|
-
- `gruff.analysis.
|
|
48
|
+
- `gruff.analysis.v2` for full analysis reports.
|
|
49
49
|
- `gruff.baseline.v1` for baselines.
|
|
50
50
|
- `gruff.hotspot.v1` for hotspot output.
|
|
51
51
|
|
|
@@ -125,7 +125,10 @@ gruff-ts report . --format=json --output gruff-report.json
|
|
|
125
125
|
```
|
|
126
126
|
|
|
127
127
|
`report` defaults to `--fail-on none`, making it suitable for local inspection
|
|
128
|
-
and scheduled reporting.
|
|
128
|
+
and scheduled reporting. `analyse` and `summary` default to `--fail-on advisory`
|
|
129
|
+
out of the box; override per-project by setting `minimumSeverity:` in
|
|
130
|
+
`.gruff-ts.yaml`. See `docs/configuration.md` and ADR-004 for the precedence
|
|
131
|
+
chain (CLI flag > config > binary default).
|
|
129
132
|
|
|
130
133
|
## Dashboard
|
|
131
134
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blundergoat/gruff-ts",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Static analyzer for TypeScript and JavaScript projects - 119 rules across 11 quality pillars, SARIF output, baselines, and a local dashboard.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Matthew Hansen (https://www.blundergoat.com/about)",
|
package/scripts/bump-version.sh
CHANGED
|
@@ -15,7 +15,8 @@ Arguments:
|
|
|
15
15
|
<new-version> Target semver, e.g. 0.1.1, 0.2.0, 1.0.0-rc.1.
|
|
16
16
|
|
|
17
17
|
Options:
|
|
18
|
-
--check Verify package.json, package-lock.json,
|
|
18
|
+
--check Verify package.json, package-lock.json, src/constants.ts, and CHANGELOG.md
|
|
19
|
+
already agree on the same version.
|
|
19
20
|
--help, -h Show this help.
|
|
20
21
|
|
|
21
22
|
Notes:
|
|
@@ -50,6 +51,14 @@ read_package_lock_package_version() {
|
|
|
50
51
|
node -e 'const fs = require("node:fs"); const data = JSON.parse(fs.readFileSync("package-lock.json", "utf8")); process.stdout.write(String(data.packages?.[""]?.version ?? ""));'
|
|
51
52
|
}
|
|
52
53
|
|
|
54
|
+
read_changelog_latest_version() {
|
|
55
|
+
# POSIX awk: avoid gawk's 3-argument match() so this still parses under mawk/BSD awk.
|
|
56
|
+
# Matches the themed-narrative heading style `## v<semver> - YYYY-MM-DD`. The leading `v` and
|
|
57
|
+
# the digit lookahead filter out any non-version headings (e.g. a hypothetical `## Unreleased`
|
|
58
|
+
# block above the latest release).
|
|
59
|
+
awk '/^##[[:space:]]+v[0-9]/ { sub(/^##[[:space:]]+v/, ""); sub(/[[:space:]].*$/, ""); print; exit }' CHANGELOG.md
|
|
60
|
+
}
|
|
61
|
+
|
|
53
62
|
write_package_version() {
|
|
54
63
|
local next_version="$1"
|
|
55
64
|
awk -v target="$next_version" '
|
|
@@ -105,7 +114,7 @@ validate_semver() {
|
|
|
105
114
|
}
|
|
106
115
|
|
|
107
116
|
check_version_lockstep() {
|
|
108
|
-
local pkg const_ lock lock_package
|
|
117
|
+
local pkg const_ lock lock_package changelog
|
|
109
118
|
pkg="$(read_package_version)" || die "failed to read package.json version"
|
|
110
119
|
const_="$(read_constants_version)" || die "failed to read src/constants.ts VERSION"
|
|
111
120
|
lock="$(read_package_lock_version)" || die "failed to read package-lock.json root version"
|
|
@@ -118,7 +127,14 @@ check_version_lockstep() {
|
|
|
118
127
|
printf 'version surfaces disagree: package.json=%s src/constants.ts=%s package-lock.json=%s package-lock.json packages[""]=%s\n' "$pkg" "$const_" "$lock" "$lock_package" >&2
|
|
119
128
|
exit 1
|
|
120
129
|
fi
|
|
121
|
-
|
|
130
|
+
[[ -f CHANGELOG.md ]] || die "CHANGELOG.md not found"
|
|
131
|
+
changelog="$(read_changelog_latest_version)" || die "failed to read CHANGELOG.md latest version"
|
|
132
|
+
[[ -n "$changelog" ]] || die "CHANGELOG.md has no '## [version]' heading"
|
|
133
|
+
if [[ "$pkg" != "$changelog" ]]; then
|
|
134
|
+
printf 'CHANGELOG.md latest version %s does not match package.json %s; run scripts/bump-version.sh %s or add a CHANGELOG.md entry for %s\n' "$changelog" "$pkg" "$changelog" "$pkg" >&2
|
|
135
|
+
exit 1
|
|
136
|
+
fi
|
|
137
|
+
printf 'package.json, package-lock.json, src/constants.ts, and CHANGELOG.md agree on %s\n' "$pkg"
|
|
122
138
|
}
|
|
123
139
|
|
|
124
140
|
main() {
|
|
@@ -33,7 +33,6 @@ FAILED=0
|
|
|
33
33
|
FAILURES=()
|
|
34
34
|
TMP_FILES=()
|
|
35
35
|
START_TIME=$(date +%s%N)
|
|
36
|
-
NPM_REGISTRY_URL="${NPM_REGISTRY_URL:-https://registry.npmjs.org/}"
|
|
37
36
|
NPM_AUDIT_LEVEL="${NPM_AUDIT_LEVEL:-moderate}"
|
|
38
37
|
|
|
39
38
|
usage() {
|
|
@@ -42,7 +41,7 @@ Usage:
|
|
|
42
41
|
scripts/preflight-checks.sh
|
|
43
42
|
|
|
44
43
|
Runs the local preflight gate:
|
|
45
|
-
-
|
|
44
|
+
- version surfaces (package.json, package-lock.json, src/constants.ts, CHANGELOG.md) agree
|
|
46
45
|
- npm dependency audit
|
|
47
46
|
- npm run check (TypeScript compile plus unit tests)
|
|
48
47
|
- gruff-ts full-project scan
|
|
@@ -50,7 +49,6 @@ Runs the local preflight gate:
|
|
|
50
49
|
|
|
51
50
|
Environment:
|
|
52
51
|
GRUFF_TS_FAIL_ON gruff-ts severity that fails static analysis (default: advisory)
|
|
53
|
-
NPM_REGISTRY_URL npm registry used for the published-version check
|
|
54
52
|
NPM_AUDIT_LEVEL npm audit threshold (default: moderate)
|
|
55
53
|
USAGE
|
|
56
54
|
}
|
|
@@ -182,52 +180,17 @@ make_temp_file() {
|
|
|
182
180
|
printf '%s\n' "$temp_file"
|
|
183
181
|
}
|
|
184
182
|
|
|
185
|
-
|
|
186
|
-
node -p "require('./package.json').name"
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
read_package_version() {
|
|
190
|
-
node -p "require('./package.json').version"
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
npm_version_check() {
|
|
194
|
-
local package_name
|
|
195
|
-
local version
|
|
183
|
+
version_consistency_check() {
|
|
196
184
|
local output
|
|
197
185
|
local status
|
|
198
186
|
|
|
199
|
-
package_name="$(read_package_name)" || return 1
|
|
200
|
-
version="$(read_package_version)" || return 1
|
|
201
|
-
[[ -n "$package_name" ]] || {
|
|
202
|
-
printf 'package.json has no name field\n'
|
|
203
|
-
return 1
|
|
204
|
-
}
|
|
205
|
-
[[ -n "$version" ]] || {
|
|
206
|
-
printf 'package.json has no version field\n'
|
|
207
|
-
return 1
|
|
208
|
-
}
|
|
209
|
-
|
|
210
187
|
output=$(bash scripts/bump-version.sh --check 2>&1)
|
|
211
188
|
status=$?
|
|
212
189
|
if ((status != 0)); then
|
|
213
190
|
printf '%s\n' "$output"
|
|
214
191
|
return "$status"
|
|
215
192
|
fi
|
|
216
|
-
|
|
217
|
-
output=$(npm view "${package_name}@${version}" version --registry="$NPM_REGISTRY_URL" 2>&1)
|
|
218
|
-
status=$?
|
|
219
|
-
if ((status == 0)); then
|
|
220
|
-
printf '%s@%s is already published on %s; run scripts/bump-version.sh <next-version>\n' "$package_name" "$version" "$NPM_REGISTRY_URL"
|
|
221
|
-
return 1
|
|
222
|
-
fi
|
|
223
|
-
|
|
224
|
-
if printf '%s\n' "$output" | grep -Eq '(^|[[:space:]])(E404|404)([[:space:]]|$)'; then
|
|
225
|
-
printf 'lockstep ok; %s@%s is not published on %s' "$package_name" "$version" "$NPM_REGISTRY_URL"
|
|
226
|
-
return 0
|
|
227
|
-
fi
|
|
228
|
-
|
|
229
|
-
printf '%s\n' "$output"
|
|
230
|
-
return "$status"
|
|
193
|
+
printf '%s' "$output"
|
|
231
194
|
}
|
|
232
195
|
|
|
233
196
|
npm_audit_check() {
|
|
@@ -411,7 +374,7 @@ main() {
|
|
|
411
374
|
return 127
|
|
412
375
|
fi
|
|
413
376
|
|
|
414
|
-
run_step "
|
|
377
|
+
run_step "Version consistency" version_consistency_check
|
|
415
378
|
|
|
416
379
|
run_step "Dependency audit" npm_audit_check
|
|
417
380
|
|
package/src/analyser.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Analyser pipeline: walks discovered sources, runs every rule pass (complexity, dead-code, design,
|
|
2
2
|
// documentation, maintainability, modernisation, naming, security, sensitive-data, size, test-quality),
|
|
3
|
-
// aggregates findings into the `gruff.analysis.
|
|
3
|
+
// aggregates findings into the `gruff.analysis.v2` schema, and exposes `analyse` to the CLI shell.
|
|
4
4
|
import { existsSync, readFileSync } from "node:fs";
|
|
5
5
|
import { cwd } from "node:process";
|
|
6
6
|
import { basename, join } from "node:path";
|
|
@@ -28,7 +28,7 @@ import { maskNonCode, maskTemplateLiteralBodies, parseDiagnostics } from "./sour
|
|
|
28
28
|
import type { AnalysisOptions, AnalysisReport, Config, Finding, RunDiagnostic } from "./types.ts";
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
|
-
* Analyse the configured paths and return the stable gruff.analysis.
|
|
31
|
+
* Analyse the configured paths and return the stable gruff.analysis.v2 report contract.
|
|
32
32
|
*
|
|
33
33
|
* @param options Normalised analysis options from the CLI or direct callers.
|
|
34
34
|
* @returns Versioned report with fingerprinted findings, diagnostics, paths, and score data.
|
|
@@ -64,7 +64,7 @@ function buildAnalysisReport(
|
|
|
64
64
|
): AnalysisReport {
|
|
65
65
|
const findings = baselineResult.findings;
|
|
66
66
|
return {
|
|
67
|
-
schemaVersion: "gruff.analysis.
|
|
67
|
+
schemaVersion: "gruff.analysis.v2",
|
|
68
68
|
tool: { name: "gruff-ts", version: VERSION },
|
|
69
69
|
run: {
|
|
70
70
|
projectRoot,
|
|
@@ -102,7 +102,7 @@ interface SourceScanResult {
|
|
|
102
102
|
|
|
103
103
|
/*
|
|
104
104
|
* Result of applying a baseline (suppression) or generating a new one. The optional `baseline`
|
|
105
|
-
* matches the `gruff.analysis.
|
|
105
|
+
* matches the `gruff.analysis.v2` schema's baseline metadata - present only when a baseline file
|
|
106
106
|
* was actually used or generated, so the report stays stable across baseline-disabled runs.
|
|
107
107
|
*/
|
|
108
108
|
interface BaselineApplication {
|