@blundergoat/gruff-ts 0.1.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 (54) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/CONTRIBUTING.md +87 -0
  3. package/LICENSE +21 -0
  4. package/README.md +303 -0
  5. package/SECURITY.md +45 -0
  6. package/bin/gruff-ts +25 -0
  7. package/docs/CONFIGURATION.md +220 -0
  8. package/docs/RELEASING.md +103 -0
  9. package/docs/REPORTS_AND_CI.md +156 -0
  10. package/fixtures/sample.ts +21 -0
  11. package/package.json +56 -0
  12. package/scripts/bump-version.sh +145 -0
  13. package/scripts/check.sh +4 -0
  14. package/scripts/npm-publish.sh +258 -0
  15. package/scripts/preflight-checks.sh +357 -0
  16. package/scripts/start-dev.sh +8 -0
  17. package/scripts/test-performance.sh +695 -0
  18. package/src/analyser.ts +461 -0
  19. package/src/baseline.ts +90 -0
  20. package/src/blocks.ts +687 -0
  21. package/src/class-rules.ts +326 -0
  22. package/src/cli-program.ts +326 -0
  23. package/src/cli.ts +19 -0
  24. package/src/comment-rules.ts +605 -0
  25. package/src/comment-scanner.ts +357 -0
  26. package/src/config.ts +622 -0
  27. package/src/constants.ts +4 -0
  28. package/src/context-doc-rules.ts +241 -0
  29. package/src/dashboard.ts +114 -0
  30. package/src/dead-code-rules.ts +183 -0
  31. package/src/discovery.ts +508 -0
  32. package/src/doc-rules.ts +368 -0
  33. package/src/findings-helpers.ts +108 -0
  34. package/src/findings.ts +45 -0
  35. package/src/fixture-purpose-rules.ts +334 -0
  36. package/src/fixtures/rule-catalogue-security-doctrine.ts +132 -0
  37. package/src/github-actions-rules.ts +413 -0
  38. package/src/line-rules.ts +538 -0
  39. package/src/naming-pushers.ts +191 -0
  40. package/src/project-config-rules.ts +555 -0
  41. package/src/project-rules.ts +545 -0
  42. package/src/report-renderers.ts +691 -0
  43. package/src/rule-list.ts +179 -0
  44. package/src/rules.ts +135 -0
  45. package/src/safety-rules.ts +355 -0
  46. package/src/scoring.ts +74 -0
  47. package/src/security-flow-rules.ts +112 -0
  48. package/src/sensitive-data-rules.ts +288 -0
  49. package/src/source-text.ts +722 -0
  50. package/src/test-block-rules.ts +347 -0
  51. package/src/test-fixtures.ts +621 -0
  52. package/src/text-scans.ts +193 -0
  53. package/src/types.ts +113 -0
  54. package/tsconfig.json +15 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,16 @@
