@blundergoat/gruff-ts 0.4.0 → 0.6.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 (77) hide show
  1. package/CHANGELOG.md +123 -1
  2. package/CONTRIBUTING.md +32 -25
  3. package/README.md +55 -46
  4. package/SECURITY.md +18 -30
  5. package/UPGRADING.md +101 -0
  6. package/bin/gruff-ts +3 -0
  7. package/docs/README.md +11 -13
  8. package/docs/agent-hook.md +33 -24
  9. package/docs/ci-integration.md +38 -24
  10. package/docs/configuration.md +173 -71
  11. package/docs/dashboard.md +12 -13
  12. package/docs/output-formats.md +100 -25
  13. package/docs/philosophy.md +2 -2
  14. package/docs/reports-and-ci.md +14 -157
  15. package/docs/rules.md +140 -106
  16. package/package.json +10 -8
  17. package/src/analyser.ts +886 -282
  18. package/src/baseline-file.ts +867 -0
  19. package/src/baseline-identity.ts +463 -0
  20. package/src/baseline-options.ts +139 -34
  21. package/src/baseline.ts +85 -55
  22. package/src/blocks.ts +579 -364
  23. package/src/changed-regions.ts +414 -65
  24. package/src/check-ignore.ts +28 -13
  25. package/src/class-rules.ts +461 -302
  26. package/src/cli-program.ts +956 -166
  27. package/src/cli.ts +9 -2
  28. package/src/comment-rules.ts +277 -414
  29. package/src/comment-scanner.ts +363 -44
  30. package/src/complexity-metrics.ts +320 -0
  31. package/src/config-load-error.ts +17 -8
  32. package/src/config-parse.ts +291 -98
  33. package/src/config-preservation.ts +81 -26
  34. package/src/config.ts +778 -210
  35. package/src/constants.ts +7 -6
  36. package/src/context-doc-rules.ts +188 -61
  37. package/src/dashboard.ts +88 -23
  38. package/src/dead-code-rules.ts +153 -74
  39. package/src/discovery.ts +521 -148
  40. package/src/doc-rules.ts +592 -147
  41. package/src/duplicate-test-group-rules.ts +359 -0
  42. package/src/findings-helpers.ts +240 -89
  43. package/src/findings.ts +48 -24
  44. package/src/fixture-purpose-rules.ts +226 -48
  45. package/src/github-actions-event-guards.ts +331 -0
  46. package/src/github-actions-rules.ts +336 -106
  47. package/src/hook-contract.ts +708 -211
  48. package/src/init-config.ts +169 -114
  49. package/src/inline-suppressions.ts +340 -0
  50. package/src/limit-band.ts +56 -0
  51. package/src/line-rules.ts +331 -419
  52. package/src/migrate-config.ts +670 -0
  53. package/src/naming-pushers.ts +33 -107
  54. package/src/parsed-script.ts +1206 -0
  55. package/src/pillar-summary.ts +56 -40
  56. package/src/profiles.ts +97 -71
  57. package/src/project-config-rules.ts +335 -146
  58. package/src/project-rules.ts +237 -115
  59. package/src/public-exports.ts +284 -0
  60. package/src/report-html.ts +217 -85
  61. package/src/report-renderers.ts +864 -195
  62. package/src/rule-list.ts +166 -46
  63. package/src/rules.ts +100 -104
  64. package/src/safety-rules.ts +191 -132
  65. package/src/scoring.ts +255 -52
  66. package/src/security-flow-rules.ts +930 -109
  67. package/src/selectors.ts +169 -0
  68. package/src/sensitive-data-rules.ts +502 -375
  69. package/src/sensitive-exclusions.ts +435 -0
  70. package/src/source-text.ts +380 -148
  71. package/src/static-analysis-redundant-rules.ts +298 -41
  72. package/src/test-block-rules.ts +422 -228
  73. package/src/text-scans.ts +67 -9
  74. package/src/types.ts +222 -71
  75. package/tsconfig.json +2 -1
  76. package/src/process-exec-metadata.ts +0 -153
  77. package/src/test-fixtures.ts +0 -668
