@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/naming-pushers.ts
CHANGED
|
@@ -1,112 +1,28 @@
|
|
|
1
1
|
// Shared "push a naming finding at this line" helpers. Used both by the per-line walker in
|
|
2
|
-
// line-rules.ts and by the parameter
|
|
3
|
-
//
|
|
2
|
+
// line-rules.ts and by the parameter walker in analyser.ts. Stable metadata.surface distinguishes
|
|
3
|
+
// call sites while every finding uses the same fingerprint identity.
|
|
4
4
|
import { type SourceFile } from "./discovery.ts";
|
|
5
5
|
import { makeFinding } from "./findings.ts";
|
|
6
|
-
import { escapeRegex } from "./findings-helpers.ts";
|
|
7
6
|
import type { Config, Finding } from "./types.ts";
|
|
8
7
|
|
|
9
8
|
/**
|
|
10
9
|
* Stable label for the call-site that emitted a naming finding. Surfaces in `metadata.surface`
|
|
11
10
|
* so downstream tooling can split per-pillar reports by origin without re-running the analyser.
|
|
12
11
|
*/
|
|
13
|
-
export type NamingSurface = "declaration" | "parameter" | "destructure"
|
|
12
|
+
export type NamingSurface = "declaration" | "parameter" | "destructure";
|
|
14
13
|
|
|
15
14
|
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* @
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
configurationKey: "allowlists.acceptedBooleanNames",
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
return {
|
|
31
|
-
remediation: "Rename this boolean with an intent-revealing prefix such as is, has, can, should, or will.",
|
|
32
|
-
remediationAction: "APPLY",
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/*
|
|
37
|
-
* Negative-framed booleans (disableX, noX, preventX, …) read as double negations at call sites.
|
|
38
|
-
* `negativeBooleanAllowed` is the user-curated exemption list. Reports the stable
|
|
39
|
-
* `naming.negative-boolean` finding.
|
|
40
|
-
*/
|
|
41
|
-
export function pushNegativeBooleanAt(file: SourceFile, line: number, name: string, config: Config, findings: Finding[], surface: NamingSurface): void {
|
|
42
|
-
if (!/^(?:disable|no|not|prevent|skip|disallow)[A-Z]/.test(name)) {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
if (config.negativeBooleanAllowed.has(name.toLowerCase())) {
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
findings.push(
|
|
49
|
-
makeFinding({
|
|
50
|
-
ruleId: "naming.negative-boolean",
|
|
51
|
-
message: `Boolean identifier \`${name}\` is framed as a negation.`,
|
|
52
|
-
filePath: file.displayPath,
|
|
53
|
-
line,
|
|
54
|
-
severity: "advisory",
|
|
55
|
-
pillar: "naming",
|
|
56
|
-
confidence: "medium",
|
|
57
|
-
symbol: name,
|
|
58
|
-
remediation: "Invert the framing so callers do not read a double negation.",
|
|
59
|
-
metadata: { identifierName: name, surface },
|
|
60
|
-
}),
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/*
|
|
65
|
-
* Reports typed booleans without an accepted prefix or exact contract name. The finding keeps its
|
|
66
|
-
* stable identity while its surface selects safe local-rename or contract configuration guidance.
|
|
67
|
-
*/
|
|
68
|
-
export function pushBooleanPrefixAt(file: SourceFile, line: number, name: string, config: Config, findings: Finding[], surface: NamingSurface): void {
|
|
69
|
-
if (hasBooleanPrefix(name, config.booleanPrefixes) || isAcceptedBooleanStateName(name) || isAcceptedContractBooleanName(name, config, surface)) {
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
const { remediation, ...remediationMetadata } = booleanPrefixGuidance(surface);
|
|
73
|
-
findings.push(
|
|
74
|
-
makeFinding({
|
|
75
|
-
ruleId: "naming.boolean-prefix",
|
|
76
|
-
message: `Boolean identifier \`${name}\` should use an intent-revealing prefix.`,
|
|
77
|
-
filePath: file.displayPath,
|
|
78
|
-
line,
|
|
79
|
-
severity: "advisory",
|
|
80
|
-
pillar: "naming",
|
|
81
|
-
confidence: "medium",
|
|
82
|
-
symbol: name,
|
|
83
|
-
remediation,
|
|
84
|
-
metadata: { identifierName: name, surface, ...remediationMetadata },
|
|
85
|
-
}),
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const ACCEPTED_BOOLEAN_STATE_NAMES = new Set(["acknowledged", "exists", "validated", "detected", "resolved", "selected", "installed"]);
|
|
90
|
-
const ACCEPTED_BOOLEAN_STATE_SUFFIXES = ["Available", "Required", "Validated", "Detected", "Resolved", "Selected", "Installed"];
|
|
91
|
-
// Some booleans are state adjectives rather than predicate phrases. Keep this list deliberately
|
|
92
|
-
// narrow so vague local names such as `ready` or `enabled` still get the maintainability prompt.
|
|
93
|
-
function isAcceptedBooleanStateName(name: string): boolean {
|
|
94
|
-
return ACCEPTED_BOOLEAN_STATE_NAMES.has(name.toLowerCase()) || ACCEPTED_BOOLEAN_STATE_SUFFIXES.some((suffix) => name.endsWith(suffix));
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// CLI option bags, DTOs, and schema fields often must expose exact external key names such as
|
|
98
|
-
// `verbose` or `ok`. Limit the exact-name exemption to contract fields so ordinary locals still
|
|
99
|
-
// need predicate-style names.
|
|
100
|
-
function isAcceptedContractBooleanName(name: string, config: Config, surface: NamingSurface): boolean {
|
|
101
|
-
return surface === "interface-field" && config.acceptedBooleanNames.has(name.toLowerCase());
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/*
|
|
105
|
-
* Allows the standard `i`, `j`, `k` loop counters and anything on `acceptedAbbreviations`. Reports
|
|
106
|
-
* `naming.short-variable` for any other one or two character name as a stable advisory finding.
|
|
107
|
-
* `loopBodyLineCount` is the for-of caller's signal: when the binding came from a `for (const X of
|
|
108
|
-
* Y) { … }` head and the body spans ≤ 10 lines, the rule suppresses the finding because the name's
|
|
109
|
-
* lifetime is locally obvious. Other call sites (declaration, parameter, destructure) pass undefined.
|
|
15
|
+
* Checks whether a short name qualifies for a naming.short-variable advisory.
|
|
16
|
+
* Names longer than two characters and i, j and k are exempt.
|
|
17
|
+
*
|
|
18
|
+
* @param file - supplies the display path for the advisory
|
|
19
|
+
* @param line - source line to report with the advisory
|
|
20
|
+
* @param name - identifier to check for sufficient length or an exemption
|
|
21
|
+
* @param config - supplies accepted abbreviations, checked against the lowercased name
|
|
22
|
+
* @param findings - receives the stable advisory when the name fails the check
|
|
23
|
+
* @param surface - records whether the name came from a declaration, parameter or destructure
|
|
24
|
+
* @param loopBodyLineCount - for-of body code-line count. At most 10 exempts the name. Undefined gives no loop exemption.
|
|
25
|
+
* @returns - returns nothing. Appends an advisory to findings when the name is too short and has no exemption.
|
|
110
26
|
*/
|
|
111
27
|
export function pushShortVariableAt(file: SourceFile, line: number, name: string, config: Config, findings: Finding[], surface: NamingSurface, loopBodyLineCount?: number): void {
|
|
112
28
|
if (loopBodyLineCount !== undefined && loopBodyLineCount <= 10) {
|
|
@@ -131,10 +47,16 @@ export function pushShortVariableAt(file: SourceFile, line: number, name: string
|
|
|
131
47
|
);
|
|
132
48
|
}
|
|
133
49
|
|
|
134
|
-
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
*
|
|
50
|
+
/**
|
|
51
|
+
* Checks for generic or numbered placeholder names, including built-in numbered stems.
|
|
52
|
+
*
|
|
53
|
+
* @param file - supplies the display path for the advisory
|
|
54
|
+
* @param line - source line to report with the advisory
|
|
55
|
+
* @param name - identifier to check against the placeholder rules
|
|
56
|
+
* @param config - supplies configured placeholders for full-name and numbered-stem checks
|
|
57
|
+
* @param findings - receives the advisory with stable variant metadata when a placeholder matches
|
|
58
|
+
* @param surface - records whether the name came from a declaration, parameter or destructure
|
|
59
|
+
* @returns - returns nothing. Appends one advisory for a matched placeholder and leaves findings unchanged otherwise.
|
|
138
60
|
*/
|
|
139
61
|
export function pushIdentifierQualityAt(file: SourceFile, line: number, name: string, config: Config, findings: Finding[], surface: NamingSurface): void {
|
|
140
62
|
const variant = identifierQualityVariant(name, config.placeholderNames);
|
|
@@ -157,9 +79,14 @@ export function pushIdentifierQualityAt(file: SourceFile, line: number, name: st
|
|
|
157
79
|
);
|
|
158
80
|
}
|
|
159
81
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
82
|
+
/**
|
|
83
|
+
* Classifies an identifier as a generic or numbered placeholder; returns undefined when no identifier-quality advisory applies.
|
|
84
|
+
* A numbered name ends in digits after a stem made of ASCII letters, underscores or dollar signs.
|
|
85
|
+
*
|
|
86
|
+
* @param name - identifier checked lowercased against placeholderNames or split into a stem and trailing digits
|
|
87
|
+
* @param placeholderNames - configured placeholder names checked for full-name and lowercased stem matches
|
|
88
|
+
* @returns "generic" if lowercased name is in placeholderNames, "numbered" if its lowercased stem is in either placeholder set, or undefined.
|
|
89
|
+
*/
|
|
163
90
|
function identifierQualityVariant(name: string, placeholderNames: Set<string>): string | undefined {
|
|
164
91
|
if (placeholderNames.has(name.toLowerCase())) {
|
|
165
92
|
return "generic";
|
|
@@ -192,25 +119,3 @@ const NUMBERED_PLACEHOLDER_STEMS = new Set([
|
|
|
192
119
|
"value",
|
|
193
120
|
"var",
|
|
194
121
|
]);
|
|
195
|
-
|
|
196
|
-
const BOOLEAN_PREFIX_REGEX_CACHE = new WeakMap<Set<string>, RegExp | null>();
|
|
197
|
-
|
|
198
|
-
// Tests the cached prefix regex from `booleanPrefixRegex`. A null regex (empty prefix set) is
|
|
199
|
-
// treated as "no rule configured" so the boolean-prefix check fires only when configured.
|
|
200
|
-
function hasBooleanPrefix(name: string, prefixes: Set<string>): boolean {
|
|
201
|
-
const regex = booleanPrefixRegex(prefixes);
|
|
202
|
-
return regex !== null && regex.test(name);
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
// Cached per prefix Set via a WeakMap so each rule pass reuses the compiled regex instead of
|
|
206
|
-
// rebuilding it for every identifier. The trailing `[A-Z_]` requirement keeps single-letter
|
|
207
|
-
// names like `is` from falsely matching the prefix-followed-by-name pattern.
|
|
208
|
-
function booleanPrefixRegex(prefixes: Set<string>): RegExp | null {
|
|
209
|
-
if (BOOLEAN_PREFIX_REGEX_CACHE.has(prefixes)) {
|
|
210
|
-
return BOOLEAN_PREFIX_REGEX_CACHE.get(prefixes) ?? null;
|
|
211
|
-
}
|
|
212
|
-
const escaped = [...prefixes].map(escapeRegex);
|
|
213
|
-
const regex = prefixes.size === 0 ? null : new RegExp(`^(?:${escaped.join("|")})[A-Z_]`);
|
|
214
|
-
BOOLEAN_PREFIX_REGEX_CACHE.set(prefixes, regex);
|
|
215
|
-
return regex;
|
|
216
|
-
}
|