@blundergoat/gruff-ts 0.1.1 → 0.3.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 +55 -19
- package/README.md +103 -35
- package/docs/README.md +2 -0
- package/docs/agent-hook.md +80 -0
- package/docs/ci-integration.md +16 -0
- package/docs/configuration.md +60 -3
- package/docs/dashboard.md +7 -0
- package/docs/output-formats.md +11 -1
- package/docs/philosophy.md +21 -0
- package/docs/releasing.md +12 -11
- package/docs/reports-and-ci.md +5 -2
- package/docs/rules.md +24 -15
- package/package.json +5 -5
- package/scripts/bump-version.sh +20 -4
- package/scripts/preflight-checks.sh +4 -41
- package/src/analyser.ts +47 -34
- package/src/blocks.ts +82 -75
- package/src/changed-regions.ts +390 -0
- package/src/check-ignore.ts +49 -0
- package/src/class-rules.ts +80 -33
- package/src/cli-program.ts +209 -51
- package/src/comment-rules.ts +4 -0
- package/src/config-load-error.ts +18 -0
- package/src/config-parse.ts +458 -0
- package/src/config-preservation.ts +64 -0
- package/src/config.ts +311 -428
- package/src/constants.ts +10 -2
- package/src/context-doc-rules.ts +2 -4
- package/src/dashboard.ts +8 -5
- package/src/dead-code-rules.ts +60 -14
- package/src/discovery.ts +88 -32
- package/src/doc-rules.ts +3 -3
- package/src/findings-helpers.ts +58 -5
- package/src/fixtures/rule-catalogue-security-doctrine.ts +28 -0
- package/src/init-config.ts +94 -31
- package/src/line-rules.ts +58 -4
- package/src/naming-pushers.ts +42 -7
- package/src/pillar-summary.ts +129 -0
- package/src/profiles.ts +232 -0
- package/src/project-config-rules.ts +5 -5
- package/src/project-rules.ts +2 -1
- package/src/report-html.ts +404 -0
- package/src/report-renderers.ts +210 -397
- package/src/rule-list.ts +85 -1
- package/src/rules.ts +28 -27
- package/src/safety-rules.ts +22 -7
- package/src/scoring.ts +78 -8
- package/src/security-flow-rules.ts +533 -0
- package/src/sensitive-data-rules.ts +138 -2
- package/src/test-block-rules.ts +140 -7
- package/src/test-fixtures.ts +59 -13
- package/src/types.ts +108 -5
package/src/rule-list.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// Console command catalogue, shell completion scripts, and rule-list renderers for CLI surfaces.
|
|
2
2
|
import { VERSION } from "./constants.ts";
|
|
3
|
+
import { profileSummaries, type ProfileSummary } from "./profiles.ts";
|
|
3
4
|
import { ruleDescriptors } from "./rules.ts";
|
|
5
|
+
import type { RuleDescriptor } from "./types.ts";
|
|
4
6
|
|
|
5
7
|
type RuleListFormat = "text" | "json";
|
|
6
8
|
type CompletionShell = "bash" | "fish" | "zsh";
|
|
@@ -23,6 +25,7 @@ const CONSOLE_COMMANDS = [
|
|
|
23
25
|
{ name: "help", description: "Display help for a command" },
|
|
24
26
|
{ name: "init", description: "Write the default .gruff-ts.yaml to the current directory." },
|
|
25
27
|
{ name: "list", description: "List commands" },
|
|
28
|
+
{ name: "list-profiles", description: "List the built-in gruff profiles." },
|
|
26
29
|
{ name: "list-rules", description: "List gruff rule metadata." },
|
|
27
30
|
{ name: "report", description: "Render a gruff report to stdout or a file." },
|
|
28
31
|
{
|
|
@@ -48,6 +51,87 @@ function renderRuleList(format: RuleListFormat): string {
|
|
|
48
51
|
return `${lines.join("\n")}\n`;
|
|
49
52
|
}
|
|
50
53
|
|
|
54
|
+
// Profile catalogue renderer. Mirrors renderRuleList: JSON is the integration surface for docs and
|
|
55
|
+
// audits, and row formatting lives in profileListRow. The text form is kept deliberately plain
|
|
56
|
+
// because it is only for terminal inspection and should not become a second schema.
|
|
57
|
+
function renderProfileList(format: RuleListFormat): string {
|
|
58
|
+
const summaries = profileSummaries();
|
|
59
|
+
if (format === "json") {
|
|
60
|
+
return `${JSON.stringify({ tool: { name: "gruff-ts", version: VERSION }, profiles: summaries }, null, 2)}\n`;
|
|
61
|
+
}
|
|
62
|
+
const header = ["gruff-ts " + VERSION + ` profiles (${summaries.length})`, ""];
|
|
63
|
+
return `${[...header, ...summaries.map(profileListRow)].join("\n")}\n`;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// One text row per profile: name, enabled/total rule count, pillar count, an optional tightened-threshold
|
|
67
|
+
// count, and the description. The tightened-threshold segment only appears for presets that set one.
|
|
68
|
+
function profileListRow(summary: ProfileSummary): string {
|
|
69
|
+
const tightened = summary.tightenedThresholdCount > 0 ? ` | tightened thresholds: ${summary.tightenedThresholdCount}` : "";
|
|
70
|
+
return `${summary.name} | ${summary.enabledRuleCount}/${summary.totalRuleCount} rules | ${summary.enabledPillars.length} pillars${tightened} | ${summary.description}`;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/*
|
|
74
|
+
* Returns a single rule descriptor by ID, or undefined when the ID is not registered. Surfaced so
|
|
75
|
+
* the explain-mode renderer can dispatch on "is this a real rule?" without iterating the full
|
|
76
|
+
* catalogue at each render site. Stable contract: lookup keys match the public rule ID strings
|
|
77
|
+
* exactly; partial / case-insensitive matches are intentionally out of scope.
|
|
78
|
+
*/
|
|
79
|
+
function getRuleDescriptor(ruleId: string): RuleDescriptor | undefined {
|
|
80
|
+
return ruleDescriptors().find((descriptor) => descriptor.ruleId === ruleId);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/*
|
|
84
|
+
* Single-rule detail renderer. Text format prints a labelled section with every populated field;
|
|
85
|
+
* JSON format wraps the descriptor in a tool envelope mirroring the multi-rule shape. Surfaces
|
|
86
|
+
* config keys (`rules.<ruleId>.{enabled,severity,threshold}`) and the option/allowlist hatches
|
|
87
|
+
* because operators looking up one rule shouldn't have to grep `src/config.ts` to find the
|
|
88
|
+
* override knobs they're about to tune.
|
|
89
|
+
*/
|
|
90
|
+
function renderRuleDetail(descriptor: RuleDescriptor, format: RuleListFormat): string {
|
|
91
|
+
if (format === "json") {
|
|
92
|
+
return `${JSON.stringify({ tool: { name: "gruff-ts", version: VERSION }, rule: { ...descriptor, configKeys: ruleConfigKeys(descriptor) } }, null, 2)}\n`;
|
|
93
|
+
}
|
|
94
|
+
const lines = [
|
|
95
|
+
`Rule: ${descriptor.ruleId}`,
|
|
96
|
+
`Pillar: ${descriptor.pillar}`,
|
|
97
|
+
`Severity: ${descriptor.severity}`,
|
|
98
|
+
`Confidence: ${descriptor.confidence}`,
|
|
99
|
+
...(typeof descriptor.threshold === "number" ? [`Threshold: ${descriptor.threshold}`] : []),
|
|
100
|
+
"",
|
|
101
|
+
`Description: ${descriptor.description}`,
|
|
102
|
+
"",
|
|
103
|
+
`Remediation: ${descriptor.remediation}`,
|
|
104
|
+
"",
|
|
105
|
+
...ruleConfigKeyLines(descriptor),
|
|
106
|
+
...(descriptor.optionKeys && descriptor.optionKeys.length > 0 ? ["", "Options:", ...descriptor.optionKeys.map((key) => ` rules.${descriptor.ruleId}.options.${key}`)] : []),
|
|
107
|
+
...(descriptor.allowlistKeys && descriptor.allowlistKeys.length > 0 ? ["", "Allowlists:", ...descriptor.allowlistKeys.map((key) => ` allowlists.${key}`)] : []),
|
|
108
|
+
];
|
|
109
|
+
return `${lines.join("\n")}\n`;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Three baseline config-key entries shared by every rule: the enable toggle, the severity override,
|
|
113
|
+
// and (when present) the threshold override. Optional knobs (options / allowlists) get their own
|
|
114
|
+
// blocks in `renderRuleDetail` to keep this list focused on the always-applicable keys.
|
|
115
|
+
function ruleConfigKeyLines(descriptor: RuleDescriptor): string[] {
|
|
116
|
+
return [
|
|
117
|
+
"Config keys:",
|
|
118
|
+
` rules.${descriptor.ruleId}.enabled (bool)`,
|
|
119
|
+
` rules.${descriptor.ruleId}.severity (advisory|warning|error)`,
|
|
120
|
+
...(typeof descriptor.threshold === "number" ? [` rules.${descriptor.ruleId}.threshold (int, default: ${descriptor.threshold})`] : []),
|
|
121
|
+
];
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// JSON representation of the same config-key list. Returned as a structured array so JSON consumers
|
|
125
|
+
// don't have to re-derive the shape from the text layout. Each entry carries the key path, the
|
|
126
|
+
// value's type vocabulary, and a default when one is known.
|
|
127
|
+
function ruleConfigKeys(descriptor: RuleDescriptor): Array<{ key: string; type: string; values?: readonly string[]; default?: number | boolean | string }> {
|
|
128
|
+
return [
|
|
129
|
+
{ key: `rules.${descriptor.ruleId}.enabled`, type: "bool", default: true },
|
|
130
|
+
{ key: `rules.${descriptor.ruleId}.severity`, type: "enum", values: ["advisory", "warning", "error"] as const, default: descriptor.severity },
|
|
131
|
+
...(typeof descriptor.threshold === "number" ? [{ key: `rules.${descriptor.ruleId}.threshold`, type: "int", default: descriptor.threshold }] : []),
|
|
132
|
+
];
|
|
133
|
+
}
|
|
134
|
+
|
|
51
135
|
// The Symfony-style command catalogue shown for `gruff-ts`, `gruff-ts list`, and `gruff-ts help`.
|
|
52
136
|
// `shouldUseAnsi` is autodetected by the caller from TTY and `--ansi` flags, never from this layer.
|
|
53
137
|
function renderConsoleList(shouldUseAnsi = false): string {
|
|
@@ -177,4 +261,4 @@ function completionShell(shellName: unknown): CompletionShell {
|
|
|
177
261
|
}
|
|
178
262
|
|
|
179
263
|
export type { RuleListFormat, CompletionShell };
|
|
180
|
-
export { renderRuleList, renderConsoleList, renderCompletionScript, completionShell };
|
|
264
|
+
export { renderRuleList, renderProfileList, renderRuleDetail, getRuleDescriptor, renderConsoleList, renderCompletionScript, completionShell };
|
package/src/rules.ts
CHANGED
|
@@ -2,21 +2,19 @@
|
|
|
2
2
|
import type { RuleDescriptor } from "./types.ts";
|
|
3
3
|
|
|
4
4
|
const RULE_DESCRIPTORS: readonly RuleDescriptor[] = [
|
|
5
|
-
{ ruleId: "complexity.cognitive", pillar: "complexity", severity: "warning", confidence: "high", description: "Flags functions with high combined branch and nesting complexity.", remediation: "Split nested decisions into smaller named functions.", threshold: 15 },
|
|
6
|
-
{ ruleId: "complexity.cyclomatic", pillar: "complexity", severity: "warning", confidence: "high", description: "Flags functions with many independent branch paths.", remediation: "Reduce branching or move policy tables out of imperative code.", threshold: 15 },
|
|
7
|
-
{ ruleId: "complexity.npath", pillar: "complexity", severity: "warning", confidence: "medium", description: "Flags functions with high approximate NPath complexity.", remediation: "Break apart compound branch combinations.", threshold: 200 },
|
|
8
|
-
{ ruleId: "dead-code.unused-private-method", pillar: "dead-code", severity: "advisory", confidence: "low", description: "Flags private methods without an apparent same-file call site.", remediation: "Remove the method or add a direct call site." },
|
|
5
|
+
{ ruleId: "complexity.cognitive", pillar: "complexity", severity: "warning", confidence: "high", description: "Flags functions with high combined branch and nesting complexity.", remediation: "Split nested decisions into smaller named functions. Or raise rules.complexity.cognitive.threshold in .gruff-ts.yaml if the bound is wrong for this project.", threshold: 15 },
|
|
6
|
+
{ ruleId: "complexity.cyclomatic", pillar: "complexity", severity: "warning", confidence: "high", description: "Flags functions with many independent branch paths.", remediation: "Reduce branching or move policy tables out of imperative code. Or raise rules.complexity.cyclomatic.threshold in .gruff-ts.yaml if the bound is wrong for this project.", threshold: 15 }, { ruleId: "dead-code.unused-private-method", pillar: "dead-code", severity: "advisory", confidence: "low", description: "Flags private methods without an apparent same-file call site.", remediation: "Remove the method or add a direct call site." },
|
|
9
7
|
{ ruleId: "design.circular-import", pillar: "design", severity: "warning", confidence: "medium", description: "Flags simple relative import cycles inside the discovered source set.", remediation: "Extract the shared contract or invert one dependency." },
|
|
10
|
-
{ ruleId: "design.deep-relative-import", pillar: "design", severity: "advisory", confidence: "medium", description: "Flags relative imports that climb too many parent directories.", remediation: "Move the shared module closer or add a local boundary.", threshold: 2 },
|
|
11
|
-
{ ruleId: "design.
|
|
12
|
-
{ ruleId: "design.large-module-concentration", pillar: "design", severity: "advisory", confidence: "medium", description: "Flags a production module that dominates project source lines.", remediation: "Split unrelated responsibilities once stable seams are visible.", threshold: 55, optionKeys: ["minFiles", "minLines"] },
|
|
8
|
+
{ ruleId: "design.deep-relative-import", pillar: "design", severity: "advisory", confidence: "medium", description: "Flags relative imports that climb too many parent directories.", remediation: "Move the shared module closer or add a local boundary. Or raise rules.design.deep-relative-import.threshold in .gruff-ts.yaml if the bound is wrong for this project.", threshold: 2 },
|
|
9
|
+
{ ruleId: "design.large-module-concentration", pillar: "design", severity: "advisory", confidence: "medium", description: "Flags a production module that dominates project source lines.", remediation: "Split unrelated responsibilities once stable seams are visible. Or raise rules.design.large-module-concentration.threshold or tune minFiles, minLines under rules.design.large-module-concentration.options.", threshold: 55, optionKeys: ["minFiles", "minLines"] },
|
|
13
10
|
{ ruleId: "design.package-bin-missing", pillar: "design", severity: "warning", confidence: "high", description: "Flags package bin entries that point at missing files.", remediation: "Update the bin path or add the executable file." },
|
|
14
11
|
{ ruleId: "design.package-bin-not-executable", pillar: "design", severity: "warning", confidence: "high", description: "Flags package bin targets that are not executable.", remediation: "Make the bin target executable and keep its shebang valid." },
|
|
15
12
|
{ ruleId: "docs.fixture-purpose-missing", pillar: "documentation", severity: "advisory", confidence: "medium", description: "Flags large or scanner-relevant fixtures without a nearby purpose comment.", remediation: "Explain what scanner path, regression, or fixture behavior the source covers." },
|
|
16
13
|
{ ruleId: "docs.magic-threshold-without-rationale", pillar: "documentation", severity: "advisory", confidence: "medium", description: "Flags threshold-like numeric values without a nearby rationale comment.", remediation: "Explain the threshold, limit, budget, or default near the value." },
|
|
17
14
|
{ ruleId: "docs.missing-error-behavior-doc", pillar: "documentation", severity: "advisory", confidence: "medium", description: "Flags commented functions whose error behavior is not described.", remediation: "Document thrown errors, diagnostics, exits, reports, or recovery behavior." },
|
|
15
|
+
{ ruleId: "docs.missing-exported-function-doc", pillar: "documentation", severity: "warning", confidence: "medium", description: "Flags exported functions without a leading maintainer comment.", remediation: "Add a JSDoc or line comment explaining the exported API's contract, since public surface has a higher cost of omission." },
|
|
18
16
|
{ ruleId: "docs.missing-file-overview", pillar: "documentation", severity: "advisory", confidence: "medium", description: "Flags source files without a top-of-file purpose comment.", remediation: "Add a brief file overview before imports or declarations." },
|
|
19
|
-
{ ruleId: "docs.missing-function-doc", pillar: "documentation", severity: "advisory", confidence: "medium", description: "Flags functions without a leading maintainer comment.", remediation: "Add a short
|
|
17
|
+
{ ruleId: "docs.missing-internal-function-doc", pillar: "documentation", severity: "advisory", confidence: "medium", description: "Flags internal helper functions without a leading maintainer comment.", remediation: "Add a short comment explaining the helper's role; internal helpers are advisory, exported surface fires the warning variant." },
|
|
20
18
|
{ ruleId: "docs.missing-interface-doc", pillar: "documentation", severity: "advisory", confidence: "medium", description: "Flags interfaces without a leading maintainer comment.", remediation: "Add a short JSDoc or line comment explaining the interface contract." },
|
|
21
19
|
{ ruleId: "docs.missing-invariant-doc", pillar: "documentation", severity: "advisory", confidence: "medium", description: "Flags commented declarations that own schema, fingerprint, baseline, or determinism contracts without saying so.", remediation: "Document the invariant, contract, schema, fingerprint, or deterministic behavior." },
|
|
22
20
|
{ ruleId: "docs.missing-param-tag", pillar: "documentation", severity: "advisory", confidence: "medium", description: "Flags documented exports with parameters missing @param tags.", remediation: "Document every current parameter in the JSDoc." },
|
|
@@ -43,16 +41,16 @@ const RULE_DESCRIPTORS: readonly RuleDescriptor[] = [
|
|
|
43
41
|
{ ruleId: "modernisation.tsconfig-index-safety-disabled", pillar: "modernisation", severity: "warning", confidence: "high", description: "Flags tsconfig files without noUncheckedIndexedAccess enabled.", remediation: "Enable noUncheckedIndexedAccess unless migration is blocked." },
|
|
44
42
|
{ ruleId: "modernisation.tsconfig-strict-disabled", pillar: "modernisation", severity: "warning", confidence: "high", description: "Flags tsconfig files without strict mode enabled.", remediation: "Enable strict unless migration is blocked." },
|
|
45
43
|
{ ruleId: "modernisation.var-declaration", pillar: "modernisation", severity: "advisory", confidence: "high", description: "Flags var declarations.", remediation: "Use let or const with the narrowest useful scope." },
|
|
46
|
-
{ ruleId: "naming.acronym-case", pillar: "naming", severity: "advisory", confidence: "medium", description: "Flags mixed casings of a known acronym in one file.", remediation: "Use one casing for each acronym throughout the file." },
|
|
47
|
-
{ ruleId: "naming.boolean-prefix", pillar: "naming", severity: "advisory", confidence: "medium", description: "Flags boolean names without intent-revealing prefixes on declarations, function parameters (typed `: boolean` or with `= true|false` default), and interface/type-literal fields.", remediation: "Use prefixes such as is, has, can, should, or will." },
|
|
44
|
+
{ ruleId: "naming.acronym-case", pillar: "naming", severity: "advisory", confidence: "medium", description: "Flags mixed casings of a known acronym in one file.", remediation: "Use one casing for each acronym throughout the file. Or extend allowlists.knownAcronyms with project-specific values.", allowlistKeys: ["knownAcronyms"] },
|
|
45
|
+
{ ruleId: "naming.boolean-prefix", pillar: "naming", severity: "advisory", confidence: "medium", description: "Flags boolean names without intent-revealing prefixes on declarations, function parameters (typed `: boolean` or with `= true|false` default), and interface/type-literal fields.", remediation: "Use prefixes such as is, has, can, should, or will. Or extend allowlists.booleanPrefixes / allowlists.acceptedBooleanNames for project-specific contract names.", allowlistKeys: ["booleanPrefixes", "acceptedBooleanNames"] },
|
|
48
46
|
{ ruleId: "naming.class-file-mismatch", pillar: "naming", severity: "advisory", confidence: "medium", description: "Flags exported classes whose name differs from the file name.", remediation: "Rename the class or file so the primary export is easy to locate." },
|
|
49
|
-
{ ruleId: "naming.generic-function", pillar: "naming", severity: "advisory", confidence: "high", description: "Flags generic function names that hide intent.", remediation: "Name the domain action instead of a generic operation." },
|
|
50
|
-
{ ruleId: "naming.generic-parameter", pillar: "naming", severity: "advisory", confidence: "medium", description: "Flags placeholder parameter names in multi-parameter, long, exported, or complex functions.", remediation: "Use a name that describes the parameter's role.", optionKeys: ["minCyclomatic", "minLineCount", "minParameters"] },
|
|
51
|
-
{ ruleId: "naming.hungarian-notation", pillar: "naming", severity: "advisory", confidence: "medium", description: "Flags identifiers named after storage type prefixes.", remediation: "Name the domain concept instead of the storage type." },
|
|
52
|
-
{ ruleId: "naming.identifier-quality", pillar: "naming", severity: "advisory", confidence: "medium", description: "Flags placeholder or numbered identifiers on declarations, function parameters, and destructured locals.", remediation: "Use names that explain domain role or intent." },
|
|
47
|
+
{ ruleId: "naming.generic-function", pillar: "naming", severity: "advisory", confidence: "high", description: "Flags generic function names that hide intent.", remediation: "Name the domain action instead of a generic operation. Or remove the name from allowlists.bannedGenericNames if your project does not consider it generic.", allowlistKeys: ["bannedGenericNames"] },
|
|
48
|
+
{ ruleId: "naming.generic-parameter", pillar: "naming", severity: "advisory", confidence: "medium", description: "Flags placeholder parameter names in multi-parameter, long, exported, or complex functions.", remediation: "Use a name that describes the parameter's role. Or tune minCyclomatic, minLineCount, minParameters under rules.naming.generic-parameter.options.", optionKeys: ["minCyclomatic", "minLineCount", "minParameters"] },
|
|
49
|
+
{ ruleId: "naming.hungarian-notation", pillar: "naming", severity: "advisory", confidence: "medium", description: "Flags identifiers named after storage type prefixes.", remediation: "Name the domain concept instead of the storage type. Or remove the prefix from allowlists.hungarianPrefixes if your project does not consider it Hungarian-style.", allowlistKeys: ["hungarianPrefixes"] },
|
|
50
|
+
{ ruleId: "naming.identifier-quality", pillar: "naming", severity: "advisory", confidence: "medium", description: "Flags placeholder or numbered identifiers on declarations, function parameters, and destructured locals.", remediation: "Use names that explain domain role or intent. Or remove the name from allowlists.placeholderNames if your project considers it valid.", allowlistKeys: ["placeholderNames"] },
|
|
53
51
|
{ ruleId: "naming.inconsistent-casing", pillar: "naming", severity: "advisory", confidence: "medium", description: "Flags the same canonical identifier appearing in two different surface forms (for example CONSTANT_CASE and camelCase) in one file.", remediation: "Choose one form and use it consistently within the file." },
|
|
54
|
-
{ ruleId: "naming.negative-boolean", pillar: "naming", severity: "advisory", confidence: "medium", description: "Flags boolean identifiers framed as a negation on declarations, parameters, and interface fields.", remediation: "Invert the framing so callers do not read a double negation." },
|
|
55
|
-
{ ruleId: "naming.short-variable", pillar: "naming", severity: "advisory", confidence: "medium", description: "Flags very short variable names outside common loop counters; covers declarations, function parameters, and destructured locals.", remediation: "Use a name that describes the domain role." },
|
|
52
|
+
{ ruleId: "naming.negative-boolean", pillar: "naming", severity: "advisory", confidence: "medium", description: "Flags boolean identifiers framed as a negation on declarations, parameters, and interface fields.", remediation: "Invert the framing so callers do not read a double negation. Or extend allowlists.negativeBooleanAllowed with project-specific values.", allowlistKeys: ["negativeBooleanAllowed"] },
|
|
53
|
+
{ ruleId: "naming.short-variable", pillar: "naming", severity: "advisory", confidence: "medium", description: "Flags very short variable names outside common loop counters; covers declarations, function parameters, and destructured locals.", remediation: "Use a name that describes the domain role. Or extend allowlists.acceptedAbbreviations with project-specific values.", allowlistKeys: ["acceptedAbbreviations"] },
|
|
56
54
|
{ ruleId: "security.async-foreach", pillar: "security", severity: "warning", confidence: "medium", description: "Flags async callbacks passed to forEach.", remediation: "Use for...of with await, Promise.all, or an explicit queue." },
|
|
57
55
|
{ ruleId: "security.disabled-tls-verification", pillar: "security", severity: "error", confidence: "high", description: "Flags code that disables TLS certificate verification.", remediation: "Remove the override and fix certificate trust at the source." },
|
|
58
56
|
{ ruleId: "security.document-write", pillar: "security", severity: "warning", confidence: "high", description: "Flags document.write usage.", remediation: "Use safe DOM APIs and encode untrusted content." },
|
|
@@ -78,20 +76,23 @@ const RULE_DESCRIPTORS: readonly RuleDescriptor[] = [
|
|
|
78
76
|
{ ruleId: "security.ssrf-candidate", pillar: "security", severity: "warning", confidence: "medium", description: "Flags external input sent to network request sinks.", remediation: "Validate destinations against an allowlist and block internal hosts." },
|
|
79
77
|
{ ruleId: "security.string-timer", pillar: "security", severity: "warning", confidence: "high", description: "Flags string callbacks passed to timers.", remediation: "Pass a function callback instead of source text." },
|
|
80
78
|
{ ruleId: "security.throw-non-error", pillar: "security", severity: "warning", confidence: "medium", description: "Flags thrown non-Error values.", remediation: "Throw an Error subclass with a clear message." },
|
|
81
|
-
{ ruleId: "security.
|
|
79
|
+
{ ruleId: "security.unsafe-deserialization", pillar: "security", severity: "warning", confidence: "medium", description: "Flags external input reaching unsafe deserialization or dynamic code-loading sinks.", remediation: "Use schema-bound parsers or validate and decode data without executing code." },
|
|
80
|
+
{ ruleId: "security.url-dependency", pillar: "security", severity: "warning", confidence: "medium", description: "Flags dependencies installed from URL, git, or local file specs.", remediation: "Prefer registry versions that can be locked and audited." },
|
|
82
81
|
{ ruleId: "security.weak-crypto", pillar: "security", severity: "warning", confidence: "high", description: "Flags weak crypto primitives such as md5, sha1, or createCipher.", remediation: "Use modern algorithms and authenticated encryption." },
|
|
83
|
-
{ ruleId: "
|
|
82
|
+
{ ruleId: "security.xxe-candidate", pillar: "security", severity: "warning", confidence: "medium", description: "Flags external XML reaching parsers configured to expand entities.", remediation: "Disable external entity expansion and use hardened XML parser options." },
|
|
83
|
+
{ ruleId: "sensitive-data.api-key-pattern", pillar: "sensitive-data", severity: "error", confidence: "high", description: "Flags vendor API key patterns including GitHub, GitLab, npm, Google API, Slack, Discord, and Stripe/OpenAI-style keys.", remediation: "Remove the secret and load it from a secure runtime source." },
|
|
84
84
|
{ ruleId: "sensitive-data.aws-access-key", pillar: "sensitive-data", severity: "error", confidence: "high", description: "Flags AWS access key looking values.", remediation: "Remove the key and rotate it immediately." },
|
|
85
|
-
{ ruleId: "sensitive-data.database-url-password", pillar: "sensitive-data", severity: "error", confidence: "high", description: "Flags database URLs that include passwords.", remediation: "Move credentials into a secret store or runtime environment." },
|
|
86
|
-
{ ruleId: "sensitive-data.
|
|
87
|
-
{ ruleId: "sensitive-data.
|
|
85
|
+
{ ruleId: "sensitive-data.database-url-password", pillar: "sensitive-data", severity: "error", confidence: "high", description: "Flags database and HTTP(S) URLs that include passwords or embedded credentials.", remediation: "Move credentials into a secret store or runtime environment." },
|
|
86
|
+
{ ruleId: "sensitive-data.gcp-service-account-key", pillar: "sensitive-data", severity: "error", confidence: "high", description: "Flags GCP service-account key files (type service_account alongside a private key).", remediation: "Remove the service-account key from source and rotate it; load credentials from a secure runtime source." },
|
|
87
|
+
{ ruleId: "sensitive-data.hardcoded-env-value", pillar: "sensitive-data", severity: "error", confidence: "medium", description: "Flags environment-style secret values committed in text.", remediation: "Load secret-like values from secure runtime configuration. Or raise rules.sensitive-data.hardcoded-env-value.threshold in .gruff-ts.yaml if the bound is wrong for this project.", threshold: 16 },
|
|
88
|
+
{ ruleId: "sensitive-data.high-entropy-string", pillar: "sensitive-data", severity: "error", confidence: "medium", description: "Flags high-entropy string literals that may be secrets.", remediation: "Remove the value and load it from a secure runtime source. Or raise rules.sensitive-data.high-entropy-string.threshold in .gruff-ts.yaml if the bound is wrong for this project.", threshold: 32 },
|
|
88
89
|
{ ruleId: "sensitive-data.jwt-token", pillar: "sensitive-data", severity: "error", confidence: "high", description: "Flags JWT-looking token literals.", remediation: "Remove the token and rotate the credential if real." },
|
|
89
|
-
{ ruleId: "sensitive-data.
|
|
90
|
+
{ ruleId: "sensitive-data.phi-pattern", pillar: "sensitive-data", severity: "error", confidence: "high", description: "Flags PHI identifiers such as Medicare (MBI) and medical record numbers.", remediation: "Remove protected health information from source and fixtures." },
|
|
91
|
+
{ ruleId: "sensitive-data.pii-pattern", pillar: "sensitive-data", severity: "error", confidence: "high", description: "Flags PII-like identifier patterns including SSN-shaped values and Luhn-valid payment cards.", remediation: "Remove personal data from source and fixtures." },
|
|
90
92
|
{ ruleId: "sensitive-data.private-key", pillar: "sensitive-data", severity: "error", confidence: "high", description: "Flags private key block markers.", remediation: "Remove the key material and rotate affected credentials." },
|
|
91
|
-
{ ruleId: "size.file-length", pillar: "size", severity: "warning", confidence: "high", description: "Flags files longer than the configured threshold.", remediation: "Split unrelated responsibilities into smaller files.", threshold: 750 },
|
|
92
|
-
{ ruleId: "size.function-length", pillar: "size", severity: "warning", confidence: "high", description: "Flags functions longer than the configured threshold.", remediation: "Extract named helpers or split workflows.", threshold: 200 },
|
|
93
|
-
{ ruleId: "size.parameter-count", pillar: "size", severity: "warning", confidence: "high", description: "Flags functions with too many parameters.", remediation: "Group related options or reduce the function's responsibility.", threshold: 7 },
|
|
94
|
-
{ ruleId: "size.stylesheet-length", pillar: "size", severity: "warning", confidence: "high", description: "Flags stylesheets longer than the configured threshold.", remediation: "Split unrelated component styles into smaller files.", threshold: 1500 },
|
|
93
|
+
{ ruleId: "size.file-length", pillar: "size", severity: "warning", confidence: "high", description: "Flags files longer than the configured threshold.", remediation: "Split unrelated responsibilities into smaller files. Or raise rules.size.file-length.threshold in .gruff-ts.yaml if the bound is wrong for this project.", threshold: 750 },
|
|
94
|
+
{ ruleId: "size.function-length", pillar: "size", severity: "warning", confidence: "high", description: "Flags functions longer than the configured threshold.", remediation: "Extract named helpers or split workflows. Or raise rules.size.function-length.threshold in .gruff-ts.yaml if the bound is wrong for this project.", threshold: 200 },
|
|
95
|
+
{ ruleId: "size.parameter-count", pillar: "size", severity: "warning", confidence: "high", description: "Flags functions with too many parameters.", remediation: "Group related options or reduce the function's responsibility. Or raise rules.size.parameter-count.threshold in .gruff-ts.yaml if the bound is wrong for this project.", threshold: 7 },
|
|
95
96
|
{ ruleId: "test-quality.conditional-logic", pillar: "test-quality", severity: "advisory", confidence: "high", description: "Flags tests with conditional logic.", remediation: "Split branch-specific expectations into separate tests." },
|
|
96
97
|
{ ruleId: "test-quality.exception-type-only", pillar: "test-quality", severity: "advisory", confidence: "high", description: "Flags tests that only assert exception type.", remediation: "Assert message, code, or observable behavior as well." },
|
|
97
98
|
{ ruleId: "test-quality.global-state-mutation", pillar: "test-quality", severity: "warning", confidence: "high", description: "Flags tests mutating process or global runtime state.", remediation: "Isolate state changes and restore them around the test." },
|
|
@@ -102,7 +103,7 @@ const RULE_DESCRIPTORS: readonly RuleDescriptor[] = [
|
|
|
102
103
|
{ ruleId: "test-quality.no-assertions", pillar: "test-quality", severity: "warning", confidence: "high", description: "Flags tests without apparent assertions.", remediation: "Add assertions for observable behavior." },
|
|
103
104
|
{ ruleId: "test-quality.no-throw-only-test", pillar: "test-quality", severity: "advisory", confidence: "high", description: "Flags tests that only assert code does not throw.", remediation: "Assert the observable result or state change." },
|
|
104
105
|
{ ruleId: "test-quality.only-skip", pillar: "test-quality", severity: "advisory", confidence: "high", description: "Flags focused or skipped test markers.", remediation: "Remove .only and either enable or delete skipped tests." },
|
|
105
|
-
{ ruleId: "test-quality.setup-bloat", pillar: "test-quality", severity: "advisory", confidence: "medium", description: "Flags tests with too much setup before the first assertion.", remediation: "Extract builders or reduce fixture setup.", threshold: 12 },
|
|
106
|
+
{ ruleId: "test-quality.setup-bloat", pillar: "test-quality", severity: "advisory", confidence: "medium", description: "Flags tests with too much setup before the first assertion.", remediation: "Extract builders or reduce fixture setup. Or raise rules.test-quality.setup-bloat.threshold in .gruff-ts.yaml if the bound is wrong for this project.", threshold: 12 },
|
|
106
107
|
{ ruleId: "test-quality.sleep-in-test", pillar: "test-quality", severity: "advisory", confidence: "high", description: "Flags sleeps in tests.", remediation: "Synchronize on behavior instead of wall-clock time." },
|
|
107
108
|
{ ruleId: "test-quality.snapshot-only-test", pillar: "test-quality", severity: "advisory", confidence: "high", description: "Flags tests that rely only on snapshots.", remediation: "Add targeted assertions for important behavior." },
|
|
108
109
|
{ ruleId: "test-quality.trivial-assertion", pillar: "test-quality", severity: "warning", confidence: "high", description: "Flags tautological assertions.", remediation: "Assert a real result from the system under test." },
|
package/src/safety-rules.ts
CHANGED
|
@@ -12,7 +12,7 @@ import type { Finding } from "./types.ts";
|
|
|
12
12
|
export function analyseTypeSafetyLine(file: SourceFile, line: string, codeLine: string, lineNumber: number, findings: Finding[]): void {
|
|
13
13
|
pushTsDirectiveFinding(file, line, lineNumber, findings);
|
|
14
14
|
pushNonNullAssertionFindings(file, codeLine, lineNumber, findings);
|
|
15
|
-
pushDoubleCastFindings(file, codeLine, lineNumber, findings);
|
|
15
|
+
pushDoubleCastFindings(file, line, codeLine, lineNumber, findings);
|
|
16
16
|
pushExportedAnyFinding(file, codeLine, lineNumber, findings);
|
|
17
17
|
}
|
|
18
18
|
|
|
@@ -86,11 +86,16 @@ function rawCatchBody(rawSource: string, codeSource: string, match: RegExpMatchA
|
|
|
86
86
|
|
|
87
87
|
// Comment-only catches are acceptable when the comment gives a rationale such as "already closed",
|
|
88
88
|
// "cache write failure is non-fatal", or "composition continues"; placeholders still surface.
|
|
89
|
+
// The bare-token alternatives (`ignore`, `ignored`, `cleanup`, `teardown`, `noop`, `no-op`) match
|
|
90
|
+
// the most common idioms for documented teardown swallows. `silent` is deliberately NOT included -
|
|
91
|
+
// real swallowed-error defects in goat-flow's dashboard-projects.ts use `/* silent */` and must
|
|
92
|
+
// continue to fire. Deferred-work markers are also excluded - that flavour of placeholder is not
|
|
93
|
+
// "intentional swallow."
|
|
89
94
|
function hasIntentionalCatchRationale(body: string): boolean {
|
|
90
95
|
return (
|
|
91
96
|
/(?:\/\/|\/\*)/.test(body) &&
|
|
92
97
|
(hasSuppressionRationale(body) ||
|
|
93
|
-
/\b(?:already (?:closed|dead|gone)|optional|best effort|missing|unreadable|not a directory|doesn't exist|not available|non-fatal|cache write failure|composition continues|try next location|server unavailable|must not affect|explicit launch|malformed messages|template missing|sets [A-Za-z_$][A-Za-z0-9_$]* = false|skip agents? that fail)\b/i.test(body))
|
|
98
|
+
/\b(?:already (?:closed|dead|gone)|optional|best effort|missing|unreadable|not a directory|doesn't exist|not available|non-fatal|cache write failure|composition continues|try next location|server unavailable|must not affect|explicit launch|malformed messages|template missing|sets [A-Za-z_$][A-Za-z0-9_$]* = false|skip agents? that fail|ignored?|cleanup|teardown|noop|no-op)\b/i.test(body))
|
|
94
99
|
);
|
|
95
100
|
}
|
|
96
101
|
|
|
@@ -141,28 +146,38 @@ function pushNonNullAssertionFindings(file: SourceFile, codeLine: string, lineNu
|
|
|
141
146
|
}
|
|
142
147
|
}
|
|
143
148
|
|
|
144
|
-
// `as unknown as Foo` and `as any as Foo` double-cast patterns.
|
|
145
|
-
//
|
|
146
|
-
|
|
149
|
+
// `as unknown as Foo` and `as any as Foo` double-cast patterns. Why: the rationale branch keeps
|
|
150
|
+
// boundary casts visible without scoring a documented TS2352/validator hop like an unexplained
|
|
151
|
+
// bypass because typed parser migrations often land later; invariant: never throws and emits stable metadata.
|
|
152
|
+
function pushDoubleCastFindings(file: SourceFile, rawLine: string, codeLine: string, lineNumber: number, findings: Finding[]): void {
|
|
147
153
|
for (const match of codeLine.matchAll(/\bas\s+(unknown|any)\s+as\s+([^;,\n]+)/g)) {
|
|
148
154
|
const sourceType = match[1] ?? "";
|
|
149
155
|
const targetType = (match[2] ?? "").trim().replace(/[.)]+$/, "");
|
|
156
|
+
const hasRationale = hasDoubleCastTrustBoundaryRationale(rawLine);
|
|
150
157
|
findings.push(
|
|
151
158
|
makeFinding({
|
|
152
159
|
ruleId: "modernisation.double-cast",
|
|
153
160
|
message: `Double cast through \`${sourceType}\` bypasses structural type checks.`,
|
|
154
161
|
filePath: file.displayPath,
|
|
155
162
|
line: lineNumber,
|
|
156
|
-
severity: "warning",
|
|
163
|
+
severity: hasRationale ? "advisory" : "warning",
|
|
157
164
|
pillar: "modernisation",
|
|
158
165
|
confidence: "medium",
|
|
159
166
|
remediation: "Prefer a typed parser, type guard, or narrower assertion at the trust boundary.",
|
|
160
|
-
metadata: { sourceType, targetType },
|
|
167
|
+
metadata: { sourceType, targetType, ...(hasRationale ? { rationale: "trust-boundary" } : {}) },
|
|
161
168
|
}),
|
|
162
169
|
);
|
|
163
170
|
}
|
|
164
171
|
}
|
|
165
172
|
|
|
173
|
+
// Accepts only inline comments that name the trust boundary or validation reason for the cast.
|
|
174
|
+
function hasDoubleCastTrustBoundaryRationale(rawLine: string): boolean {
|
|
175
|
+
return (
|
|
176
|
+
/(?:\/\/|\/\*)/.test(rawLine) &&
|
|
177
|
+
/\b(?:trust boundary|external input|wire format|parser boundary|TS2352|unknown hop|validated|narrowed|type guard|schema)\b/i.test(rawLine)
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
|
|
166
181
|
/*
|
|
167
182
|
* `any` in an exported declaration's public surface. Only one finding per line because a single
|
|
168
183
|
* `export` with multiple any-typed fields is one design problem, not many. Reports the stable
|
package/src/scoring.ts
CHANGED
|
@@ -1,27 +1,28 @@
|
|
|
1
1
|
// Score, grade, and fail-on helpers derived from finding severities for reports and CLI exits.
|
|
2
|
-
import { grade } from "./
|
|
2
|
+
import { grade } from "./pillar-summary.ts";
|
|
3
3
|
import type { AnalysisReport, FailThreshold, Finding, Pillar, Severity } from "./types.ts";
|
|
4
4
|
|
|
5
|
-
// Builds the per-pillar and per-file score breakdown that ships in `gruff.analysis.
|
|
5
|
+
// Builds the per-pillar and per-file score breakdown that ships in `gruff.analysis.v2`. The composite
|
|
6
6
|
// score is the mean of pillar scores so adding a pillar shifts the headline number. `topOffenders` is
|
|
7
7
|
// the full file list sorted worst-first; renderers cap it themselves (HTML/hotspot keep their 10-row
|
|
8
|
-
// UX, summary honours `--top`). The field shape is part of the `gruff.analysis.
|
|
8
|
+
// UX, summary honours `--top`). The field shape is part of the `gruff.analysis.v2` schema contract.
|
|
9
9
|
function scoreReport(findings: Finding[]): AnalysisReport["score"] {
|
|
10
10
|
const byPillar = new Map<Pillar, Finding[]>();
|
|
11
11
|
const byFile = new Map<string, Finding[]>();
|
|
12
|
+
const penalties = scoringPenaltyMap(findings);
|
|
12
13
|
for (const finding of findings) {
|
|
13
14
|
byPillar.set(finding.pillar, [...(byPillar.get(finding.pillar) ?? []), finding]);
|
|
14
15
|
byFile.set(finding.filePath, [...(byFile.get(finding.filePath) ?? []), finding]);
|
|
15
16
|
}
|
|
16
17
|
const pillars = [...byPillar.entries()].map(([pillar, pillarFindings]) => {
|
|
17
|
-
const penalty = pillarFindings.reduce((sum, finding) => sum +
|
|
18
|
-
return { pillar, score: Math.max(0, 100 - penalty), findings: pillarFindings.length };
|
|
18
|
+
const penalty = pillarFindings.reduce((sum, finding) => sum + findingPenalty(penalties, finding), 0);
|
|
19
|
+
return { pillar, score: Math.max(0, 100 - penalty), penalty, findings: pillarFindings.length };
|
|
19
20
|
});
|
|
20
21
|
const composite = pillars.length === 0 ? 100 : pillars.reduce((sum, pillar) => sum + pillar.score, 0) / pillars.length;
|
|
21
22
|
const topOffenders = [...byFile.entries()]
|
|
22
23
|
.map(([filePath, fileFindings]) => ({
|
|
23
24
|
filePath,
|
|
24
|
-
score: Math.max(0, 100 - fileFindings.reduce((sum, finding) => sum +
|
|
25
|
+
score: Math.max(0, 100 - fileFindings.reduce((sum, finding) => sum + findingPenalty(penalties, finding), 0)),
|
|
25
26
|
findings: fileFindings.length,
|
|
26
27
|
}))
|
|
27
28
|
.sort((left, right) => left.score - right.score);
|
|
@@ -29,7 +30,7 @@ function scoreReport(findings: Finding[]): AnalysisReport["score"] {
|
|
|
29
30
|
}
|
|
30
31
|
|
|
31
32
|
// Severity tallies emitted in the report summary. The four-key shape (advisory/warning/error/total)
|
|
32
|
-
// is part of the `gruff.analysis.
|
|
33
|
+
// is part of the `gruff.analysis.v2` schema and consumers rely on `total` matching the array length.
|
|
33
34
|
function summarize(findings: Finding[]) {
|
|
34
35
|
return {
|
|
35
36
|
advisory: findings.filter((finding) => finding.severity === "advisory").length,
|
|
@@ -71,4 +72,73 @@ function severityPenalty(severity: Severity): number {
|
|
|
71
72
|
return severity === "error" ? 8 : severity === "warning" ? 4 : 1.5;
|
|
72
73
|
}
|
|
73
74
|
|
|
74
|
-
|
|
75
|
+
const CORRELATED_COMPLEXITY_RULE_IDS = new Set(["complexity.cognitive", "complexity.cyclomatic", "size.function-length"]);
|
|
76
|
+
|
|
77
|
+
// Correlated complexity findings describe one hard-to-review function.
|
|
78
|
+
// Invariant: detailed reports keep every rule finding while grade math splits one max-severity penalty.
|
|
79
|
+
function scoringPenaltyMap(findings: Finding[]): Map<Finding, number> {
|
|
80
|
+
const penalties = new Map<Finding, number>();
|
|
81
|
+
const clusters = new Map<string, Finding[]>();
|
|
82
|
+
for (const finding of findings) {
|
|
83
|
+
penalties.set(finding, severityPenalty(finding.severity));
|
|
84
|
+
const key = complexityClusterKey(finding);
|
|
85
|
+
if (key) {
|
|
86
|
+
clusters.set(key, [...(clusters.get(key) ?? []), finding]);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
for (const cluster of clusters.values()) {
|
|
90
|
+
if (cluster.length < 2) {
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
const sharedPenalty = Math.max(...cluster.map((finding) => severityPenalty(finding.severity))) / cluster.length;
|
|
94
|
+
cluster.forEach((finding) => penalties.set(finding, sharedPenalty));
|
|
95
|
+
}
|
|
96
|
+
return penalties;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Invariant: line+symbol grouping prevents unrelated functions in the same file from sharing score relief.
|
|
100
|
+
function complexityClusterKey(finding: Finding): string | undefined {
|
|
101
|
+
if (!finding.symbol || !finding.line || !CORRELATED_COMPLEXITY_RULE_IDS.has(finding.ruleId)) {
|
|
102
|
+
return undefined;
|
|
103
|
+
}
|
|
104
|
+
return `${finding.filePath}\0${finding.symbol}\0${finding.line}`;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Invariant: one finding uses one precomputed score penalty or the normal severity weight fallback.
|
|
108
|
+
function findingPenalty(penalties: ReadonlyMap<Finding, number>, finding: Finding): number {
|
|
109
|
+
return penalties.get(finding) ?? severityPenalty(finding.severity);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/*
|
|
113
|
+
* Per-severity grade breakdown for the human summary block. The composite headline alone hides the
|
|
114
|
+
* fact that an F can be driven entirely by advisories (goat-flow scan: F at 12.9 with 0 errors / 276
|
|
115
|
+
* warnings / 1367 advisories). Mirrors the existing pillar formula `100 - count * severityPenalty`
|
|
116
|
+
* so the math stays consistent with how a single-rule pillar would score. The report-shape
|
|
117
|
+
* invariant matters: severity breakdowns and correlated complexity clustering must not add
|
|
118
|
+
* `gruff.analysis.v2` JSON fields, even when score values change.
|
|
119
|
+
*/
|
|
120
|
+
function severityGradeBreakdown(findings: Finding[]): {
|
|
121
|
+
error: { grade: string; score: number; count: number };
|
|
122
|
+
warning: { grade: string; score: number; count: number };
|
|
123
|
+
advisory: { grade: string; score: number; count: number };
|
|
124
|
+
} {
|
|
125
|
+
const counts = { error: 0, warning: 0, advisory: 0 };
|
|
126
|
+
for (const finding of findings) {
|
|
127
|
+
counts[finding.severity] += 1;
|
|
128
|
+
}
|
|
129
|
+
return {
|
|
130
|
+
error: severityBucket("error", counts.error),
|
|
131
|
+
warning: severityBucket("warning", counts.warning),
|
|
132
|
+
advisory: severityBucket("advisory", counts.advisory),
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// Single severity bucket using the same `score = max(0, 100 - count * penalty)` formula as the
|
|
137
|
+
// pillar reduce in `scoreReport`. Returns the bucket plus its grade letter so renderers don't have
|
|
138
|
+
// to import `grade` separately.
|
|
139
|
+
function severityBucket(severity: Severity, count: number): { grade: string; score: number; count: number } {
|
|
140
|
+
const score = Math.max(0, 100 - count * severityPenalty(severity));
|
|
141
|
+
return { grade: grade(score), score, count };
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export { scoreReport, summarize, exitFor, severityGradeBreakdown };
|