@blundergoat/gruff-ts 0.5.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.
- package/CHANGELOG.md +82 -0
- package/CONTRIBUTING.md +32 -25
- package/README.md +49 -50
- package/SECURITY.md +18 -31
- package/UPGRADING.md +101 -0
- package/bin/gruff-ts +3 -0
- package/docs/README.md +11 -10
- package/docs/agent-hook.md +32 -35
- package/docs/ci-integration.md +38 -24
- package/docs/configuration.md +160 -89
- package/docs/dashboard.md +12 -13
- package/docs/output-formats.md +100 -25
- package/docs/philosophy.md +2 -2
- package/docs/reports-and-ci.md +14 -172
- package/docs/rules.md +126 -98
- package/package.json +10 -8
- package/src/analyser.ts +817 -323
- package/src/baseline-file.ts +867 -0
- package/src/baseline-identity.ts +463 -0
- package/src/baseline-options.ts +139 -34
- package/src/baseline.ts +62 -68
- package/src/blocks.ts +512 -336
- package/src/changed-regions.ts +380 -79
- package/src/check-ignore.ts +28 -13
- package/src/class-rules.ts +445 -436
- package/src/cli-program.ts +915 -172
- package/src/cli.ts +9 -3
- package/src/comment-rules.ts +236 -418
- package/src/comment-scanner.ts +339 -47
- package/src/complexity-metrics.ts +111 -35
- package/src/config-load-error.ts +17 -8
- package/src/config-parse.ts +291 -98
- package/src/config-preservation.ts +81 -26
- package/src/config.ts +751 -223
- package/src/constants.ts +7 -6
- package/src/context-doc-rules.ts +182 -54
- package/src/dashboard.ts +88 -23
- package/src/dead-code-rules.ts +153 -74
- package/src/discovery.ts +493 -140
- package/src/doc-rules.ts +602 -126
- package/src/duplicate-test-group-rules.ts +359 -0
- package/src/findings-helpers.ts +134 -109
- package/src/findings.ts +47 -27
- package/src/fixture-purpose-rules.ts +194 -50
- package/src/github-actions-event-guards.ts +331 -0
- package/src/github-actions-rules.ts +328 -121
- package/src/hook-contract.ts +681 -255
- package/src/init-config.ts +163 -118
- package/src/inline-suppressions.ts +340 -0
- package/src/limit-band.ts +56 -0
- package/src/line-rules.ts +331 -468
- package/src/migrate-config.ts +670 -0
- package/src/naming-pushers.ts +32 -127
- package/src/parsed-script.ts +868 -314
- package/src/pillar-summary.ts +56 -40
- package/src/profiles.ts +86 -74
- package/src/project-config-rules.ts +324 -140
- package/src/project-rules.ts +237 -115
- package/src/public-exports.ts +102 -38
- package/src/report-html.ts +217 -85
- package/src/report-renderers.ts +821 -203
- package/src/rule-list.ts +166 -46
- package/src/rules.ts +100 -104
- package/src/safety-rules.ts +191 -132
- package/src/scoring.ts +249 -55
- package/src/security-flow-rules.ts +791 -115
- package/src/selectors.ts +169 -0
- package/src/sensitive-data-rules.ts +460 -387
- package/src/sensitive-exclusions.ts +435 -0
- package/src/source-text.ts +378 -104
- package/src/static-analysis-redundant-rules.ts +298 -41
- package/src/test-block-rules.ts +343 -253
- package/src/text-scans.ts +62 -11
- package/src/types.ts +220 -71
- package/tsconfig.json +2 -1
- package/src/process-exec-metadata.ts +0 -163
- package/src/test-fixtures.ts +0 -671
package/src/text-scans.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
-
|
|
18
|
-
|
|
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
|
-
|
|
24
|
-
|
|
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
|
-
|
|
30
|
-
|
|
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,11 +60,41 @@ function byteLine(source: string, index: number): number {
|
|
|
39
60
|
return line;
|
|
40
61
|
}
|
|
41
62
|
|
|
42
|
-
|
|
43
|
-
|
|
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
|
+
*/
|
|
44
71
|
function byteColumn(source: string, index: number): number {
|
|
45
72
|
const end = Math.max(0, index);
|
|
46
73
|
return end - source.lastIndexOf("\n", end - 1);
|
|
47
74
|
}
|
|
48
75
|
|
|
49
|
-
|
|
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
|
-
/**
|
|
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,55 +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
|
-
/**
|
|
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
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
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
115
|
acceptedClassFilePairs: Set<string>;
|
|
76
|
-
acceptedCasingPairs: Set<string>;
|
|
77
|
-
booleanPrefixes: Set<string>;
|
|
78
|
-
hungarianPrefixes: Set<string>;
|
|
79
116
|
placeholderNames: Set<string>;
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Per-command default for `--fail-on`. Precedence: CLI flag > this map > binary default.
|
|
84
|
-
* `dashboard` is intentionally not a valid key (no `--fail-on` flag exists for it); the parser
|
|
85
|
-
* rejects `dashboard` with a documented error. See ADR-004.
|
|
86
|
-
*/
|
|
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). */
|
|
87
120
|
minimumSeverity: Map<MinimumSeverityCommand, FailThreshold>;
|
|
88
|
-
|
|
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;
|
|
89
141
|
}
|
|
90
142
|
|
|
91
143
|
/**
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
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.
|
|
95
175
|
*/
|
|
96
176
|
export interface ProfileRuleSetting {
|
|
97
177
|
enabled?: boolean;
|
|
98
178
|
threshold?: number;
|
|
99
179
|
severity?: Severity;
|
|
100
|
-
options?: Map<string, number>;
|
|
180
|
+
options?: Map<string, number | boolean>;
|
|
101
181
|
}
|
|
102
182
|
|
|
103
183
|
/**
|
|
@@ -107,9 +187,9 @@ export interface ProfileRuleSetting {
|
|
|
107
187
|
export type ProfileSpec = string | InlineProfileSpec;
|
|
108
188
|
|
|
109
189
|
/**
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
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.
|
|
113
193
|
*/
|
|
114
194
|
export interface InlineProfileSpec {
|
|
115
195
|
extends?: string;
|
|
@@ -118,9 +198,9 @@ export interface InlineProfileSpec {
|
|
|
118
198
|
}
|
|
119
199
|
|
|
120
200
|
/**
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
* rules
|
|
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.
|
|
124
204
|
*/
|
|
125
205
|
export interface ProfileDefinition {
|
|
126
206
|
name: string;
|
|
@@ -128,7 +208,11 @@ export interface ProfileDefinition {
|
|
|
128
208
|
ignoredPaths: string[];
|
|
129
209
|
}
|
|
130
210
|
|
|
131
|
-
/**
|
|
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
|
+
*/
|
|
132
216
|
export interface Finding {
|
|
133
217
|
ruleId: string;
|
|
134
218
|
message: string;
|
|
@@ -146,25 +230,44 @@ export interface Finding {
|
|
|
146
230
|
metadata: Record<string, unknown>;
|
|
147
231
|
fingerprint: string;
|
|
148
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;
|
|
149
243
|
}
|
|
150
244
|
|
|
151
|
-
/**
|
|
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
|
+
*/
|
|
152
250
|
export interface RunDiagnostic {
|
|
153
251
|
diagnosticType: string;
|
|
154
252
|
message: string;
|
|
155
253
|
filePath?: string;
|
|
156
254
|
line?: number;
|
|
255
|
+
/** False marks a visible diagnostic that must not change an otherwise-successful exit status. */
|
|
256
|
+
invalidatesRun?: false;
|
|
157
257
|
}
|
|
158
258
|
|
|
159
259
|
/**
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
*
|
|
163
|
-
* 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).
|
|
164
263
|
*/
|
|
165
264
|
export type IgnoreSource = "config" | "gitignore" | "default";
|
|
166
265
|
|
|
167
|
-
/**
|
|
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
|
+
*/
|
|
168
271
|
export interface SkippedPath {
|
|
169
272
|
path: string;
|
|
170
273
|
source: IgnoreSource;
|
|
@@ -172,11 +275,9 @@ export interface SkippedPath {
|
|
|
172
275
|
}
|
|
173
276
|
|
|
174
277
|
/**
|
|
175
|
-
*
|
|
176
|
-
*
|
|
177
|
-
*
|
|
178
|
-
* budget (`bounded-deep-scan`), or bytes that are not parseable text (`non-text-file`). Notes never
|
|
179
|
-
* affect exit codes; `diagnostics` stays the surface 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.
|
|
180
281
|
*/
|
|
181
282
|
export interface ScanSurfaceNote {
|
|
182
283
|
noteType: "no-analysable-files" | "bounded-deep-scan" | "non-text-file";
|
|
@@ -185,33 +286,83 @@ export interface ScanSurfaceNote {
|
|
|
185
286
|
}
|
|
186
287
|
|
|
187
288
|
/**
|
|
188
|
-
*
|
|
289
|
+
* Native analysis state consumed by CLI renderers, HTML/dashboard views, and the coding-agent hook.
|
|
189
290
|
*
|
|
190
|
-
*
|
|
191
|
-
* `path`, the ignore `source`, and the matching `pattern`. `paths.ignoredPaths` is retained as the
|
|
192
|
-
* 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`.
|
|
193
292
|
*/
|
|
194
293
|
export interface AnalysisReport {
|
|
195
|
-
schemaVersion: "gruff.analysis.
|
|
294
|
+
schemaVersion: "gruff.analysis.v3";
|
|
196
295
|
tool: { name: "gruff-ts"; version: string };
|
|
197
|
-
run: {
|
|
296
|
+
run: {
|
|
297
|
+
projectRoot: string;
|
|
298
|
+
format: OutputFormat;
|
|
299
|
+
failOn: FailThreshold;
|
|
300
|
+
generatedAt: string;
|
|
301
|
+
inputs?: string[];
|
|
302
|
+
config?: string;
|
|
303
|
+
includeIgnored?: true;
|
|
304
|
+
};
|
|
198
305
|
summary: { advisory: number; warning: number; error: number; total: number };
|
|
199
306
|
paths: { analysedFiles: number; ignoredPaths: string[]; skipped: SkippedPath[]; missingPaths: string[] };
|
|
200
307
|
diagnostics: RunDiagnostic[];
|
|
201
|
-
/**
|
|
308
|
+
/** Missing means the scan produced no non-fatal surface notes. */
|
|
202
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[];
|
|
203
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[];
|
|
204
316
|
suppressedCount?: number;
|
|
205
317
|
score: {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
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;
|
|
210
347
|
};
|
|
211
|
-
baseline?: { path: string; source: string; suppressed: number; generated: boolean };
|
|
212
348
|
}
|
|
213
349
|
|
|
214
|
-
/**
|
|
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
|
+
*/
|
|
215
366
|
export interface RuleDescriptor {
|
|
216
367
|
ruleId: string;
|
|
217
368
|
pillar: Pillar;
|
|
@@ -219,15 +370,13 @@ export interface RuleDescriptor {
|
|
|
219
370
|
confidence: Confidence;
|
|
220
371
|
description: string;
|
|
221
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;
|
|
222
375
|
threshold?: number;
|
|
223
376
|
optionKeys?: readonly string[];
|
|
224
|
-
/**
|
|
225
|
-
* Names of `allowlists.*` keys in `.gruff-ts.yaml` that override or extend the rule's
|
|
226
|
-
* behaviour. Mirrors the `optionKeys` shape but targets the cross-pillar allowlist surface
|
|
227
|
-
* (e.g. `naming.boolean-prefix` consults `allowlists.booleanPrefixes`). Surfaced in the
|
|
228
|
-
* `list-rules --format=json` payload and the per-rule remediation text so operators don't
|
|
229
|
-
* have to grep `.gruff-ts.yaml` and `src/config.ts` to find the override knob.
|
|
230
|
-
*/
|
|
377
|
+
/** Allowlist keys shown to users for this rule; missing means the rule has no allowlist control. */
|
|
231
378
|
allowlistKeys?: readonly string[];
|
|
232
379
|
fixtureExemption?: string;
|
|
380
|
+
/** Reviewed false-positive guidance; missing means no shape has been reviewed for this rule. */
|
|
381
|
+
falsePositiveShapes?: readonly FalsePositiveShape[];
|
|
233
382
|
}
|
package/tsconfig.json
CHANGED