1
+ # Changelog
2
+
3
+ ## [0.1.0] - 2026-05-23
4
+
5
+ Initial public release of the `@blundergoat/gruff-ts` npm package.
6
+
7
+ - TypeScript/JavaScript code quality scanner: 121 rules across 11 pillars
8
+ (complexity, dead-code, design, documentation, modernisation, naming,
9
+ security, sensitive-data, size, test-quality, waste).
10
+ - CLI commands: `analyse`, `summary`, `report`, `list-rules`, `dashboard`,
11
+ `completion`.
12
+ - Output formats: `text`, `json`, `html`, `markdown`, `github`, `hotspot`,
13
+ `sarif`. Stable schemas: `gruff.analysis.v1`, `gruff.baseline.v1`,
14
+ `gruff.hotspot.v1`.
15
+ - Baselines via stable per-finding fingerprints, `--diff` for changed-file
16
+ scans, local dashboard on `127.0.0.1:8767`. Released under MIT.
@@ -0,0 +1,87 @@
1
+ # Contributing
2
+
3
+ Thanks for taking the time to improve `gruff-ts`.
4
+
5
+ ## Development Setup
6
+
7
+ ```bash
8
+ npm install
9
+ npm run check
10
+ ```
11
+
12
+ Useful local commands:
13
+
14
+ ```bash
15
+ npm test
16
+ ./bin/gruff-ts analyse . --fail-on=none
17
+ ./bin/gruff-ts list-rules
18
+ npm run start-dev
19
+ ```
20
+
21
+ CI runs the same core gate with `npm run check`, then runs
22
+ `./bin/gruff-ts analyse . --fail-on=advisory`.
23
+
24
+ ## Project Shape
25
+
26
+ The runtime lives under `src/`:
27
+
28
+ - `src/cli.ts` - thin bootstrap and public re-export shell.
29
+ - `src/cli-program.ts` - Commander program wiring and option normalization.
30
+ - `src/analyser.ts` - scan orchestration and per-file/project rule fanout.
31
+ - `src/discovery.ts` - source-file discovery and `.gitignore` handling.
32
+ - `src/rules.ts` - canonical rule descriptor catalogue.
33
+ - `src/blocks.ts`, `src/line-rules.ts`, `src/class-rules.ts`,
34
+ `src/dead-code-rules.ts`, `src/doc-rules.ts`, `src/comment-rules.ts`,
35
+ `src/context-doc-rules.ts`, `src/fixture-purpose-rules.ts`,
36
+ `src/test-block-rules.ts`, `src/security-flow-rules.ts`,
37
+ `src/github-actions-rules.ts`, and `src/safety-rules.ts` - focused rule
38
+ packs.
39
+ - `src/sensitive-data-rules.ts` - sensitive-data rule descriptors and
40
+ detectors.
41
+ - `src/project-config-rules.ts` - package and tsconfig rule descriptors.
42
+ - `src/baseline.ts`, `src/config.ts`, `src/dashboard.ts`, `src/findings.ts`,
43
+ `src/rule-list.ts`, `src/scoring.ts`, `src/source-text.ts`,
44
+ `src/text-scans.ts`, `src/report-renderers.ts`, `src/constants.ts`,
45
+ `src/types.ts` - shared helpers, contracts, and renderers.
46
+ - `src/*.test.ts` - Node test runner coverage for scanner behavior, rule
47
+ packs, fixtures, reports, and CLI surfaces.
48
+
49
+ Keep changes small and local. Do not add runtime dependencies beyond
50
+ `commander` and `tsx` unless that direction is explicitly accepted first.
51
+
52
+ ## Rules For Rule Changes
53
+
54
+ When adding or changing a rule:
55
+
56
+ - Add or update a `RuleDescriptor`.
57
+ - Include focused noisy and clean fixtures.
58
+ - Preserve the public `Finding` shape.
59
+ - Preserve fingerprint inputs unless a breaking schema change is planned.
60
+ - Add config threshold coverage when the rule has thresholds.
61
+ - Run `npm run check`.
62
+
63
+ Every finding must keep a stable `fingerprint`. Baselines depend on it.
64
+
65
+ ## Documentation Changes
66
+
67
+ Update docs when behavior changes:
68
+
69
+ - `README.md` for user-facing workflow changes.
70
+ - `CHANGELOG.md` for release-visible changes.
71
+ - `docs/CONFIGURATION.md` for config shape or threshold changes.
72
+ - `docs/REPORTS_AND_CI.md` for output, CI, dashboard, or baseline changes.
73
+ - `docs/RELEASING.md` for release process changes.
74
+
75
+ ## Pull Request Checklist
76
+
77
+ - [ ] Tests or fixtures cover the behavior change.
78
+ - [ ] `npm run check` passes.
79
+ - [ ] Public schemas are unchanged, or the breaking change is documented.
80
+ - [ ] Baseline/fingerprint behavior is unchanged, or the migration path is
81
+ documented.
82
+ - [ ] Docs and changelog are updated when user-visible behavior changes.
83
+
84
+ ## Security Issues
85
+
86
+ Do not open a public issue containing secrets, exploit payloads, or private
87
+ repository details. Follow [SECURITY.md](SECURITY.md).
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Matthew Hansen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,303 @@
1
+ # gruff-ts
2
+
3
+ `gruff-ts` is a static analyzer for TypeScript and JavaScript projects. The
4
+ dependency-light Node.js CLI scans source, tests, package metadata, and
5
+ common config files, then reports quality findings across 11 pillars with
6
+ stable fingerprints for baselines and repeatable machine output.
7
+
8
+ The 0.1.0 release ships 121 rules across 11 pillars,
9
+ JSON/HTML/Markdown/GitHub/SARIF/hotspot output, baseline support, changed-file
10
+ filtering, local score history, a rule catalogue, and a dark local dashboard.
11
+ Scanned file types include TypeScript, JavaScript, CSS, JSON, YAML, TOML, INI,
12
+ XML, and `.env*`.
13
+
14
+ ## Install
15
+
16
+ Install the scoped npm package; it exposes the `gruff-ts` CLI command:
17
+
18
+ ```bash
19
+ npm install --save-dev @blundergoat/gruff-ts
20
+ npx gruff-ts analyse . --fail-on=none
21
+ ```
22
+
23
+ From this checkout:
24
+
25
+ ```bash
26
+ npm install
27
+ ./bin/gruff-ts analyse . --fail-on=none
28
+ ```
29
+
30
+ ## Quick Start
31
+
32
+ Run an exploratory scan without failing the shell on findings:
33
+
34
+ ```bash
35
+ gruff-ts analyse . --fail-on=none
36
+ ```
37
+
38
+ Scan specific paths:
39
+
40
+ ```bash
41
+ gruff-ts analyse src fixtures/sample.ts --fail-on=none
42
+ ```
43
+
44
+ Generate a static HTML report:
45
+
46
+ ```bash
47
+ gruff-ts report . --output gruff-report.html
48
+ ```
49
+
50
+ Start the local dashboard:
51
+
52
+ ```bash
53
+ gruff-ts dashboard
54
+ ```
55
+
56
+ The dashboard binds to `127.0.0.1:8767` by default.
57
+
58
+ ## What It Checks
59
+
60
+ Findings are grouped into 11 public pillars:
61
+
62
+ - `size`
63
+ - `complexity`
64
+ - `dead-code`
65
+ - `waste`
66
+ - `naming`
67
+ - `documentation`
68
+ - `modernisation`
69
+ - `security`
70
+ - `sensitive-data`
71
+ - `test-quality`
72
+ - `design`
73
+
74
+ Inspect the exact rule ids, severities, confidence levels, remediation text,
75
+ threshold values, and options:
76
+
77
+ ```bash
78
+ gruff-ts list-rules
79
+ gruff-ts list-rules --format=json
80
+ ```
81
+
82
+ ## Commands
83
+
84
+ | Command | Purpose |
85
+ | --- | --- |
86
+ | `analyse [paths...]` | Run the scanner and print findings. |
87
+ | `summary [paths...]` | Print per-pillar counts, top rules, and top file offenders without per-finding output. |
88
+ | `report [paths...]` | Render an HTML or JSON report, optionally to a file. |
89
+ | `list-rules` | Print rule catalogue metadata. |
90
+ | `dashboard` | Serve the local HTTP dashboard. |
91
+ | `completion [shell]` | Print a shell completion script for `bash`, `zsh`, or `fish`. |
92
+ | `list` | Print the Symfony-style command catalogue. |
93
+
94
+ Useful help commands:
95
+
96
+ ```bash
97
+ gruff-ts --help
98
+ gruff-ts list
99
+ gruff-ts analyse --help
100
+ gruff-ts summary --help
101
+ gruff-ts report --help
102
+ gruff-ts dashboard --help
103
+ ```
104
+
105
+ Global console options match the `gruff` PHP CLI surface: `--silent`,
106
+ `--quiet`, `--ansi` / `--no-ansi`, `--no-interaction`, and `-v` / `-vv` /
107
+ `-vvv`. The command menu uses the same ANSI colour treatment as `gruff` when
108
+ stdout is a TTY; `--ansi` forces colour and `--no-ansi` disables it.
109
+
110
+ ## Output Formats
111
+
112
+ `analyse` supports:
113
+
114
+ | Format | Use case |
115
+ | --- | --- |
116
+ | `text` | Human terminal output. |
117
+ | `json` | Full machine-readable `gruff.analysis.v1` report. |
118
+ | `html` | Self-contained dark inspection report. |
119
+ | `markdown` | Short Markdown summary. |
120
+ | `github` | GitHub Actions annotation commands. |
121
+ | `hotspot` | Compact `gruff.hotspot.v1` top-offender payload. |
122
+ | `sarif` | SARIF 2.1.0 code-scanning output. |
123
+
124
+ Examples:
125
+
126
+ ```bash
127
+ gruff-ts analyse . --format=json --fail-on=none
128
+ gruff-ts analyse . --format=github --fail-on=warning
129
+ gruff-ts analyse . --format=hotspot --fail-on=none
130
+ gruff-ts analyse . --format=sarif --fail-on=none > gruff.sarif
131
+ ```
132
+
133
+ `report` supports `html` and `json`:
134
+
135
+ ```bash
136
+ gruff-ts report . --format=json --output gruff-report.json
137
+ ```
138
+
139
+ ## CI
140
+
141
+ `analyse` defaults to `--fail-on error`.
142
+
143
+ ```bash
144
+ # Exploratory scan: never fail because of findings.
145
+ gruff-ts analyse . --fail-on=none
146
+
147
+ # CI gate only on error findings.
148
+ gruff-ts analyse . --fail-on=error
149
+
150
+ # Stricter CI gate on warnings and errors.
151
+ gruff-ts analyse . --fail-on=warning
152
+ ```
153
+
154
+ Exit codes:
155
+
156
+ - `0`: scan completed and no finding met `--fail-on`.
157
+ - `1`: scan completed and at least one finding met `--fail-on`.
158
+ - `2`: scan produced diagnostics such as missing inputs or parse/config errors.
159
+
160
+ Changed-file scans:
161
+
162
+ ```bash
163
+ gruff-ts analyse . --diff=working-tree --format=github --fail-on=warning
164
+ gruff-ts analyse . --diff=staged --format=json --fail-on=none
165
+ ```
166
+
167
+ `--diff` accepts `working-tree`, `staged`, `unstaged`, or a base ref.
168
+
169
+ Security-focused CI can run without baseline suppression so new error-severity
170
+ security or sensitive-data findings cannot be hidden by an adoption baseline:
171
+
172
+ ```bash
173
+ gruff-ts analyse . --no-baseline --fail-on=error
174
+ ```
175
+
176
+ ## Baselines And History
177
+
178
+ Baselines suppress existing findings by stable fingerprint so teams can adopt
179
+ the tool without fixing every current issue first.
180
+
181
+ ```bash
182
+ gruff-ts analyse . --generate-baseline gruff-baseline.json --fail-on=none
183
+ gruff-ts analyse . --baseline gruff-baseline.json --fail-on=warning
184
+ gruff-ts analyse . --no-baseline --fail-on=none
185
+ ```
186
+
187
+ Baseline files use `schemaVersion: "gruff.baseline.v1"`.
188
+
189
+ `report` is intended for raw inspection output and does not accept
190
+ `--baseline`; use `analyse` when you need baseline suppression in CI.
191
+
192
+ Append local score history:
193
+
194
+ ```bash
195
+ gruff-ts analyse . --history-file .gruff-history.json --fail-on=none
196
+ ```
197
+
198
+ ## Configuration
199
+
200
+ `analyse` auto-loads the first supported config file it finds in the project root:
201
+
202
+ 1. `.gruff-ts.yaml`
203
+ 2. `.gruff.json`
204
+ 3. `.gruff.yaml`
205
+ 4. `.gruff.yml`
206
+
207
+ Use an explicit config or skip config loading:
208
+
209
+ ```bash
210
+ gruff-ts analyse . --config .gruff-ts.yaml
211
+ gruff-ts analyse . --no-config
212
+ ```
213
+
214
+ Recursive scans respect root and nested `.gitignore` files. Use
215
+ `--include-ignored` to include default and Git-ignored paths for a run;
216
+ `paths.ignore` entries still apply as project policy.
217
+
218
+ Minimal YAML example:
219
+
220
+ ```yaml
221
+ paths:
222
+ ignore:
223
+ - "generated/**"
224
+
225
+ allowlists:
226
+ acceptedAbbreviations:
227
+ - api
228
+ - cli
229
+ secretPreviews: []
230
+
231
+ rules:
232
+ complexity.cyclomatic:
233
+ threshold: 10
234
+ severity: warning
235
+ size.file-length:
236
+ threshold: 400
237
+ severity: warning
238
+ ```
239
+
240
+ See [Configuration](docs/CONFIGURATION.md) for the full config shape and
241
+ examples.
242
+
243
+ ## Dashboard
244
+
245
+ Start the local dashboard:
246
+
247
+ ```bash
248
+ gruff-ts dashboard --host 127.0.0.1 --port 8767 --project-root .
249
+ ```
250
+
251
+ The dashboard serves a local iframe report and a compact controls panel. Keep
252
+ the default loopback bind unless the network is trusted. The `/scan` endpoint
253
+ analyses filesystem paths from request parameters, so the bind address is the
254
+ main safety boundary.
255
+
256
+ ## Safety And Limitations
257
+
258
+ - Secret-like findings include redacted previews; raw secret values should not
259
+ appear in findings or rendered output.
260
+ - The scanner is heuristic. It is not a TypeScript compiler, type checker, or
261
+ full JavaScript parser.
262
+ - Rule confidence is included in the rule catalogue and each finding. Treat low
263
+ and medium confidence findings as review prompts.
264
+ - Baselines suppress matching fingerprints. Review baseline diffs carefully so
265
+ new findings are not hidden by accident.
266
+
267
+ ## Documentation
268
+
269
+ - [Changelog](CHANGELOG.md)
270
+ - [Configuration](docs/CONFIGURATION.md)
271
+ - [Reports and CI](docs/REPORTS_AND_CI.md)
272
+ - [Contributing](CONTRIBUTING.md)
273
+ - [Security](SECURITY.md)
274
+ - [Release checklist](docs/RELEASING.md)
275
+
276
+ ## Development
277
+
278
+ ```bash
279
+ npm install
280
+ npm run check
281
+ npm test
282
+ npm run start-dev
283
+ ./bin/gruff-ts analyse . --fail-on=none
284
+ ```
285
+
286
+ Source lives under `src/`: `src/cli.ts` is the thin bootstrap,
287
+ `src/cli-program.ts` owns Commander wiring, `src/analyser.ts` orchestrates the
288
+ scan, `src/rules.ts` holds the descriptor catalogue, and focused sibling
289
+ modules own rule packs and renderers. Tests live in focused `src/*.test.ts`
290
+ files.
291
+
292
+ To bump the released version, run `scripts/bump-version.sh <new-version>` - it
293
+ updates `package.json` and `src/constants.ts` in lockstep so the CLI
294
+ `--version` output stays consistent with the published `@blundergoat/gruff-ts`
295
+ package.
296
+
297
+ ## Author
298
+
299
+ Built by [Matthew Hansen](https://www.blundergoat.com/about).
300
+
301
+ ## License
302
+
303
+ [MIT](LICENSE)
package/SECURITY.md ADDED
@@ -0,0 +1,45 @@
1
+ # Security Policy
2
+
3
+ ## Supported Versions
4
+
5
+ | Version | Supported |
6
+ | --- | --- |
7
+ | 0.1.x | Yes |
8
+
9
+ ## Reporting A Vulnerability
10
+
11
+ Do not file a public issue with exploit details, secrets, tokens, private source
12
+ paths, or sensitive scan output.
13
+
14
+ Use the project's private vulnerability reporting channel if one is enabled on
15
+ the public repository. If private reporting is not available yet, contact the
16
+ maintainer through the preferred private channel before posting details
17
+ publicly.
18
+
19
+ Please include:
20
+
21
+ - A short description of the issue.
22
+ - A minimal reproduction when possible.
23
+ - Affected command or output format.
24
+ - Whether sensitive data is exposed in findings, reports, dashboard output, or
25
+ logs.
26
+ - Whether a baseline, SARIF upload, GitHub annotation output, or dashboard scan
27
+ endpoint is involved.
28
+
29
+ ## Security Boundaries
30
+
31
+ - The dashboard is a local developer tool. It binds to `127.0.0.1` by default.
32
+ Binding it to `0.0.0.0` can expose filesystem scanning to the network.
33
+ - Sensitive-data rules should render redacted previews only.
34
+ - HTML output is generated without a template engine; new interpolated fields
35
+ must be escaped.
36
+ - The scanner is heuristic and is not a vulnerability scanner or dependency
37
+ advisory database.
38
+ - Baselines suppress matching fingerprints. For security-focused CI, prefer
39
+ `gruff-ts analyse . --no-baseline --fail-on=error`.
40
+
41
+ ## Disclosure Expectations
42
+
43
+ The maintainer should acknowledge valid private reports, assess impact, and
44
+ coordinate a fix before public disclosure. Public advisories should include the
45
+ affected versions, fixed version, and mitigation.
package/bin/gruff-ts ADDED
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env sh
2
+ set -eu
3
+
4
+ PRG="$0"
5
+ while [ -h "$PRG" ]; do
6
+ SCRIPT_DIR="$(CDPATH= cd -- "$(dirname -- "$PRG")" && pwd)"
7
+ PRG="$(readlink "$PRG")"
8
+ case "$PRG" in
9
+ /*) ;;
10
+ *) PRG="$SCRIPT_DIR/$PRG" ;;
11
+ esac
12
+ done
13
+
14
+ SCRIPT_DIR="$(CDPATH= cd -- "$(dirname -- "$PRG")" && pwd)"
15
+ PACKAGE_DIR="$SCRIPT_DIR/.."
16
+
17
+ if [ -f "$PACKAGE_DIR/node_modules/tsx/dist/loader.mjs" ]; then
18
+ TSX_LOADER="$PACKAGE_DIR/node_modules/tsx/dist/loader.mjs"
19
+ elif [ -f "$PACKAGE_DIR/../tsx/dist/loader.mjs" ]; then
20
+ TSX_LOADER="$PACKAGE_DIR/../tsx/dist/loader.mjs"
21
+ else
22
+ TSX_LOADER="tsx"
23
+ fi
24
+
25
+ exec node --import "$TSX_LOADER" "$PACKAGE_DIR/src/cli.ts" "$@"