@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.
- package/CHANGELOG.md +123 -1
- package/CONTRIBUTING.md +32 -25
- package/README.md +55 -46
- package/SECURITY.md +18 -30
- package/UPGRADING.md +101 -0
- package/bin/gruff-ts +3 -0
- package/docs/README.md +11 -13
- package/docs/agent-hook.md +33 -24
- package/docs/ci-integration.md +38 -24
- package/docs/configuration.md +173 -71
- 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 -157
- package/docs/rules.md +140 -106
- package/package.json +10 -8
- package/src/analyser.ts +886 -282
- 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 +85 -55
- package/src/blocks.ts +579 -364
- package/src/changed-regions.ts +414 -65
- package/src/check-ignore.ts +28 -13
- package/src/class-rules.ts +461 -302
- package/src/cli-program.ts +956 -166
- package/src/cli.ts +9 -2
- package/src/comment-rules.ts +277 -414
- package/src/comment-scanner.ts +363 -44
- package/src/complexity-metrics.ts +320 -0
- 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 +778 -210
- package/src/constants.ts +7 -6
- package/src/context-doc-rules.ts +188 -61
- package/src/dashboard.ts +88 -23
- package/src/dead-code-rules.ts +153 -74
- package/src/discovery.ts +521 -148
- package/src/doc-rules.ts +592 -147
- package/src/duplicate-test-group-rules.ts +359 -0
- package/src/findings-helpers.ts +240 -89
- package/src/findings.ts +48 -24
- package/src/fixture-purpose-rules.ts +226 -48
- package/src/github-actions-event-guards.ts +331 -0
- package/src/github-actions-rules.ts +336 -106
- package/src/hook-contract.ts +708 -211
- package/src/init-config.ts +169 -114
- package/src/inline-suppressions.ts +340 -0
- package/src/limit-band.ts +56 -0
- package/src/line-rules.ts +331 -419
- package/src/migrate-config.ts +670 -0
- package/src/naming-pushers.ts +33 -107
- package/src/parsed-script.ts +1206 -0
- package/src/pillar-summary.ts +56 -40
- package/src/profiles.ts +97 -71
- package/src/project-config-rules.ts +335 -146
- package/src/project-rules.ts +237 -115
- package/src/public-exports.ts +284 -0
- package/src/report-html.ts +217 -85
- package/src/report-renderers.ts +864 -195
- package/src/rule-list.ts +166 -46
- package/src/rules.ts +100 -104
- package/src/safety-rules.ts +191 -132
- package/src/scoring.ts +255 -52
- package/src/security-flow-rules.ts +930 -109
- package/src/selectors.ts +169 -0
- package/src/sensitive-data-rules.ts +502 -375
- package/src/sensitive-exclusions.ts +435 -0
- package/src/source-text.ts +380 -148
- package/src/static-analysis-redundant-rules.ts +298 -41
- package/src/test-block-rules.ts +422 -228
- package/src/text-scans.ts +67 -9
- package/src/types.ts +222 -71
- package/tsconfig.json +2 -1
- package/src/process-exec-metadata.ts +0 -153
- package/src/test-fixtures.ts +0 -668
|
@@ -1,47 +1,96 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
// strict validator is the wrong tool for that handoff - the next analyser load will run it.
|
|
1
|
+
// Recovers supported settings when a user regenerates an older config with `init --force`.
|
|
2
|
+
//
|
|
3
|
+
// Keeps ignored paths, command gates, and valid sensitive exclusions with their reasons.
|
|
4
|
+
// Empty collections mean no usable entries were recovered for that setting.
|
|
6
5
|
import { objectValue, parseConfigFile } from "./config-parse.ts";
|
|
7
|
-
import
|
|
6
|
+
import { ConfigLoadError } from "./config-load-error.ts";
|
|
7
|
+
import { parseSensitiveExclusions } from "./sensitive-exclusions.ts";
|
|
8
|
+
import type { FailThreshold, MinimumSeverityCommand, SensitiveExclusion } from "./types.ts";
|
|
8
9
|
|
|
9
|
-
//
|
|
10
|
-
// values mean nothing was preserved, not that the existing config was empty.
|
|
10
|
+
// Settings recovered for `init --force`. Each empty collection leaves the new config with its generated settings.
|
|
11
11
|
interface PreservedConfigFields {
|
|
12
12
|
ignoredPaths: string[];
|
|
13
|
-
|
|
13
|
+
failOn: Map<MinimumSeverityCommand, FailThreshold>;
|
|
14
|
+
sensitiveExclusions: SensitiveExclusion[];
|
|
14
15
|
}
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
17
|
+
/**
|
|
18
|
+
* Recovers settings before init --force regenerates a config. Files without a schemaVersion can still supply settings.
|
|
19
|
+
* The regeneration caller proceeds with empty fields if reading or parsing fails.
|
|
20
|
+
*
|
|
21
|
+
* @param configPath - path to the existing config to read
|
|
22
|
+
* @returns - preserved ignore globs, command thresholds, and sensitive exclusions, with empty collections for unavailable entries
|
|
23
|
+
* @throws {ConfigLoadError} - for a missing file, unsupported extension, invalid syntax, or a root value that is not a mapping
|
|
24
|
+
* @throws {Error} - when another filesystem read error occurs
|
|
23
25
|
*/
|
|
24
26
|
export function extractPreservedConfigFields(configPath: string): PreservedConfigFields {
|
|
25
27
|
const raw = parseConfigFile(configPath);
|
|
26
28
|
return {
|
|
27
29
|
ignoredPaths: extractIgnoredPaths(raw),
|
|
28
|
-
|
|
30
|
+
failOn: extractFailOn(raw),
|
|
31
|
+
sensitiveExclusions: extractSensitiveExclusions(raw),
|
|
29
32
|
};
|
|
30
33
|
}
|
|
31
34
|
|
|
32
|
-
|
|
33
|
-
|
|
35
|
+
/**
|
|
36
|
+
* Carries existing sensitive exclusions and their written reasons into the regenerated config.
|
|
37
|
+
*
|
|
38
|
+
* @param raw - parsed config. An absent or empty sensitiveExclusions list supplies no exclusions to carry forward.
|
|
39
|
+
* @returns validated exclusion scopes in order. An invalid entry contributes no exclusion.
|
|
40
|
+
* @throws unexpected errors from the exclusion validator.
|
|
41
|
+
*/
|
|
42
|
+
function extractSensitiveExclusions(raw: Record<string, unknown>): SensitiveExclusion[] {
|
|
43
|
+
const entries = raw.sensitiveExclusions;
|
|
44
|
+
// Some older projects have no exclusion list to carry over.
|
|
45
|
+
if (!Array.isArray(entries)) {
|
|
46
|
+
return [];
|
|
47
|
+
}
|
|
48
|
+
const preserved: SensitiveExclusion[] = [];
|
|
49
|
+
const seen = new Set<string>();
|
|
50
|
+
// Review each entry separately so one malformed scope does not discard the user's other exclusions.
|
|
51
|
+
for (const entry of entries) {
|
|
52
|
+
try {
|
|
53
|
+
const [candidate] = parseSensitiveExclusions({ sensitiveExclusions: [entry] });
|
|
54
|
+
// A validator result without a scope adds nothing to the regenerated file.
|
|
55
|
+
if (candidate === undefined) {
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
const scope = JSON.stringify([candidate.rule, candidate.path, candidate.symbol]);
|
|
59
|
+
// A pasted duplicate keeps the first scope and its original written reason.
|
|
60
|
+
if (!seen.has(scope)) {
|
|
61
|
+
preserved.push(candidate);
|
|
62
|
+
seen.add(scope);
|
|
63
|
+
}
|
|
64
|
+
} catch (error) {
|
|
65
|
+
// A user might have left an exclusion's scope incomplete. Skip invalid config entries and surface unexpected failures.
|
|
66
|
+
if (!(error instanceof ConfigLoadError)) {
|
|
67
|
+
throw error;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return preserved;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Extracts glob strings from `paths.ignore` in a parsed config for regeneration, skipping non-string entries.
|
|
76
|
+
*
|
|
77
|
+
* @param raw - parsed existing config mapping to inspect for a `paths.ignore` list
|
|
78
|
+
* @returns glob strings from `paths.ignore`, or an empty list when missing or not an array
|
|
79
|
+
*/
|
|
34
80
|
function extractIgnoredPaths(raw: Record<string, unknown>): string[] {
|
|
35
81
|
const ignore = objectValue(raw.paths)?.ignore;
|
|
36
82
|
return Array.isArray(ignore) ? ignore.filter((entry): entry is string => typeof entry === "string") : [];
|
|
37
83
|
}
|
|
38
84
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
85
|
+
/**
|
|
86
|
+
* Preserves valid per-command gates during config rewrites so that one invalid entry does not discard the others.
|
|
87
|
+
*
|
|
88
|
+
* @param raw - parsed file settings. Legacy minimumSeverity: supplies gates only when failOn supplies no mapping.
|
|
89
|
+
* @returns - map from command to threshold, empty when there is no mapping or no valid entry
|
|
90
|
+
*/
|
|
91
|
+
function extractFailOn(raw: Record<string, unknown>): Map<MinimumSeverityCommand, FailThreshold> {
|
|
43
92
|
const result = new Map<MinimumSeverityCommand, FailThreshold>();
|
|
44
|
-
const block = objectValue(raw.minimumSeverity);
|
|
93
|
+
const block = objectValue(raw.failOn) ?? objectValue(raw.minimumSeverity);
|
|
45
94
|
if (!block) {
|
|
46
95
|
return result;
|
|
47
96
|
}
|
|
@@ -51,8 +100,14 @@ function extractMinimumSeverity(raw: Record<string, unknown>): Map<MinimumSeveri
|
|
|
51
100
|
return result;
|
|
52
101
|
}
|
|
53
102
|
|
|
54
|
-
|
|
55
|
-
|
|
103
|
+
/**
|
|
104
|
+
* Stores an existing config's failure threshold for a supported command in the destination map used for regeneration.
|
|
105
|
+
*
|
|
106
|
+
* @param result - destination map mutated with the validated command threshold when both inputs are supported
|
|
107
|
+
* @param commandName - command name key from the parsed config; only `analyse`, `summary`, and `report` are accepted
|
|
108
|
+
* @param rawThreshold - candidate threshold value; only `none`, `advisory`, `warning`, and `error` are stored
|
|
109
|
+
* @returns Nothing. Leaves `result` unchanged when the command or threshold is unsupported.
|
|
110
|
+
*/
|
|
56
111
|
function addPreservedSeverityEntry(result: Map<MinimumSeverityCommand, FailThreshold>, commandName: string, rawThreshold: unknown): void {
|
|
57
112
|
if (commandName !== "analyse" && commandName !== "summary" && commandName !== "report") {
|
|
58
113
|
return;
|