@blundergoat/gruff-ts 0.1.0 → 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.
Files changed (45) hide show
  1. package/CHANGELOG.md +35 -11
  2. package/CONTRIBUTING.md +3 -3
  3. package/README.md +141 -183
  4. package/docs/README.md +23 -0
  5. package/docs/ci-integration.md +63 -0
  6. package/docs/{CONFIGURATION.md → configuration.md} +41 -20
  7. package/docs/dashboard.md +36 -0
  8. package/docs/output-formats.md +65 -0
  9. package/docs/{RELEASING.md → releasing.md} +17 -14
  10. package/docs/{REPORTS_AND_CI.md → reports-and-ci.md} +5 -2
  11. package/docs/rules.md +177 -0
  12. package/package.json +2 -2
  13. package/scripts/bump-version.sh +83 -18
  14. package/scripts/dependency-install.sh +96 -0
  15. package/scripts/dependency-update.sh +177 -0
  16. package/scripts/preflight-checks.sh +38 -0
  17. package/src/analyser.ts +9 -24
  18. package/src/blocks.ts +66 -12
  19. package/src/class-rules.ts +5 -6
  20. package/src/cli-program.ts +216 -39
  21. package/src/cli.ts +4 -1
  22. package/src/comment-rules.ts +2 -0
  23. package/src/config-load-error.ts +18 -0
  24. package/src/config-preservation.ts +64 -0
  25. package/src/config.ts +155 -29
  26. package/src/constants.ts +10 -2
  27. package/src/dashboard.ts +1 -1
  28. package/src/dead-code-rules.ts +62 -16
  29. package/src/doc-rules.ts +3 -3
  30. package/src/findings-helpers.ts +17 -0
  31. package/src/init-config.ts +308 -0
  32. package/src/line-rules.ts +64 -12
  33. package/src/naming-pushers.ts +7 -32
  34. package/src/pillar-summary.ts +129 -0
  35. package/src/project-config-rules.ts +1 -1
  36. package/src/report-html.ts +404 -0
  37. package/src/report-renderers.ts +210 -406
  38. package/src/rule-list.ts +65 -1
  39. package/src/rules.ts +36 -37
  40. package/src/safety-rules.ts +9 -4
  41. package/src/scoring.ts +41 -9
  42. package/src/test-block-rules.ts +43 -1
  43. package/src/test-fixtures.ts +13 -7
  44. package/src/text-scans.ts +1 -152
  45. package/src/types.ts +32 -6