package/src/text-scans.ts CHANGED
@@ -1,5 +1,11 @@
1
- // Empty-match guard (`lastIndex += 1`) prevents zero-width patterns like /(?=)/g from looping forever.
2
- // Caller's RegExp is never mutated - `globalRegExp` clones it when the global flag is missing.
1
+ /**
2
+ * Counts pattern matches in `source` for occurrence-based rules without mutating `pattern`.
3
+ * Empty matches count toward the total; the scan advances by one code unit to avoid retrying a zero-width match.
4
+ *
5
+ * @param source - Text to scan for matches.
6
+ * @param pattern - Regular expression matched via a fresh global copy so caller state is unchanged.
7
+ * @returns Number of matches found in `source`, or zero when none match.
8
+ */
3
9
  function countMatches(source: string, pattern: RegExp): number {
4
10
  const globalPattern = globalRegExp(pattern);
5
11
  let count = 0;
@@ -14,20 +20,35 @@ function countMatches(source: string, pattern: RegExp): number {
14
20
  return count;
15
21
  }
16
22
 
17
- // Clones into a new `g`-flagged RegExp when needed. Mutating the caller's pattern (via `lastIndex`)
18
- // would silently break any further use on the calling side - rule descriptors share patterns at module scope.
23
+ /**
24
+ * Clones `pattern` with the global flag enabled while preserving its other flags so scans cannot mutate the caller's RegExp.
25
+ *
26
+ * @param pattern - Source regular expression whose pattern text and existing flags are copied.
27
+ * @returns New global RegExp instance with the same source and flags as `pattern`.
28
+ */
19
29
  function globalRegExp(pattern: RegExp): RegExp {
20
30
  return new RegExp(pattern.source, pattern.flags.includes("g") ? pattern.flags : `${pattern.flags}g`);
21
31
  }
22
32
 
23
- // One-based line number of the first matching line, defaulting to 1 when no match exists so
24
- // findings always have a valid anchor. Used by rules that need a stable file-level location.
33
+ /**
34
+ * Finds the first line accepted by `pattern.test` to anchor file-level findings.
35
+ * Uses `pattern`'s current state; global or sticky patterns may change `lastIndex` and affect which line is accepted.
36
+ *
37
+ * @param source - Multi-line text split on LF or CRLF line endings.
38
+ * @param pattern - Regular expression tested line by line using its current `lastIndex` state.
39
+ * @returns One-based line number of the first matching line, or 1 when no line passes.
40
+ */
25
41
  function firstLine(source: string, pattern: RegExp): number {
26
42
  return source.split(/\r?\n/).findIndex((line) => pattern.test(line)) + 1 || 1;
27
43
  }
28
44
 
29
- // One-based line number containing byte offset `index`. Used to anchor findings extracted from
30
- // regex match indices; off-by-one would shift every reported line in the resulting reports.
45
+ /**
46
+ * Computes the one-based line number at a UTF-16 index for regex-derived finding locations.
47
+ *
48
+ * @param source - Text whose newline characters before `index` are counted.
49
+ * @param index - Zero-based UTF-16 code unit offset; negative indices use the start of `source`.
50
+ * @returns One-based line number at `index`.
51
+ */
31
52
  function byteLine(source: string, index: number): number {
32
53
  const end = Math.max(0, index);
33
54
  let line = 1;
@@ -39,4 +60,41 @@ function byteLine(source: string, index: number): number {
39
60
  return line;
40
61
  }
41
62
 
42
- export { byteLine, countMatches, firstLine };
63
+ /**
64
+ * Computes the one-based column of UTF-16 offset `index` on its line.
65
+ * Lets two matches on one line report distinct positions so neither occurrence is lost when their line-keyed identities collide.
66
+ *
67
+ * @param source - Text containing the line to measure against.
68
+ * @param index - Zero-based UTF-16 offset; negative indices are clamped to the start of `source`.
69
+ * @returns One-based column offset from the start of the line containing `index`.
70
+ */
71
+ function byteColumn(source: string, index: number): number {
72
+ const end = Math.max(0, index);
73
+ return end - source.lastIndexOf("\n", end - 1);
74
+ }
75
+
76
+ /**
77
+ * Finds the closing parenthesis paired with the opening parenthesis at `openParen` in masked source.
78
+ * Callers mask strings and comments so parentheses inside them do not affect the nesting count.
79
+ *
80
+ * @param source - Masked source text scanned forward from `openParen`.
81
+ * @param openParen - Zero-based index of the opening parenthesis in `source`.
82
+ * @returns Zero-based index of the matching closing parenthesis, or undefined if none is found.
83
+ */
84
+ function matchingCloseParen(source: string, openParen: number): number | undefined {
85
+ let depth = 0;
86
+ for (let index = openParen; index < source.length; index += 1) {
87
+ const character = source[index];
88
+ if (character === "(") {
89
+ depth += 1;
90
+ } else if (character === ")") {
91
+ depth -= 1;
92
+ if (depth === 0) {
93
+ return index;
94
+ }
95
+ }
96
+ }
97
+ return undefined;
98
+ }
99
+
100
+ export { byteColumn, byteLine, countMatches, firstLine, matchingCloseParen };
package/src/types.ts CHANGED
@@ -1,3 +1,8 @@
1
+ // Shared analyzer types define the settings, findings, diagnostics, and reports exposed across the TypeScript port.
2
+ //
3
+ // CLI commands, rules, and renderers share these shapes so users and CI get one consistent view of every run.
4
+ // Optional flags and source coordinates stay omitted when absent rather than turning into `null`.
5
+
1
6
  /** Finding impact level used for scoring, output, and fail-on thresholds. */
2
7
  export type Severity = "advisory" | "warning" | "error";
3
8
 
@@ -27,21 +32,39 @@ export type FailThreshold = "none" | "advisory" | "warning" | "error";
27
32
  /** Changed-region filter precision for diff-aware analysis. */
28
33
  export type ChangedScopeMode = "symbol" | "hunk" | "file";
29
34
 
30
- /** Public options contract consumed by the analyzer core and CLI. */
35
+ /** Records which layer selected the effective bounded deep-scan settings. */
36
+ export type DeepScanBudgetOverrideState = "default" | "config" | "cli";
37
+
38
+ /** Effective per-source bounds for expensive script analysis. */
39
+ export interface DeepScanBudget {
40
+ enabled: boolean;
41
+ maxLines: number;
42
+ maxBytes: number;
43
+ override: DeepScanBudgetOverrideState;
44
+ }
45
+
46
+ /** Atomic CLI override; disabling the budget intentionally carries no numeric limits. */
47
+ export type DeepScanBudgetOverride =
48
+ | { enabled: false }
49
+ | { enabled: true; maxLines: number; maxBytes: number };
50
+
51
+ /**
52
+ * Defines the stable options contract resolved from one user command before analysis starts.
53
+ *
54
+ * Optional paths and filters stay absent when the user did not select them, allowing downstream code to preserve default behavior.
55
+ */
31
56
  export interface AnalysisOptions {
32
57
  paths: string[];
33
58
  config?: string;
34
- /**
35
- * Named built-in profile (`gruff.minimal` / `gruff.recommended` / `gruff.strict`) or a path to a
36
- * profile file, from the `--profile` CLI flag. Wins over a config-file `profile:` block. Absent
37
- * means "fall back to the config-file profile, else the default `recommended` (a no-op delta)".
38
- */
59
+ /** CLI profile name or file; missing means use the config-file profile or the recommended default. */
39
60
  profile?: string;
40
61
  shouldSkipConfig: boolean;
41
62
  format: OutputFormat;
42
63
  failOn: FailThreshold;
43
64
  shouldIncludeIgnored: boolean;
44
65
  diff?: string;
66
+ /** True when `diff` came from `--diff-base` and names an explicit Git revision rather than a `--diff` mode keyword. */
67
+ isDiffExplicitRef?: boolean;
45
68
  since?: string;
46
69
  changedRanges?: string;
47
70
  changedScope: ChangedScopeMode;
@@ -49,53 +72,112 @@ export interface AnalysisOptions {
49
72
  historyFile?: string;
50
73
  baseline?: string;
51
74
  generateBaseline?: string;
75
+ /** 0.5 baseline whose reviews are carried into `generateBaseline`; absent means nothing is carried across. */
76
+ migrateBaseline?: string;
77
+ /** Overwrite a 0.5 baseline at the shared default path instead of refusing, which is what `--force` means. */
78
+ shouldForceBaselineOverwrite?: boolean;
52
79
  shouldSkipBaseline: boolean;
80
+ deepScanBudget?: DeepScanBudgetOverride;
81
+ /**
82
+ * Which rules this run executes, from `--include-rule` and its three siblings.
83
+ *
84
+ * Absent means the whole catalogue runs. It belongs here, and the presentation selectors do not, because these
85
+ * change what is found and therefore the score.
86
+ */
87
+ execution?: ExecutionSelectors;
53
88
  }
54
89
 
55
- /** Command keys that participate in the `minimumSeverity:` config block. `dashboard` is omitted on purpose - it has no `--fail-on` flag and accepting it as a key would silently no-op. See ADR-004. */
90
+ /**
91
+ * Which rules one run executes, chosen by `--include-rule`, `--exclude-rule`, `--include-pillar` and `--exclude-pillar`.
92
+ *
93
+ * Every list is empty when the user asked for nothing, which leaves the full catalogue running.
94
+ */
95
+ export interface ExecutionSelectors {
96
+ includeRules: string[];
97
+ excludeRules: string[];
98
+ includePillars: string[];
99
+ excludePillars: string[];
100
+ }
101
+
102
+ /** Commands that support a configured `failOn` gate; dashboard is absent because it has no `--fail-on` behavior (ADR-004). */
56
103
  export type MinimumSeverityCommand = "analyse" | "summary" | "report";
57
104
 
58
105
  /**
59
- * Loaded analyzer configuration derived from optional gruff config files. The schema invariant is
60
- * that `schemaVersion` is fixed at the supported version and every field has a defined default in
61
- * `defaultConfig()` so consumers can rely on the shape without per-field guards.
106
+ * Describes the complete settings used for one user scan after defaults, profiles, and config overlays.
107
+ *
108
+ * Every collection is present even when empty, while the fixed schema version lets consumers use the shape without field guards.
62
109
  */
63
110
  export interface Config {
64
- /**
65
- * Required top-level config-schema version. Pre-1.0 break: every `.gruff-ts.yaml` must declare
66
- * `schemaVersion: gruff-ts.config.v0.1` or loading throws. Lives in the `gruff-ts.config.*`
67
- * namespace, distinct from the output schemas (`gruff.analysis.v2`, etc.). See ADR-004.
68
- */
111
+ /** Required config-schema version; missing or different values stop the user's command before analysis (ADR-004). */
69
112
  schemaVersion: "gruff-ts.config.v0.1";
70
113
  ignoredPaths: string[];
71
114
  acceptedAbbreviations: Set<string>;
72
- secretPreviews: Set<string>;
73
- bannedGenericNames: Set<string>;
74
- acceptedBooleanNames: Set<string>;
75
- booleanPrefixes: Set<string>;
76
- hungarianPrefixes: Set<string>;
115
+ acceptedClassFilePairs: Set<string>;
77
116
  placeholderNames: Set<string>;
78
- negativeBooleanAllowed: Set<string>;
79
- knownAcronyms: Set<string>;
80
- /**
81
- * Per-command default for `--fail-on`. Precedence: CLI flag > this map > binary default.
82
- * `dashboard` is intentionally not a valid key (no `--fail-on` flag exists for it); the parser
83
- * rejects `dashboard` with a documented error. See ADR-004.
84
- */
117
+ /** Project rationale and tracking references such as milestone ids, from `allowlists.trackingTokens`; none ship by default. */
118
+ trackingTokens: RegExp[];
119
+ /** Per-command `--fail-on` defaults from `failOn:`; an empty map means each command keeps its binary default (ADR-004). */
85
120
  minimumSeverity: Map<MinimumSeverityCommand, FailThreshold>;
86
- rules: Map<string, { enabled?: boolean; threshold?: number; severity?: Severity; options: Map<string, number> }>;
121
+ /** The `minimumSeverity:` display floor: findings below it are hidden from the report and still scored and gated. */
122
+ displayFloor?: Severity;
123
+ rules: Map<string, { enabled?: boolean; threshold?: number; severity?: Severity; options: Map<string, number | boolean> }>;
124
+ deepScanBudget: DeepScanBudget;
125
+ /** Reviewed sensitive-data suppressions in declaration order; an empty list means nothing is suppressed. */
126
+ sensitiveExclusions: SensitiveExclusion[];
127
+ }
128
+
129
+ /**
130
+ * Describes one reviewed suppression from the config file's `sensitiveExclusions:` section.
131
+ *
132
+ * The scope is exactly one rule id in exactly one project-relative file, narrowed further when the user supplies a symbol.
133
+ * Stable contract: nothing is matched against a finding's message or its detected value, so a suppression can never depend on secret material.
134
+ */
135
+ export interface SensitiveExclusion {
136
+ rule: string;
137
+ path: string;
138
+ /** Present only when the user narrowed the scope; a finding without that exact symbol keeps reporting. */
139
+ symbol?: string;
140
+ reason: string;
87
141
  }
88
142
 
89
143
  /**
90
- * One rule's settings inside a profile. Mirrors the per-rule knobs of the config `rules:` block
91
- * (`enabled` defaults to true when omitted). `options` is optional here - built-in presets never set
92
- * options - whereas the loaded `Config.rules` value always carries an (often empty) options map.
144
+ * Reports what one configured sensitive exclusion suppressed during the user's scan.
145
+ *
146
+ * Every configured entry publishes a row even when it matched nothing, so a suppression is counted rather than silently invisible.
147
+ * `symbol` is null when the entry did not narrow to one, and `paths` holds the entry's single configured path as the family-shaped list.
148
+ */
149
+ export interface SuppressionSummary {
150
+ index: number;
151
+ rule: string;
152
+ paths: string[];
153
+ symbol: string | null;
154
+ reason: string;
155
+ suppressed: number;
156
+ /** `built-in` on a row the family test-path skip produced, `inline` or `duplicate` on a section 13c row; absent on a configured entry's row. */
157
+ source?: "built-in" | "inline" | "duplicate";
158
+ }
159
+
160
+ /**
161
+ * A finding another tool's comment or a repeated claim removed (FAMILY-CONTRACT.md section 13c).
162
+ *
163
+ * Invariant: it never reaches the findings list, the score or the exit code; SARIF keeps it as a result marked suppressed.
164
+ */
165
+ export interface SuppressedFinding {
166
+ finding: Finding;
167
+ /** The audit reason a SARIF reader sees on the suppressed result. */
168
+ justification: string;
169
+ }
170
+
171
+ /**
172
+ * Describes one rule override inside a profile before it joins the user's effective configuration.
173
+ *
174
+ * Missing fields inherit from the base profile or descriptor; a missing options map means the profile did not tune any option.
93
175
  */
94
176
  export interface ProfileRuleSetting {
95
177
  enabled?: boolean;
96
178
  threshold?: number;
97
179
  severity?: Severity;
98
- options?: Map<string, number>;
180
+ options?: Map<string, number | boolean>;
99
181
  }
100
182
 
101
183
  /**
@@ -105,9 +187,9 @@ export interface ProfileRuleSetting {
105
187
  export type ProfileSpec = string | InlineProfileSpec;
106
188
 
107
189
  /**
108
- * The inline `profile:` object form. `extends` names the base (a built-in name or a relative file
109
- * path; defaults to `gruff.recommended` when omitted); `rules` and `ignoredPaths` override the base
110
- * with child-wins semantics - per-rule fields merge, and the `ignoredPaths` array replaces.
190
+ * Describes the inline profile form users can place in configuration.
191
+ *
192
+ * Missing `extends` selects recommended; missing rules or ignored paths inherit the base, while supplied values use child-wins behavior.
111
193
  */
112
194
  export interface InlineProfileSpec {
113
195
  extends?: string;
@@ -116,9 +198,9 @@ export interface InlineProfileSpec {
116
198
  }
117
199
 
118
200
  /**
119
- * A fully resolved and flattened profile: the effective rule settings and ignored paths after the
120
- * whole `extends:` chain has collapsed into one delta from the descriptor defaults. Enabled-at-default
121
- * rules are omitted from `rules`, so `gruff.recommended` flattens to an empty map (the parity contract).
201
+ * Describes a fully resolved profile ready to sit beneath the user's direct configuration.
202
+ *
203
+ * Empty rules or ignored paths mean the profile adds no values in that area; the recommended profile is therefore a no-op delta.
122
204
  */
123
205
  export interface ProfileDefinition {
124
206
  name: string;
@@ -126,7 +208,11 @@ export interface ProfileDefinition {
126
208
  ignoredPaths: string[];
127
209
  }
128
210
 
129
- /** Stable analysis finding emitted by a rule. */
211
+ /**
212
+ * Defines the stable finding contract shown in user reports and machine integrations.
213
+ *
214
+ * Missing locations, symbols, or remediation mean the rule could not provide that context; metadata remains an object even when empty.
215
+ */
130
216
  export interface Finding {
131
217
  ruleId: string;
132
218
  message: string;
@@ -144,25 +230,44 @@ export interface Finding {
144
230
  metadata: Record<string, unknown>;
145
231
  fingerprint: string;
146
232
  stableIdentity: string;
233
+ /**
234
+ * The ratified durable identity this run computed, which SARIF publishes as the code-scanning fingerprint.
235
+ * Absent for a sensitive finding, which has no durable name, and for a finding built outside the analyser.
236
+ */
237
+ baselineIdentity?: string;
238
+ /**
239
+ * The subject that identity hashed, which carries the declaration ordinal a consumer needs to recompute it.
240
+ * Absent wherever `baselineIdentity` is, because the two are computed together or not at all.
241
+ */
242
+ baselineSubject?: string;
147
243
  }
148
244
 
149
- /** Non-finding runtime diagnostic emitted while preparing or reading inputs. */
245
+ /**
246
+ * Describes a runtime problem encountered while preparing or reading the user's scan inputs.
247
+ *
248
+ * Missing file or line fields mean the problem applies to the command or input set rather than one precise source location.
249
+ */
150
250
  export interface RunDiagnostic {
151
251
  diagnosticType: string;
152
252
  message: string;
153
253
  filePath?: string;
154
254
  line?: number;
255
+ /** False marks a visible diagnostic that must not change an otherwise-successful exit status. */
256
+ invalidatesRun?: false;
155
257
  }
156
258
 
157
259
  /**
158
- * Source that excluded a path from analysis. `config` (`paths.ignore`) is authoritative in every
159
- * invocation mode - explicit file operands and diff/changed-region runs included - and is never
160
- * overridden by `--include-ignored`. `gitignore` and `default` are discovery-walk ignores: they are
161
- * suppressed by `--include-ignored` and bypassed for an explicitly supplied file operand (ADR-003).
260
+ * Names the policy source that excluded a path from the user's scan.
261
+ *
262
+ * Config ignores always apply; `--include-ignored` can bypass discovery ignores from Git or Gruff defaults (ADR-003).
162
263
  */
163
264
  export type IgnoreSource = "config" | "gitignore" | "default";
164
265
 
165
- /** One path excluded from analysis, with the ignore source and the exact pattern that matched. */
266
+ /**
267
+ * Describes one path excluded from the user's analysis surface.
268
+ *
269
+ * The source and matching pattern explain why it was skipped, so no field is optional or empty for a recorded entry.
270
+ */
166
271
  export interface SkippedPath {
167
272
  path: string;
168
273
  source: IgnoreSource;
@@ -170,46 +275,94 @@ export interface SkippedPath {
170
275
  }
171
276
 
172
277
  /**
173
- * Non-fatal scan-surface note (additive in 0.4.0, owner-approved): explains a scan whose surface
174
- * differs from what the caller likely expected - a requested input that produced no analysable
175
- * files (`no-analysable-files`), or a file whose deep script analysis was bounded by the scan
176
- * budget (`bounded-deep-scan`). Notes never affect exit codes; `diagnostics` stays the surface
177
- * that drives exit 2.
278
+ * Describes a non-fatal difference between the scan surface requested by the user and the files Gruff could analyze.
279
+ *
280
+ * Notes explain empty, bounded, or non-text inputs without changing exit status; fatal preparation problems remain diagnostics.
178
281
  */
179
282
  export interface ScanSurfaceNote {
180
- noteType: "no-analysable-files" | "bounded-deep-scan";
283
+ noteType: "no-analysable-files" | "bounded-deep-scan" | "non-text-file";
181
284
  path: string;
182
285
  message: string;
183
286
  }
184
287
 
185
288
  /**
186
- * Stable gruff.analysis.v2 report schema returned by analyse and JSON report commands.
289
+ * Native analysis state consumed by CLI renderers, HTML/dashboard views, and the coding-agent hook.
187
290
  *
188
- * `paths.skipped` (added in 0.3.0, ADR-007) is an additive field: each entry carries the excluded
189
- * `path`, the ignore `source`, and the matching `pattern`. `paths.ignoredPaths` is retained as the
190
- * back-compatible `string[]` of the same paths, so existing v2 consumers keep working without change.
291
+ * Invariant: native identities and score values remain stable while JSON renderers project this state into `gruff.analysis.v3`.
191
292
  */
192
293
  export interface AnalysisReport {
193
- schemaVersion: "gruff.analysis.v2";
294
+ schemaVersion: "gruff.analysis.v3";
194
295
  tool: { name: "gruff-ts"; version: string };
195
- run: { projectRoot: string; format: OutputFormat; failOn: FailThreshold; generatedAt: string };
296
+ run: {
297
+ projectRoot: string;
298
+ format: OutputFormat;
299
+ failOn: FailThreshold;
300
+ generatedAt: string;
301
+ inputs?: string[];
302
+ config?: string;
303
+ includeIgnored?: true;
304
+ };
196
305
  summary: { advisory: number; warning: number; error: number; total: number };
197
306
  paths: { analysedFiles: number; ignoredPaths: string[]; skipped: SkippedPath[]; missingPaths: string[] };
198
307
  diagnostics: RunDiagnostic[];
199
- /** Additive in 0.4.0: present only when at least one scan-surface note was produced. */
308
+ /** Missing means the scan produced no non-fatal surface notes. */
200
309
  notes?: ScanSurfaceNote[];
310
+ /** Configured audit rows in declaration order, then built-in test-path, inline and duplicate rows;
311
+ * empty only when nothing is configured and nothing was removed. */
312
+ suppressions: SuppressionSummary[];
201
313
  findings: Finding[];
314
+ /** Findings section 13c removed; never in the JSON envelope, which counts them in `suppressions`, but kept by SARIF. */
315
+ suppressedFindings?: SuppressedFinding[];
202
316
  suppressedCount?: number;
203
317
  score: {
204
- composite: number;
205
- grade: string;
206
- pillars: Array<{ pillar: Pillar; score: number; penalty: number; findings: number }>;
207
- topOffenders: Array<{ filePath: string; score: number; findings: number }>;
318
+ /** Mean of the applicable pillar scores; null when nothing applicable was evaluated. */
319
+ composite: number | null;
320
+ /** Letter grade derived from `composite`; null whenever `composite` is. */
321
+ grade: string | null;
322
+ /** Ratified scoring denominator: script files that survived discovery. */
323
+ evaluatedFiles: number;
324
+ /** Every pillar this run could reach, so the composite's denominator is visible. */
325
+ scoredPillars: Pillar[];
326
+ /** Correlated concepts that billed one shared weight, so a reader can see what the grade counted once. */
327
+ clusters: Array<{ file: string; symbol: string; ruleIds: string[]; findings: number; weight: number }>;
328
+ /** How much weight each native rule removed from the score; the native ruleId is the attribution key. */
329
+ ruleAttribution: Array<{ ruleId: string; findings: number; weight: number }>;
330
+ pillars: Array<{ pillar: Pillar; applicable: boolean; score: number | null; grade: string | null; penalty: number; findings: number }>;
331
+ topOffenders: Array<{ filePath: string; score: number | null; penalty: number; findings: number }>;
332
+ };
333
+ /**
334
+ * Present only when a baseline was used or written. `suppressed` counts the reviewed debt this run hid;
335
+ * `newFindings` is the gated count the user must still act on, and is absent on a generate run, which hides nothing.
336
+ */
337
+ baseline?: {
338
+ path: string;
339
+ source: string;
340
+ suppressed: number;
341
+ generated: boolean;
342
+ entries?: number;
343
+ newFindings?: number;
344
+ unchangedFindings?: number;
345
+ resolvedFindings?: number;
346
+ sensitiveCounted?: number;
208
347
  };
209
- baseline?: { path: string; source: string; suppressed: number; generated: boolean };
210
348
  }
211
349
 
212
- /** Static catalogue entry describing a rule's purpose and configuration knobs. */
350
+ /**
351
+ * One reviewed code shape that trips a rule without representing the defect it targets, shown in `list-rules --rule <id>`.
352
+ *
353
+ * `shape` names the pattern a developer recognises in source; `mitigation` names a concrete config key or code adjustment.
354
+ * Omitted when no reviewed false-positive shapes exist rather than emitted as an empty array.
355
+ */
356
+ export interface FalsePositiveShape {
357
+ shape: string;
358
+ mitigation: string;
359
+ }
360
+
361
+ /**
362
+ * The public metadata for one rule: what `list-rules` prints, what reports carry, and what the
363
+ * generated config comments describe. Every optional member is omitted rather than emitted empty,
364
+ * so an absent key means the rule has no such control rather than an unset one.
365
+ */
213
366
  export interface RuleDescriptor {
214
367
  ruleId: string;
215
368
  pillar: Pillar;
@@ -217,15 +370,13 @@ export interface RuleDescriptor {
217
370
  confidence: Confidence;
218
371
  description: string;
219
372
  remediation: string;
373
+ /** False for a rule that runs only when a config enables it; omitted means the rule is on by default. Published as `defaultEnabled`. */
374
+ isEnabledByDefault?: boolean;
220
375
  threshold?: number;
221
376
  optionKeys?: readonly string[];
222
- /**
223
- * Names of `allowlists.*` keys in `.gruff-ts.yaml` that override or extend the rule's
224
- * behaviour. Mirrors the `optionKeys` shape but targets the cross-pillar allowlist surface
225
- * (e.g. `naming.boolean-prefix` consults `allowlists.booleanPrefixes`). Surfaced in the
226
- * `list-rules --format=json` payload and the per-rule remediation text so operators don't
227
- * have to grep `.gruff-ts.yaml` and `src/config.ts` to find the override knob.
228
- */
377
+ /** Allowlist keys shown to users for this rule; missing means the rule has no allowlist control. */
229
378
  allowlistKeys?: readonly string[];
230
379
  fixtureExemption?: string;
380
+ /** Reviewed false-positive guidance; missing means no shape has been reviewed for this rule. */
381
+ falsePositiveShapes?: readonly FalsePositiveShape[];
231
382
  }
package/tsconfig.json CHANGED
@@ -9,7 +9,8 @@
9
9
  "skipLibCheck": true,
10
10
  "noUncheckedIndexedAccess": true,
11
11
  "exactOptionalPropertyTypes": true,
12
- "allowImportingTsExtensions": true
12
+ "allowImportingTsExtensions": true,
13
+ "types": ["node"]
13
14
  },
14
15
  "include": ["src/**/*.ts"]
15
16
  }