@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/init-config.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
// Renders the
|
|
2
|
-
//
|
|
3
|
-
//
|
|
1
|
+
// Renders the starter `.gruff-ts.yaml` file from the rule descriptor registry when the user runs `gruff-ts init`.
|
|
2
|
+
//
|
|
3
|
+
// Gives a new project the analyser's effective defaults and preserves existing ignore paths, gates, and exclusions on `--force`.
|
|
4
|
+
// Also drives the interactive first-run init prompt before a terminal scan when no config file exists yet.
|
|
4
5
|
import { existsSync, writeFileSync } from "node:fs";
|
|
5
6
|
import { join } from "node:path";
|
|
6
7
|
import { createInterface } from "node:readline/promises";
|
|
@@ -11,19 +12,16 @@ import type { FailThreshold, MinimumSeverityCommand, RuleDescriptor } from "./ty
|
|
|
11
12
|
|
|
12
13
|
const DEFAULT_CONFIG_FILE_NAME = ".gruff-ts.yaml";
|
|
13
14
|
|
|
14
|
-
// Default option values for rules
|
|
15
|
-
// `
|
|
16
|
-
|
|
17
|
-
// here match the implementation defaults so drift fails the test suite, not user projects.
|
|
18
|
-
const RULE_OPTION_DEFAULTS: Readonly<Record<string, Readonly<Record<string, number>>>> = {
|
|
15
|
+
// Default option values for rules declaring `optionKeys`, mirrored here so `gruff-ts init` stays self-contained.
|
|
16
|
+
// `init-config.test.ts` asserts parity with the live `optionNumber`/`optionBoolean` defaults in rule implementations.
|
|
17
|
+
const RULE_OPTION_DEFAULTS: Readonly<Record<string, Readonly<Record<string, number | boolean>>>> = {
|
|
19
18
|
"design.large-module-concentration": { minFiles: 4, minLines: 80 },
|
|
20
|
-
"
|
|
19
|
+
"docs.missing-param-tag": { everyCallable: true },
|
|
20
|
+
"docs.missing-return-tag": { everyCallable: true },
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
-
//
|
|
24
|
-
//
|
|
25
|
-
// Universal-programming abbreviations that earn their place across nearly any codebase; project-specific
|
|
26
|
-
// vocabulary (domain acronyms) should be appended in the user's config rather than added here.
|
|
23
|
+
// Starter abbreviation allowlist copied from `defaultConfig()` in `config.ts`, emitted as a readable YAML block sequence.
|
|
24
|
+
// Project-specific domain acronyms belong in the repository's `.gruff-ts.yaml` rather than this universal starter list.
|
|
27
25
|
const DEFAULT_ACCEPTED_ABBREVIATIONS: readonly string[] = [
|
|
28
26
|
"age", "app", "db", "fs", "id", "io", "key", "log", "max", "min", "now", "raw", "rx", "tx", "ui", "url",
|
|
29
27
|
];
|
|
@@ -34,16 +32,16 @@ interface InitResult {
|
|
|
34
32
|
status: "written" | "overwritten" | "exists";
|
|
35
33
|
}
|
|
36
34
|
|
|
37
|
-
// Inputs
|
|
38
|
-
//
|
|
39
|
-
// three
|
|
40
|
-
// and stdout so a piped consumer (e.g. `... --format=json | jq`) does not block on hidden input.
|
|
35
|
+
// Inputs `analyse` and `summary` pass before deciding whether to prompt the user to run `gruff-ts init`.
|
|
36
|
+
//
|
|
37
|
+
// All three TTY flags matter so piped JSON commands (such as `--format=json | jq`) never block on an invisible interactive prompt.
|
|
41
38
|
interface InitPromptContext {
|
|
42
39
|
projectRoot: string;
|
|
43
40
|
shouldSkipConfig: boolean;
|
|
44
41
|
hasExplicitConfig: boolean;
|
|
45
42
|
isInteractionAllowed: boolean;
|
|
46
43
|
isOutputSuppressed: boolean;
|
|
44
|
+
isMachineFormat?: boolean;
|
|
47
45
|
isStdinTty: boolean;
|
|
48
46
|
isStdoutTty: boolean;
|
|
49
47
|
isStderrTty: boolean;
|
|
@@ -51,45 +49,111 @@ interface InitPromptContext {
|
|
|
51
49
|
|
|
52
50
|
/**
|
|
53
51
|
* Bundle of values that survive an `init --force` regeneration. `paths.ignore` is preserved
|
|
54
|
-
* verbatim, `
|
|
52
|
+
* verbatim, the per-command `failOn` gate is replayed entry-by-entry; the schemaVersion field is fixed for now
|
|
55
53
|
* because there is only one supported version.
|
|
56
54
|
*/
|
|
57
55
|
interface PreservedInitConfig {
|
|
58
56
|
ignoredPaths: readonly string[];
|
|
59
|
-
|
|
57
|
+
failOn: ReadonlyMap<MinimumSeverityCommand, FailThreshold>;
|
|
58
|
+
sensitiveExclusions: readonly PreservedSensitiveExclusionEntry[];
|
|
60
59
|
}
|
|
61
60
|
|
|
62
|
-
|
|
61
|
+
// One reviewed suppression carried through regeneration, in the ratified key order.
|
|
62
|
+
interface PreservedSensitiveExclusionEntry {
|
|
63
|
+
rule: string;
|
|
64
|
+
path: string;
|
|
65
|
+
symbol?: string;
|
|
66
|
+
reason: string;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const EMPTY_PRESERVED_CONFIG: PreservedInitConfig = { ignoredPaths: [], failOn: new Map(), sensitiveExclusions: [] };
|
|
63
70
|
|
|
64
71
|
/**
|
|
65
|
-
* Render the default .gruff-ts.yaml content from the rule descriptor registry. Output order is
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
* lines for readability.
|
|
72
|
+
* Render the default .gruff-ts.yaml content from the rule descriptor registry. Output order is schemaVersion → failOn → paths → allowlists →
|
|
73
|
+
* sensitiveExclusions → rules so the highest-impact CI behaviour (gating threshold per command) sits near the top of the file. Sections are separated
|
|
74
|
+
* by blank lines for readability.
|
|
69
75
|
*
|
|
70
|
-
* @param ignoredPaths
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
* @param preservedMinimumSeverity Optional carry-over of the existing config's `minimumSeverity:`
|
|
74
|
-
* block. Empty Map falls back to canonical defaults (advisory / advisory / none).
|
|
76
|
+
* @param ignoredPaths - path exclusions kept by gruff-ts init --force. An empty list emits ignore: [].
|
|
77
|
+
* @param preservedFailOn - existing command gates. Missing entries default to advisory for analyse and none for summary and report.
|
|
78
|
+
* @param preservedSensitiveExclusions - existing reviewed suppressions, re-emitted below the guidance comments; an empty list emits only the comments
|
|
75
79
|
* @returns A YAML document string terminated by a trailing newline.
|
|
76
80
|
*/
|
|
77
|
-
function renderDefaultConfig(
|
|
81
|
+
function renderDefaultConfig(
|
|
82
|
+
ignoredPaths: readonly string[] = [],
|
|
83
|
+
preservedFailOn: ReadonlyMap<MinimumSeverityCommand, FailThreshold> = new Map(),
|
|
84
|
+
preservedSensitiveExclusions: readonly PreservedSensitiveExclusionEntry[] = [],
|
|
85
|
+
): string {
|
|
78
86
|
return [
|
|
79
87
|
renderSchemaVersionSection(),
|
|
80
88
|
"",
|
|
81
|
-
|
|
89
|
+
renderFailOnSection(preservedFailOn),
|
|
82
90
|
"",
|
|
83
91
|
renderPathsSection(ignoredPaths),
|
|
84
92
|
"",
|
|
85
93
|
renderAllowlistsSection(),
|
|
86
94
|
"",
|
|
95
|
+
renderSensitiveExclusionsSection(preservedSensitiveExclusions),
|
|
96
|
+
"",
|
|
87
97
|
renderRulesSection(),
|
|
88
98
|
].join("\n") + "\n";
|
|
89
99
|
}
|
|
90
100
|
|
|
91
|
-
|
|
92
|
-
|
|
101
|
+
/**
|
|
102
|
+
* Render the reviewed sensitive-data exclusions described in FAMILY-CONTRACT.md section 13a.
|
|
103
|
+
* Guidance stays commented so fresh projects suppress nothing here. Active entries come from prior manual review.
|
|
104
|
+
*
|
|
105
|
+
* @param preservedEntries - reviewed exclusions carried forward from the existing config
|
|
106
|
+
* @returns YAML section text with guidance and any preserved entries, or only commented guidance when the list is empty
|
|
107
|
+
*/
|
|
108
|
+
function renderSensitiveExclusionsSection(preservedEntries: readonly PreservedSensitiveExclusionEntry[]): string {
|
|
109
|
+
const guidance = [
|
|
110
|
+
"# Reviewed suppressions for sensitive-data findings. Written by hand only - gruff never",
|
|
111
|
+
"# converts a detected value, a preview, or a finding message into an exclusion.",
|
|
112
|
+
"#",
|
|
113
|
+
"# Each entry names exactly one rule id and one project-relative path, and must carry a",
|
|
114
|
+
"# non-empty reason. `symbol:` narrows further where a rule stamps one. Nothing else is",
|
|
115
|
+
"# suppressed: the same rule in another file and another rule in the same file keep reporting.",
|
|
116
|
+
"# Every entry reports its own count in the report's `suppressions` array and in the text",
|
|
117
|
+
"# `Suppressed findings:` line, so a suppression is always visible in review.",
|
|
118
|
+
"#",
|
|
119
|
+
"# Test, fixture and example paths automatically suppress sensitive-data findings",
|
|
120
|
+
"# except sensitive-data.pii-test-fixture; real credentials there are skipped too.",
|
|
121
|
+
"# Add entries only for reviewed findings that still report.",
|
|
122
|
+
"# Use the finding's rule id and replace the path/reason placeholders.",
|
|
123
|
+
"# sensitiveExclusions:",
|
|
124
|
+
"# - rule: sensitive-data.aws-access-key",
|
|
125
|
+
"# path: <reviewed-project-relative-path>",
|
|
126
|
+
"# reason: <reviewed-rationale>",
|
|
127
|
+
];
|
|
128
|
+
// Regeneration must never silently re-enable a finding a reviewer accepted in writing, so any
|
|
129
|
+
// existing entries are serialized as active YAML below the guidance comment.
|
|
130
|
+
if (preservedEntries.length === 0) {
|
|
131
|
+
return guidance.join("\n");
|
|
132
|
+
}
|
|
133
|
+
return [...guidance, "sensitiveExclusions:", ...preservedEntries.flatMap(renderPreservedExclusionEntry)].join("\n");
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Format one preserved sensitive exclusion as block-sequence YAML lines in the expected key order.
|
|
138
|
+
* An entry without a symbol keeps that selector unset in the generated YAML.
|
|
139
|
+
*
|
|
140
|
+
* @param entry - reviewed exclusion containing rule, path, reason, and optional symbol
|
|
141
|
+
* @returns YAML lines for the entry in rule, path, optional symbol, and reason order
|
|
142
|
+
*/
|
|
143
|
+
function renderPreservedExclusionEntry(entry: PreservedSensitiveExclusionEntry): string[] {
|
|
144
|
+
const lines = [` - rule: ${JSON.stringify(entry.rule)}`, ` path: ${JSON.stringify(entry.path)}`];
|
|
145
|
+
if (entry.symbol !== undefined) {
|
|
146
|
+
lines.push(` symbol: ${JSON.stringify(entry.symbol)}`);
|
|
147
|
+
}
|
|
148
|
+
lines.push(` reason: ${JSON.stringify(entry.reason)}`);
|
|
149
|
+
return lines;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Build the required top-level schema version field for the generated config.
|
|
154
|
+
*
|
|
155
|
+
* @returns YAML comment and `schemaVersion: gruff-ts.config.v0.1` line joined by a newline
|
|
156
|
+
*/
|
|
93
157
|
function renderSchemaVersionSection(): string {
|
|
94
158
|
return [
|
|
95
159
|
"# Config-schema version. Required as of gruff-ts 0.2.0. See ADR-004 (decision log).",
|
|
@@ -97,44 +161,42 @@ function renderSchemaVersionSection(): string {
|
|
|
97
161
|
].join("\n");
|
|
98
162
|
}
|
|
99
163
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
164
|
+
/**
|
|
165
|
+
* Build the `failOn` YAML section using preserved command thresholds when present.
|
|
166
|
+
* Missing analyse defaults to advisory; missing summary and report default to none. Dashboard has no entry.
|
|
167
|
+
*
|
|
168
|
+
* @param preserved - existing per-command fail thresholds recovered from a prior config
|
|
169
|
+
* @returns YAML header comments and `failOn:` block with analyse, summary, and report entries
|
|
170
|
+
*/
|
|
171
|
+
function renderFailOnSection(preserved: ReadonlyMap<MinimumSeverityCommand, FailThreshold>): string {
|
|
104
172
|
const header = [
|
|
105
173
|
"# Per-command default for `--fail-on`. CLI flag > this block > binary default.",
|
|
106
174
|
"# `dashboard` is intentionally NOT a valid key - it has no --fail-on flag. See ADR-004.",
|
|
175
|
+
"# `minimumSeverity:` is a different setting: one severity that hides quieter findings from the",
|
|
176
|
+
"# report without changing the score or the exit code.",
|
|
107
177
|
"#",
|
|
108
178
|
"# Values:",
|
|
109
179
|
"# error - exit non-zero only when an error-severity finding fires (strictest gate).",
|
|
110
180
|
"# warning - exit non-zero on warning or error findings (advisory findings pass).",
|
|
111
181
|
"# advisory - exit non-zero on any finding at all (advisory, warning, or error).",
|
|
112
182
|
"# none - never exit non-zero from findings (use for raw reporting / baseline generation).",
|
|
113
|
-
"
|
|
183
|
+
"failOn:",
|
|
114
184
|
];
|
|
115
185
|
const entries: Array<[MinimumSeverityCommand, FailThreshold]> = [
|
|
116
186
|
["analyse", preserved.get("analyse") ?? "advisory"],
|
|
117
|
-
["summary", preserved.get("summary") ?? "
|
|
187
|
+
["summary", preserved.get("summary") ?? "none"],
|
|
118
188
|
["report", preserved.get("report") ?? "none"],
|
|
119
189
|
];
|
|
120
190
|
return [...header, ...entries.map(([command, severity]) => ` ${command}: ${severity}`)].join("\n");
|
|
121
191
|
}
|
|
122
192
|
|
|
123
193
|
/**
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
* is the incumbent. Refuses to clobber (no side effect) when ANY supported config file is present
|
|
127
|
-
* (the four-name precedence list in `DEFAULT_CONFIG_FILES`), not just `.gruff-ts.yaml` -
|
|
128
|
-
* otherwise `init` would silently create a higher-precedence file alongside an existing
|
|
129
|
-
* `.gruff.yaml` / `.gruff.yml` / `.gruff.json` and quietly change the effective config. When
|
|
130
|
-
* overwriting an existing `.gruff-ts.yaml`, the file's `paths.ignore` entries are preserved so
|
|
131
|
-
* `init --force` does not erase project-specific recursive-scan exclusions.
|
|
194
|
+
* Writes .gruff-ts.yaml when no supported config exists or force is enabled.
|
|
195
|
+
* Uses DEFAULT_CONFIG_FILES precedence so the caller can name the blocking file or carry its settings forward on a forced write.
|
|
132
196
|
*
|
|
133
|
-
* @param projectRoot
|
|
134
|
-
* @param shouldOverwrite
|
|
135
|
-
* @returns
|
|
136
|
-
* refusal is triggered by a non-canonical name, `path` points at that file so the caller's
|
|
137
|
-
* error message names the actual blocker.
|
|
197
|
+
* @param projectRoot - directory to search for the incumbent config and write the canonical file
|
|
198
|
+
* @param shouldOverwrite - allows a canonical write even when a supported config already exists
|
|
199
|
+
* @returns the incumbent path with exists when skipped, or the canonical path with written or overwritten after a write
|
|
138
200
|
*/
|
|
139
201
|
function writeDefaultConfig(projectRoot: string, shouldOverwrite: boolean): InitResult {
|
|
140
202
|
const targetPath = join(projectRoot, DEFAULT_CONFIG_FILE_NAME);
|
|
@@ -143,23 +205,22 @@ function writeDefaultConfig(projectRoot: string, shouldOverwrite: boolean): Init
|
|
|
143
205
|
return { path: existingConfigPath, status: "exists" };
|
|
144
206
|
}
|
|
145
207
|
const targetExists = existsSync(targetPath);
|
|
146
|
-
//
|
|
147
|
-
//
|
|
148
|
-
//
|
|
149
|
-
//
|
|
208
|
+
// Carry forward paths.ignore, command gates, and reviewed sensitive exclusions so a forced write preserves the selected scan policy.
|
|
209
|
+
//
|
|
210
|
+
// An existing alias can supply that policy when the project has no canonical file.
|
|
211
|
+
// If the existing settings cannot be read, regeneration uses defaults.
|
|
150
212
|
const preserved = existingConfigPath !== undefined ? readExistingPreservedConfig(existingConfigPath) : EMPTY_PRESERVED_CONFIG;
|
|
151
|
-
writeFileSync(targetPath, renderDefaultConfig(preserved.ignoredPaths, preserved.
|
|
213
|
+
writeFileSync(targetPath, renderDefaultConfig(preserved.ignoredPaths, preserved.failOn, preserved.sensitiveExclusions));
|
|
152
214
|
return { path: targetPath, status: targetExists ? "overwritten" : "written" };
|
|
153
215
|
}
|
|
154
216
|
|
|
155
|
-
|
|
156
|
-
* Recover
|
|
157
|
-
*
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
* is that curated entries survive when readable.
|
|
217
|
+
/**
|
|
218
|
+
* Recover ignore paths, command gates, and reviewed sensitive exclusions from an existing config file.
|
|
219
|
+
* Uses the permissive extractor so configs without schemaVersion can retain their readable settings.
|
|
220
|
+
* Read or parse failures silently return empty settings because forced regeneration permits replacing unreadable content.
|
|
221
|
+
*
|
|
222
|
+
* @param existingConfigPath - path to the incumbent config file to read and extract settings from
|
|
223
|
+
* @returns recovered preserved config settings, or empty settings if extraction throws
|
|
163
224
|
*/
|
|
164
225
|
function readExistingPreservedConfig(existingConfigPath: string): PreservedInitConfig {
|
|
165
226
|
try {
|
|
@@ -169,14 +230,19 @@ function readExistingPreservedConfig(existingConfigPath: string): PreservedInitC
|
|
|
169
230
|
}
|
|
170
231
|
}
|
|
171
232
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
233
|
+
/**
|
|
234
|
+
* Build the `paths` YAML section with guidance comments and configured ignore patterns.
|
|
235
|
+
* With no supplied exclusions, it emits an empty ignore list because discovery already applies built-in ignores.
|
|
236
|
+
*
|
|
237
|
+
* @param ignoredPaths - existing path exclusions preserved so user entries survive forced regeneration
|
|
238
|
+
* @returns YAML `paths:` block containing either `ignore: []` or JSON-quoted ignore list entries
|
|
239
|
+
*/
|
|
175
240
|
function renderPathsSection(ignoredPaths: readonly string[]): string {
|
|
176
241
|
const header = [
|
|
177
242
|
"paths:",
|
|
178
243
|
" # Recursive scans already respect .gitignore plus built-in default directories",
|
|
179
|
-
" # such as .git, node_modules, dist, coverage,
|
|
244
|
+
" # such as .git, node_modules, build, dist, coverage, and vendor.",
|
|
245
|
+
" # (.git, dist, and vendor are always skipped; node_modules, build, and coverage apply as fallback when no .gitignore governs.)",
|
|
180
246
|
" # Add project-specific generated or local outputs here when Git does not ignore them.",
|
|
181
247
|
" # Examples:",
|
|
182
248
|
" # - \"out/**\"",
|
|
@@ -193,53 +259,34 @@ function renderPathsSection(ignoredPaths: readonly string[]): string {
|
|
|
193
259
|
].join("\n");
|
|
194
260
|
}
|
|
195
261
|
|
|
196
|
-
|
|
197
|
-
|
|
262
|
+
/**
|
|
263
|
+
* Build the starter YAML naming allowlists, listing the default abbreviations accepted in identifiers.
|
|
264
|
+
* The other naming allowlists stay commented so users can discover them without changing defaults.
|
|
265
|
+
*
|
|
266
|
+
* @returns YAML `allowlists:` section with `acceptedAbbreviations` and commented optional settings
|
|
267
|
+
*/
|
|
198
268
|
function renderAllowlistsSection(): string {
|
|
199
269
|
return [
|
|
200
270
|
"allowlists:",
|
|
201
271
|
" # Abbreviations listed here are accepted in identifiers without a naming finding.",
|
|
202
272
|
" # Replace this list with the short terms reviewers accept in this project.",
|
|
203
273
|
" acceptedAbbreviations:",
|
|
204
|
-
// Each family term is visible so a user can review or replace the complete list in generated YAML.
|
|
205
274
|
...DEFAULT_ACCEPTED_ABBREVIATIONS.map((abbreviation) => ` - ${abbreviation}`),
|
|
206
|
-
" secretPreviews: []",
|
|
207
|
-
" # Names that trigger naming.generic-function. Each key replaces the built-in",
|
|
208
|
-
" # default when present; an empty list disables that rule's blacklist branch.",
|
|
209
|
-
" # Default: [process, handle, doit, run, execute, manage]",
|
|
210
|
-
" # bannedGenericNames: [process, handle, doit, run, execute, manage]",
|
|
211
|
-
" # Exact public/CLI/DTO boolean names accepted by naming.boolean-prefix.",
|
|
212
|
-
" # Default: [all, apply, check, dev, enabled, force, fresh, harness, json, ok, verbose, yes]",
|
|
213
|
-
" # acceptedBooleanNames: [all, apply, check, dev, enabled, force, fresh, harness, json, ok, verbose, yes]",
|
|
214
275
|
" # Exact fileBase:ClassName pairs accepted by naming.class-file-mismatch.",
|
|
215
276
|
" # Default: []",
|
|
216
277
|
" # acceptedClassFilePairs: [focusModeTranscript:TranscriptFocusController]",
|
|
217
|
-
" # Exact wire_name:internalName alias pairs accepted within one naming owner.",
|
|
218
|
-
" # Default: []",
|
|
219
|
-
" # acceptedCasingPairs: [note_id:noteId]",
|
|
220
|
-
" # Accepted prefixes for boolean identifiers. Names without one of these",
|
|
221
|
-
" # prefixes trigger naming.boolean-prefix.",
|
|
222
|
-
" # Default: [is, has, can, should, does, did, was, will, may, in, scan, supports, requires, allow, check, enable, exclude, include, omit, skip, with, without]",
|
|
223
|
-
" # booleanPrefixes: [is, has, can, should, does, did, was, will, may, in, scan, supports, requires, allow, check, enable, exclude, include, omit, skip, with, without]",
|
|
224
|
-
" # Hungarian type-style prefixes flagged by naming.hungarian-notation.",
|
|
225
|
-
" # Default: [str, obj, arr, bool, int, num]",
|
|
226
|
-
" # hungarianPrefixes: [str, obj, arr, bool, int, num]",
|
|
227
278
|
" # Placeholder words flagged as generic by naming.identifier-quality. The",
|
|
228
279
|
" # numbered-suffix branch (foo1, value2) stays active even when this is empty.",
|
|
229
280
|
" # Default: [foo, bar, baz, tmp, temp, thing, stuff, data, value, item]",
|
|
230
281
|
" # placeholderNames: [foo, bar, baz, tmp, temp, thing, stuff, data, value, item]",
|
|
231
|
-
" # Negative-framed boolean names that should NOT trigger naming.negative-boolean.",
|
|
232
|
-
" # Defaults are HTTP-header conventions; add project terms as needed.",
|
|
233
|
-
" # Default: [nostore, nofollow, noreferrer, noscript, noindex]",
|
|
234
|
-
" # negativeBooleanAllowed: [nostore, nofollow, noreferrer, noscript, noindex]",
|
|
235
|
-
" # Known acronyms whose mixed casings trigger naming.acronym-case. Stored",
|
|
236
|
-
" # case-insensitively; match is against canonical lowercase.",
|
|
237
|
-
" # Default: [url, http, https, id, xml, json, html, css, api, sql, db, io, ui, uuid, ip, tcp, udp, ast, cli, npm]",
|
|
238
|
-
" # knownAcronyms: [url, http, https, id, xml, json, html, css, api, sql, db, io, ui, uuid, ip, tcp, udp, ast, cli, npm]",
|
|
239
282
|
].join("\n");
|
|
240
283
|
}
|
|
241
284
|
|
|
242
|
-
|
|
285
|
+
/**
|
|
286
|
+
* Walk the rule registry in its canonical (sorted) order so the generated YAML is byte-stable.
|
|
287
|
+
*
|
|
288
|
+
* @returns YAML `rules:` section containing formatted entries for all registered rule descriptors
|
|
289
|
+
*/
|
|
243
290
|
function renderRulesSection(): string {
|
|
244
291
|
const lines = ["rules:"];
|
|
245
292
|
for (const descriptor of ruleDescriptors()) {
|
|
@@ -248,14 +295,18 @@ function renderRulesSection(): string {
|
|
|
248
295
|
return lines.join("\n");
|
|
249
296
|
}
|
|
250
297
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
298
|
+
/**
|
|
299
|
+
* Format YAML lines for a rule descriptor, including its description, id, and default enabled state.
|
|
300
|
+
* A numeric threshold adds threshold and severity; option fields come from RULE_OPTION_DEFAULTS when registered.
|
|
301
|
+
*
|
|
302
|
+
* @param descriptor - rule metadata entry from the registry to serialize
|
|
303
|
+
* @returns indented YAML comment and configuration lines for the rule
|
|
304
|
+
*/
|
|
254
305
|
function renderRuleEntry(descriptor: RuleDescriptor): string[] {
|
|
255
306
|
const lines: string[] = [];
|
|
256
307
|
lines.push(` # ${descriptor.pillar}/${descriptor.severity}: ${descriptor.description}`);
|
|
257
308
|
lines.push(` ${descriptor.ruleId}:`);
|
|
258
|
-
lines.push(
|
|
309
|
+
lines.push(` enabled: ${descriptor.isEnabledByDefault !== false}`);
|
|
259
310
|
if (typeof descriptor.threshold === "number") {
|
|
260
311
|
lines.push(` threshold: ${descriptor.threshold}`);
|
|
261
312
|
lines.push(` severity: ${descriptor.severity}`);
|
|
@@ -271,22 +322,18 @@ function renderRuleEntry(descriptor: RuleDescriptor): string[] {
|
|
|
271
322
|
}
|
|
272
323
|
|
|
273
324
|
/**
|
|
274
|
-
* Decide whether
|
|
325
|
+
* Decide whether analyse or summary may offer init when interaction is allowed and output is not suppressed.
|
|
326
|
+
* Requires no explicit config or opt-out, three TTY streams and no supported config file at the project root.
|
|
275
327
|
*
|
|
276
|
-
*
|
|
277
|
-
* user hasn't already opted in (--config) or out (--no-config) of config loading, all three
|
|
278
|
-
* standard streams are TTYs (stdin to type, stderr to display, stdout to confirm the run is not
|
|
279
|
-
* piping machine output to a downstream consumer), and no supported config file is already
|
|
280
|
-
* present at the project root.
|
|
281
|
-
*
|
|
282
|
-
* @param context CLI-collected state needed to make the decision.
|
|
328
|
+
* @param context - CLI flags, stream state and project root used to decide whether to prompt
|
|
283
329
|
* @returns Whether the prompt should be shown.
|
|
284
330
|
*/
|
|
285
331
|
function shouldPromptForInit(context: InitPromptContext): boolean {
|
|
286
332
|
if (!context.isInteractionAllowed) {
|
|
287
333
|
return false;
|
|
288
334
|
}
|
|
289
|
-
|
|
335
|
+
// Quiet runs and JSON, SARIF, GitHub or hotspot output never stop to ask, so automation reading stdout is not blocked.
|
|
336
|
+
if (context.isOutputSuppressed || context.isMachineFormat === true) {
|
|
290
337
|
return false;
|
|
291
338
|
}
|
|
292
339
|
if (context.shouldSkipConfig || context.hasExplicitConfig) {
|
|
@@ -299,13 +346,11 @@ function shouldPromptForInit(context: InitPromptContext): boolean {
|
|
|
299
346
|
}
|
|
300
347
|
|
|
301
348
|
/**
|
|
302
|
-
* Ask the user a yes/no question on stderr
|
|
303
|
-
*
|
|
304
|
-
* Defaults to "no" when the user just presses enter so the prompt is safe to dismiss. Reads from
|
|
305
|
-
* stdin; closes the readline interface in a finally so a Ctrl-C exits cleanly.
|
|
349
|
+
* Ask the user a yes/no question on stderr, reading stdin; empty or other answers mean no.
|
|
350
|
+
* The readline interface closes when the question settles.
|
|
306
351
|
*
|
|
307
|
-
* @param question
|
|
308
|
-
* @returns
|
|
352
|
+
* @param question - prompt text written to stderr verbatim
|
|
353
|
+
* @returns true for a trimmed, case-insensitive y or yes; false for other answers
|
|
309
354
|
*/
|
|
310
355
|
async function promptYesNo(question: string): Promise<boolean> {
|
|
311
356
|
const readlineInterface = createInterface({ input: process.stdin, output: process.stderr });
|