@@ -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/**"
@@ -41,7 +79,6 @@ allowlists:
41
79
  booleanPrefixes: [is, has, can, should, does, did, was, will, may, in, scan, supports, requires]
42
80
  hungarianPrefixes: [str, obj, arr, bool, int, num]
43
81
  placeholderNames: [foo, bar, baz, tmp, temp, thing, stuff, data, value, item]
44
- abbreviationDenylist: [ctx, pkg, opts, fn, idx, cb]
45
82
  negativeBooleanAllowed: [nostore, nofollow, noreferrer, noscript, noindex]
46
83
  knownAcronyms: [url, http, https, id, xml, json, html, css, api, sql, db, io, ui, uuid, ip, tcp, udp, ast, cli, npm]
47
84
 
@@ -106,7 +143,7 @@ allowlists:
106
143
  Prefer fixing false positives with a narrow config entry instead of disabling an
107
144
  entire sensitive-data rule.
108
145
 
109
- Naming allowlists tune the 0.1.0 naming pack without changing rule ids or
146
+ Naming allowlists tune the 0.2.0 naming pack without changing rule ids or
110
147
  fingerprints:
111
148
 
112
149
  | Key | Used by | Default behavior |
@@ -116,7 +153,6 @@ fingerprints:
116
153
  | `booleanPrefixes` | `naming.boolean-prefix` | Replaces the accepted boolean-name prefixes such as `is`, `has`, `should`, `may`, `supports`, and `requires`. |
117
154
  | `hungarianPrefixes` | `naming.hungarian-notation` | Replaces type-style prefixes to flag. |
118
155
  | `placeholderNames` | `naming.identifier-quality`, `naming.generic-parameter` | Replaces placeholder words; numbered suffix checks stay active. |
119
- | `abbreviationDenylist` | `naming.abbreviation` | Replaces the opt-in abbreviation denylist. |
120
156
  | `negativeBooleanAllowed` | `naming.negative-boolean` | Replaces domain terms allowed to start with `no`. |
121
157
  | `knownAcronyms` | `naming.acronym-case` | Replaces acronyms checked for mixed casing. |
122
158
 
@@ -165,6 +201,8 @@ gruff-ts list-rules
165
201
  gruff-ts list-rules --format=json
166
202
  ```
167
203
 
204
+ See [Rules](./rules.md) for the full rule catalogue grouped by pillar.
205
+
168
206
  ## Example Project Config
169
207
 
170
208
  ```yaml
@@ -201,20 +239,3 @@ rules:
201
239
  threshold: 12
202
240
  severity: advisory
203
241
  ```
204
-
205
- ## Adoption Defaults
206
-
207
- Two noisy-by-nature rules are present in the public catalogue but disabled by
208
- default in this repo config:
209
-
210
- ```yaml
211
- rules:
212
- docs.todo-density:
213
- enabled: false
214
- naming.abbreviation:
215
- enabled: false
216
- ```
217
-
218
- `docs.todo-without-tracking` remains enabled because it checks whether a TODO
219
- has owner, issue, date, ADR, or task context instead of counting raw TODO
220
- markers.
@@ -0,0 +1,36 @@
1
+ # Dashboard
2
+
3
+ `gruff-ts dashboard` serves a local browser dashboard for repeated analysis.
4
+
5
+ ## Start
6
+
7
+ ```sh
8
+ ./bin/gruff-ts dashboard --host 127.0.0.1 --port 8767 --project-root .
9
+ ```
10
+
11
+ ## Options
12
+
13
+ | Option | Default | Purpose |
14
+ | --- | --- | --- |
15
+ | `--host` | `127.0.0.1` | Bind host. |
16
+ | `--port` | `8767` | Bind port. |
17
+ | `--project-root` | current directory | Initial project root. |
18
+
19
+ ## Safety
20
+
21
+ The dashboard has no authentication and should stay bound to loopback unless the
22
+ network is trusted. The `/scan` endpoint analyses filesystem paths from request
23
+ parameters, so the bind address is the safety boundary.
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
+
32
+ ## Polyglot Repos
33
+
34
+ `gruff-ts` defaults to port `8767`, `gruff-rs` defaults to `8766`, and Go, PHP,
35
+ and Python default to `8765`. Use `--port` when running multiple dashboards at
36
+ once.
@@ -0,0 +1,65 @@
1
+ # Output Formats
2
+
3
+ `gruff-ts analyse --format <format>` renders the same analysis data for
4
+ different consumers. The combined legacy page remains at
5
+ [Reports And CI](reports-and-ci.md).
6
+
7
+ ## Text
8
+
9
+ Use `text` for local terminal scans:
10
+
11
+ ```sh
12
+ ./bin/gruff-ts analyse src --format text --fail-on=warning
13
+ ```
14
+
15
+ ## JSON
16
+
17
+ Use `json` for automation. JSON reports use `gruff.analysis.v2`.
18
+
19
+ ```sh
20
+ ./bin/gruff-ts analyse src --format=json --fail-on=none > gruff-ts.json
21
+ ```
22
+
23
+ ## HTML
24
+
25
+ Use `html` for archived human review or dashboard scan output:
26
+
27
+ ```sh
28
+ ./bin/gruff-ts report src --format=html --output gruff-ts.html
29
+ ```
30
+
31
+ ## Markdown
32
+
33
+ Use `markdown` for pull request comments and release notes.
34
+
35
+ ## GitHub
36
+
37
+ Use `github` inside GitHub Actions to emit workflow annotations.
38
+
39
+ ## Hotspot
40
+
41
+ Use `hotspot` for compact score and offender analysis.
42
+
43
+ ## SARIF
44
+
45
+ Use `sarif` for GitHub code scanning or other SARIF consumers:
46
+
47
+ ```sh
48
+ ./bin/gruff-ts analyse src --format=sarif --fail-on=none > gruff-ts.sarif
49
+ ```
50
+
51
+ ## Summary
52
+
53
+ `summary` has its own compact text/JSON contract:
54
+
55
+ ```sh
56
+ ./bin/gruff-ts summary src --format=json --top=5 --fail-on=none
57
+ ```
58
+
59
+ TypeScript keeps the existing `summary` analysis flags such as `--diff`,
60
+ `--baseline`, and `--generate-baseline` as extensions.
61
+
62
+ ## Exit Codes
63
+
64
+ `analyse` exits `1` when at least one finding meets `--fail-on`. Use
65
+ `--fail-on none` for report-only jobs.
@@ -1,19 +1,20 @@
1
1
  # Releasing
2
2
 
3
- This checklist prepares the public `@blundergoat/gruff-ts@0.1.0` release and
4
- subsequent `0.1.x` patch releases.
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
- `scripts/bump-version.sh <semver>` updates `package.json` and
9
- `src/constants.ts` together so the CLI `--version` output and the published
10
- `@blundergoat/gruff-ts` package version cannot drift apart. For the initial
11
- `0.1.0` release, the version should already be `0.1.0`; use `--check` instead
12
- of bumping unless the release version changes.
8
+ `scripts/bump-version.sh <semver>` updates `package.json`,
9
+ `package-lock.json`, and `src/constants.ts` together so the CLI `--version`
10
+ output and the published `@blundergoat/gruff-ts` package version cannot drift
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.1
17
+ scripts/bump-version.sh 0.1.3
17
18
  scripts/bump-version.sh --check
18
19
  ```
19
20
 
@@ -30,9 +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 (runs `npm run check`, a full
34
- `gruff-ts` self-scan, and `shellcheck` on `scripts/*.sh` when
35
- `shellcheck` is installed).
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).
36
38
  - [ ] `npm pack --dry-run` shows only publishable runtime, docs, scripts, and
37
39
  metadata files.
38
40
  - [ ] Local smoke scan succeeds:
@@ -58,8 +60,9 @@ The package should include:
58
60
  - `bin/gruff-ts`
59
61
  - `src/` (all runtime `.ts` files; `src/**/*.test.ts` files are excluded by
60
62
  `.npmignore`)
61
- - `scripts/` (`bump-version.sh`, `check.sh`, `preflight-checks.sh`,
62
- `npm-publish.sh`, `start-dev.sh`, `test-performance.sh`)
63
+ - `scripts/` (`bump-version.sh`, `check.sh`, `dependency-install.sh`,
64
+ `dependency-update.sh`, `preflight-checks.sh`, `npm-publish.sh`,
65
+ `start-dev.sh`, `test-performance.sh`)
63
66
  - `fixtures/sample.ts`
64
67
  - `README.md`
65
68
  - `CHANGELOG.md`
@@ -99,5 +102,5 @@ prompts before publishing.
99
102
  - [ ] Run `gruff-ts summary . --fail-on=none`.
100
103
  - [ ] Run `gruff-ts list-rules`.
101
104
  - [ ] Verify `README.md` install instructions from a clean checkout.
102
- - [ ] Tag the release in git (`git tag v0.1.0 && git push --tags`) and create
105
+ - [ ] Tag the release in git (`git tag v0.2.0 && git push --tags`) and create
103
106
  or update public release notes from `CHANGELOG.md`.
@@ -45,7 +45,7 @@ per-pillar counts, top rules, and top file offenders.
45
45
 
46
46
  Schema strings:
47
47
 
48
- - `gruff.analysis.v1` for full analysis reports.
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/docs/rules.md ADDED
@@ -0,0 +1,177 @@
1
+ # Rules
2
+
3
+ `gruff-ts` exposes 119 rules across 11 pillars. This list is generated from the
4
+ public rule catalogue used by `gruff-ts list-rules`; severity, confidence,
5
+ thresholds, and option names are the defaults before project config overrides.
6
+
7
+ Use the CLI when you need machine-readable metadata:
8
+
9
+ ```bash
10
+ gruff-ts list-rules --format=json
11
+ ```
12
+
13
+ ## Pillar Counts
14
+
15
+ - complexity: 3
16
+ - dead-code: 1
17
+ - design: 6
18
+ - documentation: 17
19
+ - maintainability: 14
20
+ - modernisation: 14
21
+ - naming: 10
22
+ - security: 27
23
+ - sensitive-data: 8
24
+ - size: 4
25
+ - test-quality: 15
26
+
27
+ ## Complexity
28
+
29
+ - `complexity.cognitive` (warning; high confidence; threshold 15): Flags functions with high combined branch and nesting complexity.
30
+ - `complexity.cyclomatic` (warning; high confidence; threshold 15): Flags functions with many independent branch paths.
31
+ - `complexity.npath` (warning; medium confidence; threshold 200): Flags functions with high approximate NPath complexity.
32
+
33
+ ## Dead Code
34
+
35
+ - `dead-code.unused-private-method` (advisory; low confidence): Flags private methods without an apparent same-file call site.
36
+
37
+ ## Design
38
+
39
+ - `design.circular-import` (warning; medium confidence): Flags simple relative import cycles inside the discovered source set.
40
+ - `design.deep-relative-import` (advisory; medium confidence; threshold 2): Flags relative imports that climb too many parent directories.
41
+ - `design.god-function` (warning; high confidence): Flags functions that are both long and complex.
42
+ - `design.large-module-concentration` (advisory; medium confidence; threshold 55; options: minFiles, minLines): Flags a production module that dominates project source lines.
43
+ - `design.package-bin-missing` (warning; high confidence): Flags package bin entries that point at missing files.
44
+ - `design.package-bin-not-executable` (warning; high confidence): Flags package bin targets that are not executable.
45
+
46
+ ## Documentation
47
+
48
+ - `docs.fixture-purpose-missing` (advisory; medium confidence): Flags large or scanner-relevant fixtures without a nearby purpose comment.
49
+ - `docs.magic-threshold-without-rationale` (advisory; medium confidence): Flags threshold-like numeric values without a nearby rationale comment.
50
+ - `docs.missing-error-behavior-doc` (advisory; medium confidence): Flags commented functions whose error behavior is not described.
51
+ - `docs.missing-file-overview` (advisory; medium confidence): Flags source files without a top-of-file purpose comment.
52
+ - `docs.missing-function-doc` (advisory; medium confidence): Flags functions without a leading maintainer comment.
53
+ - `docs.missing-interface-doc` (advisory; medium confidence): Flags interfaces without a leading maintainer comment.
54
+ - `docs.missing-invariant-doc` (advisory; medium confidence): Flags commented declarations that own schema, fingerprint, baseline, or determinism contracts without saying so.
55
+ - `docs.missing-param-tag` (advisory; medium confidence): Flags documented exports with parameters missing @param tags.
56
+ - `docs.missing-public-doc` (advisory; medium confidence): Flags exported class, type, and enum APIs without a nearby doc comment.
57
+ - `docs.missing-return-tag` (advisory; medium confidence): Flags documented non-void exports without @returns.
58
+ - `docs.missing-side-effect-doc` (advisory; medium confidence): Flags commented functions that perform observable side effects without naming them.
59
+ - `docs.missing-why-for-complex-code` (advisory; medium confidence): Flags comments on complex functions that do not explain why the shape exists.
60
+ - `docs.stale-comment` (advisory; medium confidence): Flags comments that reference missing files, unknown rules, stale CLI flags, or the wrong declaration.
61
+ - `docs.stale-param-tag` (advisory; medium confidence): Flags @param tags for parameters no longer in the signature.
62
+ - `docs.suppression-without-rationale` (advisory; medium confidence): Flags lint, formatter, coverage, or tool suppressions without a maintainer rationale.
63
+ - `docs.todo-without-tracking` (advisory; high confidence): Flags TODO, FIXME, HACK, and XXX comments without tracking context.
64
+ - `docs.useless-docblock` (advisory; medium confidence): Flags comments or docblocks that only restate the symbol name.
65
+
66
+ ## Modernisation
67
+
68
+ - `modernisation.date-now-candidate` (advisory; high confidence): Flags verbose current-time expressions that can use Date.now().
69
+ - `modernisation.double-cast` (warning; medium confidence): Flags casts through unknown or any into another type.
70
+ - `modernisation.loose-equality` (advisory; medium confidence): Flags loose equality comparisons that may coerce values.
71
+ - `modernisation.non-null-assertion` (warning; medium confidence): Flags non-null assertions that bypass null checks.
72
+ - `modernisation.nullish-coalescing-candidate` (advisory; medium confidence): Flags || fallbacks that may erase valid falsy values.
73
+ - `modernisation.object-spread-candidate` (advisory; medium confidence): Flags Object.assign({}, ...) cloning that can use object spread.
74
+ - `modernisation.optional-chaining-candidate` (advisory; medium confidence): Flags repeated guard-and-property access patterns.
75
+ - `modernisation.public-property` (advisory; high confidence): Flags public class properties that expose representation.
76
+ - `modernisation.readonly-property-candidate` (advisory; medium confidence): Flags class properties that appear readonly-worthy.
77
+ - `modernisation.ts-comment-without-rationale` (warning; medium confidence): Flags TypeScript suppression comments without a rationale.
78
+ - `modernisation.tsconfig-exact-optional-disabled` (warning; high confidence): Flags tsconfig files without exactOptionalPropertyTypes enabled.
79
+ - `modernisation.tsconfig-index-safety-disabled` (warning; high confidence): Flags tsconfig files without noUncheckedIndexedAccess enabled.
80
+ - `modernisation.tsconfig-strict-disabled` (warning; high confidence): Flags tsconfig files without strict mode enabled.
81
+ - `modernisation.var-declaration` (advisory; high confidence): Flags var declarations.
82
+
83
+ ## Naming
84
+
85
+ - `naming.acronym-case` (advisory; medium confidence): Flags mixed casings of a known acronym in one file.
86
+ - `naming.boolean-prefix` (advisory; medium confidence): Flags boolean names without intent-revealing prefixes on declarations, function parameters (typed `: boolean` or with `= true|false` default), and interface/type-literal fields.
87
+ - `naming.class-file-mismatch` (advisory; medium confidence): Flags exported classes whose name differs from the file name.
88
+ - `naming.generic-function` (advisory; high confidence): Flags generic function names that hide intent.
89
+ - `naming.generic-parameter` (advisory; medium confidence; options: minCyclomatic, minLineCount, minParameters): Flags placeholder parameter names in multi-parameter, long, exported, or complex functions.
90
+ - `naming.hungarian-notation` (advisory; medium confidence): Flags identifiers named after storage type prefixes.
91
+ - `naming.identifier-quality` (advisory; medium confidence): Flags placeholder or numbered identifiers on declarations, function parameters, and destructured locals.
92
+ - `naming.inconsistent-casing` (advisory; medium confidence): Flags the same canonical identifier appearing in two different surface forms (for example CONSTANT_CASE and camelCase) in one file.
93
+ - `naming.negative-boolean` (advisory; medium confidence): Flags boolean identifiers framed as a negation on declarations, parameters, and interface fields.
94
+ - `naming.short-variable` (advisory; medium confidence): Flags very short variable names outside common loop counters; covers declarations, function parameters, and destructured locals.
95
+
96
+ ## Security
97
+
98
+ - `security.async-foreach` (warning; medium confidence): Flags async callbacks passed to forEach.
99
+ - `security.disabled-tls-verification` (error; high confidence): Flags code that disables TLS certificate verification.
100
+ - `security.document-write` (warning; high confidence): Flags document.write usage.
101
+ - `security.dynamic-regexp` (warning; medium confidence): Flags external input used to construct regular expressions.
102
+ - `security.eval-call` (error; high confidence): Flags eval() dynamic code execution.
103
+ - `security.floating-promise` (warning; medium confidence): Flags promise-like calls without await, return, or void.
104
+ - `security.github-actions-broad-permissions` (warning; medium confidence): Flags GitHub Actions workflows that grant broad write permissions.
105
+ - `security.github-actions-pull-request-target` (warning; medium confidence): Flags pull_request_target workflows paired with risky execution or trust context.
106
+ - `security.github-actions-remote-shell` (warning; medium confidence): Flags workflow run steps that pipe remote downloads to a shell.
107
+ - `security.github-actions-secrets-in-pr` (warning; medium confidence): Flags pull request workflows that reference GitHub secrets.
108
+ - `security.github-actions-unpinned-action` (warning; medium confidence): Flags third-party GitHub Actions that are not pinned to a full commit SHA.
109
+ - `security.inner-html` (warning; high confidence): Flags innerHTML assignment.
110
+ - `security.insecure-random` (warning; high confidence): Flags Math.random usage in source.
111
+ - `security.javascript-url` (error; high confidence): Flags javascript: URL literals that execute script.
112
+ - `security.new-function` (error; high confidence): Flags Function constructor dynamic code execution.
113
+ - `security.open-redirect-candidate` (warning; medium confidence): Flags external input sent to redirect or navigation sinks.
114
+ - `security.path-traversal-candidate` (warning; medium confidence): Flags external input sent to filesystem path sinks.
115
+ - `security.process-exec` (warning; high confidence): Flags child-process execution calls.
116
+ - `security.proto-access` (warning; medium confidence): Flags direct __proto__ access that can enable prototype pollution.
117
+ - `security.remote-install-script` (error; medium confidence): Flags package scripts that pipe remote content to a shell.
118
+ - `security.risky-lifecycle-script` (warning; medium confidence): Flags package lifecycle scripts that run automatically.
119
+ - `security.sql-concatenation` (warning; high confidence): Flags SQL text composed with runtime string interpolation.
120
+ - `security.ssrf-candidate` (warning; medium confidence): Flags external input sent to network request sinks.
121
+ - `security.string-timer` (warning; high confidence): Flags string callbacks passed to timers.
122
+ - `security.throw-non-error` (warning; medium confidence): Flags thrown non-Error values.
123
+ - `security.url-dependency` (warning; medium confidence): Flags dependencies installed from URL or git specs.
124
+ - `security.weak-crypto` (warning; high confidence): Flags weak crypto primitives such as md5, sha1, or createCipher.
125
+
126
+ ## Sensitive Data
127
+
128
+ - `sensitive-data.api-key-pattern` (error; high confidence): Flags vendor API key patterns.
129
+ - `sensitive-data.aws-access-key` (error; high confidence): Flags AWS access key looking values.
130
+ - `sensitive-data.database-url-password` (error; high confidence): Flags database URLs that include passwords.
131
+ - `sensitive-data.hardcoded-env-value` (error; medium confidence; threshold 16): Flags environment-style secret values committed in text.
132
+ - `sensitive-data.high-entropy-string` (error; medium confidence; threshold 32): Flags high-entropy string literals that may be secrets.
133
+ - `sensitive-data.jwt-token` (error; high confidence): Flags JWT-looking token literals.
134
+ - `sensitive-data.pii-pattern` (error; high confidence): Flags PII-like identifier patterns.
135
+ - `sensitive-data.private-key` (error; high confidence): Flags private key block markers.
136
+
137
+ ## Size
138
+
139
+ - `size.file-length` (warning; high confidence; threshold 750): Flags files longer than the configured threshold.
140
+ - `size.function-length` (warning; high confidence; threshold 200): Flags functions longer than the configured threshold.
141
+ - `size.parameter-count` (warning; high confidence; threshold 7): Flags functions with too many parameters.
142
+ - `size.stylesheet-length` (warning; high confidence; threshold 1500): Flags stylesheets longer than the configured threshold.
143
+
144
+ ## Test Quality
145
+
146
+ - `test-quality.conditional-logic` (advisory; high confidence): Flags tests with conditional logic.
147
+ - `test-quality.exception-type-only` (advisory; high confidence): Flags tests that only assert exception type.
148
+ - `test-quality.global-state-mutation` (warning; high confidence): Flags tests mutating process or global runtime state.
149
+ - `test-quality.loop-in-test` (advisory; high confidence): Flags loops inside test bodies.
150
+ - `test-quality.magic-number-assertion` (advisory; medium confidence): Flags assertions against unexplained numeric literals.
151
+ - `test-quality.missing-nearby-test` (advisory; medium confidence): Flags exported production files without nearby tests.
152
+ - `test-quality.mock-only-test` (advisory; high confidence): Flags tests that only verify mock interaction.
153
+ - `test-quality.no-assertions` (warning; high confidence): Flags tests without apparent assertions.
154
+ - `test-quality.no-throw-only-test` (advisory; high confidence): Flags tests that only assert code does not throw.
155
+ - `test-quality.only-skip` (advisory; high confidence): Flags focused or skipped test markers.
156
+ - `test-quality.setup-bloat` (advisory; medium confidence; threshold 12): Flags tests with too much setup before the first assertion.
157
+ - `test-quality.sleep-in-test` (advisory; high confidence): Flags sleeps in tests.
158
+ - `test-quality.snapshot-only-test` (advisory; high confidence): Flags tests that rely only on snapshots.
159
+ - `test-quality.trivial-assertion` (warning; high confidence): Flags tautological assertions.
160
+ - `test-quality.unused-mock` (advisory; medium confidence): Flags mocks created but not used.
161
+
162
+ ## Maintainability
163
+
164
+ - `waste.any-type` (warning; high confidence): Flags any type usage.
165
+ - `waste.broad-runtime-version` (advisory; medium confidence): Flags broad runtime dependency version ranges.
166
+ - `waste.commented-out-code` (advisory; high confidence): Flags comments that appear to contain disabled code.
167
+ - `waste.console-log` (advisory; high confidence): Flags console log/debug calls in source.
168
+ - `waste.empty-function` (advisory; high confidence): Flags functions with no executable body.
169
+ - `waste.exported-any` (warning; medium confidence): Flags exported APIs exposing any.
170
+ - `waste.redundant-boolean-cast` (advisory; medium confidence): Flags redundant boolean casts in condition expressions.
171
+ - `waste.redundant-variable` (advisory; medium confidence): Flags variables returned immediately after assignment.
172
+ - `waste.swallowed-catch` (warning; medium confidence): Flags empty catch blocks.
173
+ - `waste.unreachable-code` (warning; high confidence): Flags statements after terminating statements.
174
+ - `waste.unused-import` (advisory; medium confidence): Flags named imports with no apparent usage.
175
+ - `waste.unused-parameter` (advisory; medium confidence): Flags parameters with no apparent usage.
176
+ - `waste.useless-catch` (advisory; high confidence): Flags catch blocks that only rethrow the caught value.
177
+ - `waste.useless-return` (advisory; medium confidence): Flags terminal bare return statements in void functions.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@blundergoat/gruff-ts",
3
- "version": "0.1.0",
4
- "description": "Static analyzer for TypeScript and JavaScript projects - 121 rules across 11 quality pillars, SARIF output, baselines, and a local dashboard.",
3
+ "version": "0.2.0",
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)",
7
7
  "homepage": "https://github.com/blundergoat/gruff-ts#readme",
@@ -1,9 +1,9 @@
1
1
  #!/usr/bin/env bash
2
2
  set -euo pipefail
3
3
 
4
- # Bump gruff-ts to a new semver in package.json and src/constants.ts in one step.
5
- # The CLI surfaces VERSION from src/constants.ts; package.json drives `npm publish`.
6
- # Keeping them in lockstep is a release invariant.
4
+ # Bump gruff-ts to a new semver in package.json, package-lock.json, and src/constants.ts.
5
+ # The CLI surfaces VERSION from src/constants.ts; package metadata drives `npm publish`.
6
+ # Keeping all release version surfaces in lockstep is a release invariant.
7
7
 
8
8
  usage() {
9
9
  cat <<'USAGE'
@@ -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 and src/constants.ts already agree.
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:
@@ -42,6 +43,22 @@ read_constants_version() {
42
43
  awk -F'"' '/^const VERSION = "/ { print $2; exit }' src/constants.ts
43
44
  }
44
45
 
46
+ read_package_lock_version() {
47
+ node -e 'const fs = require("node:fs"); const data = JSON.parse(fs.readFileSync("package-lock.json", "utf8")); process.stdout.write(String(data.version ?? ""));'
48
+ }
49
+
50
+ read_package_lock_package_version() {
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 ?? ""));'
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
+
45
62
  write_package_version() {
46
63
  local next_version="$1"
47
64
  awk -v target="$next_version" '
@@ -69,13 +86,57 @@ write_constants_version() {
69
86
  mv src/constants.ts.tmp src/constants.ts
70
87
  }
71
88
 
89
+ write_package_lock_version() {
90
+ local next_version="$1"
91
+ node - "$next_version" <<'NODE'
92
+ const fs = require("node:fs");
93
+
94
+ const target = process.argv[2];
95
+ const lockPath = "package-lock.json";
96
+ const lock = JSON.parse(fs.readFileSync(lockPath, "utf8"));
97
+
98
+ lock.version = target;
99
+ if (!lock.packages || typeof lock.packages !== "object" || !lock.packages[""]) {
100
+ throw new Error('package-lock.json missing packages[""] root package entry');
101
+ }
102
+ lock.packages[""].version = target;
103
+
104
+ fs.writeFileSync(`${lockPath}.tmp`, `${JSON.stringify(lock, null, 2)}\n`);
105
+ NODE
106
+ mv package-lock.json.tmp package-lock.json
107
+ }
108
+
72
109
  validate_semver() {
73
110
  local value="$1"
74
111
  # Standard semver: MAJOR.MINOR.PATCH with optional prerelease/build metadata.
75
- local pattern='^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-[0-9A-Za-z.-]+)?(\+[0-9A-Za-z.-]+)?$'
112
+ local pattern='^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-((0|[1-9][0-9]*|[0-9A-Za-z-]*[A-Za-z-][0-9A-Za-z-]*)(\.(0|[1-9][0-9]*|[0-9A-Za-z-]*[A-Za-z-][0-9A-Za-z-]*))*))?(\+([0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*))?$'
76
113
  [[ "$value" =~ $pattern ]] || die "not a valid semver: $value"
77
114
  }
78
115
 
116
+ check_version_lockstep() {
117
+ local pkg const_ lock lock_package changelog
118
+ pkg="$(read_package_version)" || die "failed to read package.json version"
119
+ const_="$(read_constants_version)" || die "failed to read src/constants.ts VERSION"
120
+ lock="$(read_package_lock_version)" || die "failed to read package-lock.json root version"
121
+ lock_package="$(read_package_lock_package_version)" || die "failed to read package-lock.json package version"
122
+ [[ -n "$pkg" ]] || die "package.json has no \"version\" field"
123
+ [[ -n "$const_" ]] || die "src/constants.ts has no VERSION constant"
124
+ [[ -n "$lock" ]] || die "package-lock.json has no root \"version\" field"
125
+ [[ -n "$lock_package" ]] || die 'package-lock.json has no packages[""].version field'
126
+ if ! [[ "$pkg" == "$const_" && "$pkg" == "$lock" && "$pkg" == "$lock_package" ]]; then
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
128
+ exit 1
129
+ fi
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"
138
+ }
139
+
79
140
  main() {
80
141
  if [[ "$#" -eq 0 ]]; then
81
142
  usage >&2
@@ -84,6 +145,7 @@ main() {
84
145
 
85
146
  cd "$(repo_root)"
86
147
  [[ -f package.json ]] || die "package.json not found"
148
+ [[ -f package-lock.json ]] || die "package-lock.json not found"
87
149
  [[ -f src/constants.ts ]] || die "src/constants.ts not found"
88
150
 
89
151
  case "$1" in
@@ -92,16 +154,7 @@ main() {
92
154
  exit 0
93
155
  ;;
94
156
  --check)
95
- local pkg const_
96
- pkg="$(read_package_version)" || die "failed to read package.json version"
97
- const_="$(read_constants_version)" || die "failed to read src/constants.ts VERSION"
98
- [[ -n "$pkg" ]] || die "package.json has no \"version\" field"
99
- [[ -n "$const_" ]] || die "src/constants.ts has no VERSION constant"
100
- if [[ "$pkg" != "$const_" ]]; then
101
- printf 'package.json (%s) and src/constants.ts (%s) disagree\n' "$pkg" "$const_" >&2
102
- exit 1
103
- fi
104
- printf 'package.json and src/constants.ts agree on %s\n' "$pkg"
157
+ check_version_lockstep
105
158
  exit 0
106
159
  ;;
107
160
  esac
@@ -117,8 +170,14 @@ main() {
117
170
  current_const="$(read_constants_version)" || die "failed to read src/constants.ts VERSION"
118
171
  [[ -n "$current_const" ]] || die "src/constants.ts has no VERSION constant"
119
172
 
120
- if [[ "$current" != "$current_const" ]]; then
121
- die "current versions diverge: package.json=$current src/constants.ts=$current_const (resolve manually first)"
173
+ local current_lock current_lock_package
174
+ current_lock="$(read_package_lock_version)" || die "failed to read package-lock.json root version"
175
+ current_lock_package="$(read_package_lock_package_version)" || die "failed to read package-lock.json package version"
176
+ [[ -n "$current_lock" ]] || die "package-lock.json has no root \"version\" field"
177
+ [[ -n "$current_lock_package" ]] || die 'package-lock.json has no packages[""].version field'
178
+
179
+ if ! [[ "$current" == "$current_const" && "$current" == "$current_lock" && "$current" == "$current_lock_package" ]]; then
180
+ die "current versions diverge: package.json=$current src/constants.ts=$current_const package-lock.json=$current_lock package-lock.json packages[\"\"]=$current_lock_package (resolve manually first)"
122
181
  fi
123
182
 
124
183
  if [[ "$current" == "$next" ]]; then
@@ -128,15 +187,21 @@ main() {
128
187
 
129
188
  write_package_version "$next"
130
189
  write_constants_version "$next"
190
+ write_package_lock_version "$next"
131
191
 
132
- local check_pkg check_const
192
+ local check_pkg check_const check_lock check_lock_package
133
193
  check_pkg="$(read_package_version)"
134
194
  check_const="$(read_constants_version)"
195
+ check_lock="$(read_package_lock_version)"
196
+ check_lock_package="$(read_package_lock_package_version)"
135
197
  [[ "$check_pkg" == "$next" ]] || die "package.json did not update cleanly (read back: ${check_pkg:-empty})"
136
198
  [[ "$check_const" == "$next" ]] || die "src/constants.ts did not update cleanly (read back: ${check_const:-empty})"
199
+ [[ "$check_lock" == "$next" ]] || die "package-lock.json did not update cleanly (read back: ${check_lock:-empty})"
200
+ [[ "$check_lock_package" == "$next" ]] || die "package-lock.json packages[\"\"] did not update cleanly (read back: ${check_lock_package:-empty})"
137
201
 
138
202
  printf 'bumped %s -> %s\n' "$current" "$next"
139
203
  printf ' package.json\n'
204
+ printf ' package-lock.json\n'
140
205
  printf ' src/constants.ts\n'
141
206
  # shellcheck disable=SC2016
142
207
  printf 'next: update CHANGELOG.md and run `npm run check`\n'