@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
package/src/rule-list.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
//
|
|
1
|
+
// Formats the CLI command catalogue, shell completion scripts (`bash`/`zsh`/`fish`), and `list-rules`/`list-profiles` output.
|
|
2
|
+
//
|
|
3
|
+
// Projects internal rule descriptors into the public cross-port listing shape used by CLI text and JSON consumers.
|
|
4
|
+
// Keeps command discovery, tab completion, and rule documentation backed by one source of truth.
|
|
2
5
|
import { VERSION } from "./constants.ts";
|
|
3
6
|
import { profileSummaries, type ProfileSummary } from "./profiles.ts";
|
|
4
7
|
import { ruleDescriptors } from "./rules.ts";
|
|
5
|
-
import type { RuleDescriptor } from "./types.ts";
|
|
8
|
+
import type { RuleDescriptor, Severity } from "./types.ts";
|
|
6
9
|
|
|
7
10
|
type RuleListFormat = "text" | "json";
|
|
8
11
|
type CompletionShell = "bash" | "fish" | "zsh";
|
|
@@ -20,6 +23,7 @@ const ANSI_RESET_FG = "\x1b[39m";
|
|
|
20
23
|
|
|
21
24
|
const CONSOLE_COMMANDS = [
|
|
22
25
|
{ name: "analyse", description: "Run gruff analysis." },
|
|
26
|
+
{ name: "check-ignore", description: "Report whether gruff would ignore each path, with the matching source and pattern. Runs no analysis." },
|
|
23
27
|
{ name: "completion", description: "Dump the shell completion script" },
|
|
24
28
|
{ name: "dashboard", description: "Serve the local gruff dashboard." },
|
|
25
29
|
{ name: "help", description: "Display help for a command" },
|
|
@@ -28,6 +32,7 @@ const CONSOLE_COMMANDS = [
|
|
|
28
32
|
{ name: "list", description: "List commands" },
|
|
29
33
|
{ name: "list-profiles", description: "List the built-in gruff profiles." },
|
|
30
34
|
{ name: "list-rules", description: "List gruff rule metadata." },
|
|
35
|
+
{ name: "migrate-config", description: "Rewrite a 0.5 config for the current schema, writing the result to a different file." },
|
|
31
36
|
{ name: "report", description: "Render a gruff report to stdout or a file." },
|
|
32
37
|
{
|
|
33
38
|
name: "summary",
|
|
@@ -36,12 +41,57 @@ const CONSOLE_COMMANDS = [
|
|
|
36
41
|
},
|
|
37
42
|
] as const;
|
|
38
43
|
|
|
39
|
-
//
|
|
40
|
-
//
|
|
44
|
+
// Cross-port threshold knob names for single-threshold rules (ratified M09 listing contract).
|
|
45
|
+
// Any rule without a family knob name publishes `{"threshold": N}` so no new permanent identifier is invented.
|
|
46
|
+
const LISTING_THRESHOLD_KNOB_NAMES: Readonly<Record<string, string>> = {
|
|
47
|
+
"complexity.cyclomatic": "maxComplexity",
|
|
48
|
+
"size.file-length": "maxLines",
|
|
49
|
+
"size.function-length": "maxLines",
|
|
50
|
+
"size.parameter-count": "maxParameters",
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// Public JSON projection emitted by `list-rules` (`id`, `defaultSeverity`, `defaultEnabled`, and named `thresholds`).
|
|
54
|
+
// Internal descriptors keep their native field names for reports, hooks, and config validation.
|
|
55
|
+
type ListedRule = Omit<RuleDescriptor, "ruleId" | "severity" | "isEnabledByDefault" | "threshold"> & {
|
|
56
|
+
id: string;
|
|
57
|
+
defaultSeverity: Severity;
|
|
58
|
+
defaultEnabled: boolean;
|
|
59
|
+
thresholds?: Record<string, number>;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Project one internal rule descriptor into a public listed record with deliberate field order:
|
|
64
|
+
* identity and scoring first, then defaultEnabled, an optional named threshold map, and remaining fields.
|
|
65
|
+
*
|
|
66
|
+
* @param descriptor - Internal rule descriptor whose fields are projected into the public record.
|
|
67
|
+
* @returns Public listed record with `defaultEnabled` defaulted to true when absent and `thresholds` omitted when no numeric threshold is set.
|
|
68
|
+
*/
|
|
69
|
+
function listedRule(descriptor: RuleDescriptor): ListedRule {
|
|
70
|
+
const { ruleId, pillar, severity, confidence, isEnabledByDefault, threshold, ...rest } = descriptor;
|
|
71
|
+
const knob = LISTING_THRESHOLD_KNOB_NAMES[ruleId] ?? "threshold";
|
|
72
|
+
return {
|
|
73
|
+
id: ruleId,
|
|
74
|
+
pillar,
|
|
75
|
+
defaultSeverity: severity,
|
|
76
|
+
confidence,
|
|
77
|
+
// Every record publishes the family field, so a rule that is on by default says so rather than leaving it absent.
|
|
78
|
+
defaultEnabled: isEnabledByDefault !== false,
|
|
79
|
+
...(typeof threshold === "number" ? { thresholds: { [knob]: threshold } } : {}),
|
|
80
|
+
...rest,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Render the full rule catalogue. JSON is the integration surface for docs and audits; text stays
|
|
86
|
+
* plain because it is only for terminal inspection and should not become another schema.
|
|
87
|
+
*
|
|
88
|
+
* @param format - Output format selecting either JSON with tool metadata and projected rules or plain text lines.
|
|
89
|
+
* @returns Newline-terminated rule catalogue string in the requested format.
|
|
90
|
+
*/
|
|
41
91
|
function renderRuleList(format: RuleListFormat): string {
|
|
42
92
|
const descriptors = ruleDescriptors();
|
|
43
93
|
if (format === "json") {
|
|
44
|
-
return `${JSON.stringify({ tool: { name: "gruff-ts", version: VERSION }, rules: descriptors }, null, 2)}\n`;
|
|
94
|
+
return `${JSON.stringify({ tool: { name: "gruff-ts", version: VERSION }, rules: descriptors.map(listedRule) }, null, 2)}\n`;
|
|
45
95
|
}
|
|
46
96
|
const lines = ["gruff-ts " + VERSION + ` rules (${descriptors.length})`, ""];
|
|
47
97
|
for (const descriptor of descriptors) {
|
|
@@ -52,9 +102,13 @@ function renderRuleList(format: RuleListFormat): string {
|
|
|
52
102
|
return `${lines.join("\n")}\n`;
|
|
53
103
|
}
|
|
54
104
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
105
|
+
/**
|
|
106
|
+
* Render the built-in profile catalogue. Mirrors renderRuleList: JSON is the integration surface for docs
|
|
107
|
+
* and audits, while text stays plain because it is only for terminal inspection and should not become a second schema.
|
|
108
|
+
*
|
|
109
|
+
* @param format - Output format selecting either JSON with tool metadata and profile summaries or plain text rows via profileListRow.
|
|
110
|
+
* @returns Newline-terminated profile catalogue string in the requested format.
|
|
111
|
+
*/
|
|
58
112
|
function renderProfileList(format: RuleListFormat): string {
|
|
59
113
|
const summaries = profileSummaries();
|
|
60
114
|
if (format === "json") {
|
|
@@ -64,39 +118,46 @@ function renderProfileList(format: RuleListFormat): string {
|
|
|
64
118
|
return `${[...header, ...summaries.map(profileListRow)].join("\n")}\n`;
|
|
65
119
|
}
|
|
66
120
|
|
|
67
|
-
|
|
68
|
-
|
|
121
|
+
/**
|
|
122
|
+
* Format one plain-text row for a profile with name, enabled/total rule count, pillar count,
|
|
123
|
+
* optional tightened-threshold count, and description. The tightened-threshold segment only appears for presets that set one.
|
|
124
|
+
*
|
|
125
|
+
* @param summary - Profile summary supplying counts, enabled pillars, and description text.
|
|
126
|
+
* @returns Single formatted text line for the profile.
|
|
127
|
+
*/
|
|
69
128
|
function profileListRow(summary: ProfileSummary): string {
|
|
70
129
|
const tightened = summary.tightenedThresholdCount > 0 ? ` | tightened thresholds: ${summary.tightenedThresholdCount}` : "";
|
|
71
130
|
return `${summary.name} | ${summary.enabledRuleCount}/${summary.totalRuleCount} rules | ${summary.enabledPillars.length} pillars${tightened} | ${summary.description}`;
|
|
72
131
|
}
|
|
73
132
|
|
|
74
|
-
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
133
|
+
/**
|
|
134
|
+
* Look up a registered rule by its exact, case-sensitive public ID for explain-mode rendering.
|
|
135
|
+
*
|
|
136
|
+
* @param ruleId - complete public rule ID to match
|
|
137
|
+
* @returns matching descriptor, or undefined when the ID is not registered
|
|
79
138
|
*/
|
|
80
139
|
function getRuleDescriptor(ruleId: string): RuleDescriptor | undefined {
|
|
81
140
|
return ruleDescriptors().find((descriptor) => descriptor.ruleId === ruleId);
|
|
82
141
|
}
|
|
83
142
|
|
|
84
|
-
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
* override
|
|
143
|
+
/**
|
|
144
|
+
* Show supported overrides because operators looking up a rule should be able to find its keys without opening src/config.ts.
|
|
145
|
+
*
|
|
146
|
+
* @param descriptor - Catalogue entry supplying the rule details and supported configuration and allowlist keys.
|
|
147
|
+
* @param format - Selects the labelled text card or the catalogue record with config keys and tool metadata in JSON.
|
|
148
|
+
* @returns The selected single-rule detail with a trailing newline. The threshold override appears only for a numeric threshold.
|
|
90
149
|
*/
|
|
91
150
|
function renderRuleDetail(descriptor: RuleDescriptor, format: RuleListFormat): string {
|
|
92
151
|
if (format === "json") {
|
|
93
|
-
return `${JSON.stringify({ tool: { name: "gruff-ts", version: VERSION }, rule: { ...descriptor, configKeys: ruleConfigKeys(descriptor) } }, null, 2)}\n`;
|
|
152
|
+
return `${JSON.stringify({ tool: { name: "gruff-ts", version: VERSION }, rule: { ...listedRule(descriptor), configKeys: ruleConfigKeys(descriptor) } }, null, 2)}\n`;
|
|
94
153
|
}
|
|
95
154
|
const lines = [
|
|
96
155
|
`Rule: ${descriptor.ruleId}`,
|
|
97
156
|
`Pillar: ${descriptor.pillar}`,
|
|
98
157
|
`Severity: ${descriptor.severity}`,
|
|
99
158
|
`Confidence: ${descriptor.confidence}`,
|
|
159
|
+
// The family's detail-card wording; a rule that ships off (ADR-021) runs only when a config enables it.
|
|
160
|
+
`Enabled by default: ${descriptor.isEnabledByDefault === false ? "no" : "yes"}`,
|
|
100
161
|
...(typeof descriptor.threshold === "number" ? [`Threshold: ${descriptor.threshold}`] : []),
|
|
101
162
|
"",
|
|
102
163
|
`Description: ${descriptor.description}`,
|
|
@@ -106,13 +167,20 @@ function renderRuleDetail(descriptor: RuleDescriptor, format: RuleListFormat): s
|
|
|
106
167
|
...ruleConfigKeyLines(descriptor),
|
|
107
168
|
...(descriptor.optionKeys && descriptor.optionKeys.length > 0 ? ["", "Options:", ...descriptor.optionKeys.map((key) => ` rules.${descriptor.ruleId}.options.${key}`)] : []),
|
|
108
169
|
...(descriptor.allowlistKeys && descriptor.allowlistKeys.length > 0 ? ["", "Allowlists:", ...descriptor.allowlistKeys.map((key) => ` allowlists.${key}`)] : []),
|
|
170
|
+
...(descriptor.falsePositiveShapes && descriptor.falsePositiveShapes.length > 0
|
|
171
|
+
? ["", "Known false positives:", ...descriptor.falsePositiveShapes.flatMap(({ shape, mitigation }) => [` ${shape}`, ` -> ${mitigation}`])]
|
|
172
|
+
: []),
|
|
109
173
|
];
|
|
110
174
|
return `${lines.join("\n")}\n`;
|
|
111
175
|
}
|
|
112
176
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
177
|
+
/**
|
|
178
|
+
* Build config-key text lines for a rule's enable and severity settings, plus a threshold line when
|
|
179
|
+
* numeric. Options and allowlists are rendered separately by renderRuleDetail.
|
|
180
|
+
*
|
|
181
|
+
* @param descriptor - Rule descriptor supplying the rule id and optional default numeric threshold.
|
|
182
|
+
* @returns Lines starting with a "Config keys:" heading followed by each applicable key and value type.
|
|
183
|
+
*/
|
|
116
184
|
function ruleConfigKeyLines(descriptor: RuleDescriptor): string[] {
|
|
117
185
|
return [
|
|
118
186
|
"Config keys:",
|
|
@@ -122,19 +190,28 @@ function ruleConfigKeyLines(descriptor: RuleDescriptor): string[] {
|
|
|
122
190
|
];
|
|
123
191
|
}
|
|
124
192
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
193
|
+
/**
|
|
194
|
+
* Build structured config-key entries for JSON consumers. An omitted enablement flag defaults to true,
|
|
195
|
+
* and a threshold entry appears only for a numeric threshold.
|
|
196
|
+
*
|
|
197
|
+
* @param descriptor - Rule descriptor supplying the rule id, enabled state, severity, and optional threshold.
|
|
198
|
+
* @returns Config-key descriptors naming each key, its type, and any applicable default or enum values.
|
|
199
|
+
*/
|
|
128
200
|
function ruleConfigKeys(descriptor: RuleDescriptor): Array<{ key: string; type: string; values?: readonly string[]; default?: number | boolean | string }> {
|
|
129
201
|
return [
|
|
130
|
-
{ key: `rules.${descriptor.ruleId}.enabled`, type: "bool", default:
|
|
202
|
+
{ key: `rules.${descriptor.ruleId}.enabled`, type: "bool", default: descriptor.isEnabledByDefault !== false },
|
|
131
203
|
{ key: `rules.${descriptor.ruleId}.severity`, type: "enum", values: ["advisory", "warning", "error"] as const, default: descriptor.severity },
|
|
132
204
|
...(typeof descriptor.threshold === "number" ? [{ key: `rules.${descriptor.ruleId}.threshold`, type: "int", default: descriptor.threshold }] : []),
|
|
133
205
|
];
|
|
134
206
|
}
|
|
135
207
|
|
|
136
|
-
|
|
137
|
-
|
|
208
|
+
/**
|
|
209
|
+
* Render the command catalogue shown for gruff-ts, gruff-ts list, and gruff-ts help.
|
|
210
|
+
* CLI callers supply their ANSI policy rather than detecting terminal capabilities in this renderer.
|
|
211
|
+
*
|
|
212
|
+
* @param shouldUseAnsi - Whether to colorize labels and headings with ANSI escapes; defaults to false for plain text.
|
|
213
|
+
* @returns Newline-terminated command usage, global options, and available commands listing.
|
|
214
|
+
*/
|
|
138
215
|
function renderConsoleList(shouldUseAnsi = false): string {
|
|
139
216
|
const listCommand = ansiWrap("list", ANSI_GREEN, shouldUseAnsi);
|
|
140
217
|
return [
|
|
@@ -157,8 +234,15 @@ function renderConsoleList(shouldUseAnsi = false): string {
|
|
|
157
234
|
].join("\n") + "\n";
|
|
158
235
|
}
|
|
159
236
|
|
|
160
|
-
|
|
161
|
-
|
|
237
|
+
/**
|
|
238
|
+
* Format an indented console listing row with padding computed from the uncolored label length.
|
|
239
|
+
*
|
|
240
|
+
* @param label - Command or option label displayed at the start of the row.
|
|
241
|
+
* @param description - Explanatory text appended after the separating padding.
|
|
242
|
+
* @param width - Minimum column width toward which the label is padded before the description.
|
|
243
|
+
* @param shouldUseAnsi - Whether to wrap the label in green ANSI foreground escapes.
|
|
244
|
+
* @returns Indented row with the label, at least one separating space, and the description.
|
|
245
|
+
*/
|
|
162
246
|
function formatConsoleRow(label: string, description: string, width: number, shouldUseAnsi: boolean): string {
|
|
163
247
|
const paddedLabel = ansiWrap(label, ANSI_GREEN, shouldUseAnsi);
|
|
164
248
|
const padding = " ".repeat(Math.max(1, width - label.length));
|
|
@@ -166,8 +250,15 @@ function formatConsoleRow(label: string, description: string, width: number, sho
|
|
|
166
250
|
return ` ${paddedLabel}${padding}${rowDescription}`;
|
|
167
251
|
}
|
|
168
252
|
|
|
169
|
-
|
|
170
|
-
|
|
253
|
+
/**
|
|
254
|
+
* Conditionally wrap text in an ANSI foreground color prefix and reset suffix.
|
|
255
|
+
* The caller supplies the color prefix and decides whether its output destination supports ANSI escapes.
|
|
256
|
+
*
|
|
257
|
+
* @param text - Plain text content to wrap or pass through unchanged.
|
|
258
|
+
* @param color - ANSI escape sequence prefix applied before the text when enabled.
|
|
259
|
+
* @param shouldUseAnsi - Whether to emit ANSI color escapes around the text.
|
|
260
|
+
* @returns Colored text with a foreground reset sequence when enabled, or the original text unchanged.
|
|
261
|
+
*/
|
|
171
262
|
function ansiWrap(text: string, color: string, shouldUseAnsi: boolean): string {
|
|
172
263
|
if (!shouldUseAnsi) {
|
|
173
264
|
return text;
|
|
@@ -176,8 +267,13 @@ function ansiWrap(text: string, color: string, shouldUseAnsi: boolean): string {
|
|
|
176
267
|
return `${ansiColor}${text}${ANSI_RESET_FG}`;
|
|
177
268
|
}
|
|
178
269
|
|
|
179
|
-
|
|
180
|
-
|
|
270
|
+
/**
|
|
271
|
+
* Generate a shell completion script for the requested shell, routing fish and zsh to dedicated
|
|
272
|
+
* renderers and defaulting all other values to Bash.
|
|
273
|
+
*
|
|
274
|
+
* @param shell - Target shell selector determining which completion renderer to invoke.
|
|
275
|
+
* @returns Rendered completion script text for the selected shell.
|
|
276
|
+
*/
|
|
181
277
|
function renderCompletionScript(shell: CompletionShell): string {
|
|
182
278
|
const context = completionContext();
|
|
183
279
|
if (shell === "fish") {
|
|
@@ -189,8 +285,12 @@ function renderCompletionScript(shell: CompletionShell): string {
|
|
|
189
285
|
return renderBashCompletion(context);
|
|
190
286
|
}
|
|
191
287
|
|
|
192
|
-
|
|
193
|
-
|
|
288
|
+
/**
|
|
289
|
+
* Assemble space-separated command names and global options for shell completion renderers.
|
|
290
|
+
* Help is excluded because Commander handles it implicitly; offering it here would put it alongside analyse.
|
|
291
|
+
*
|
|
292
|
+
* @returns Completion context containing space-joined subcommands and global CLI option flags.
|
|
293
|
+
*/
|
|
194
294
|
function completionContext(): CompletionContext {
|
|
195
295
|
return {
|
|
196
296
|
commands: CONSOLE_COMMANDS.filter((command) => command.name !== "help").map((command) => command.name).join(" "),
|
|
@@ -198,8 +298,13 @@ function completionContext(): CompletionContext {
|
|
|
198
298
|
};
|
|
199
299
|
}
|
|
200
300
|
|
|
201
|
-
|
|
202
|
-
|
|
301
|
+
/**
|
|
302
|
+
* Render a Fish completion script with file completion disabled so candidates come from the
|
|
303
|
+
* supplied command and option lists.
|
|
304
|
+
*
|
|
305
|
+
* @param context - Completion context holding space-separated subcommands and global option flags.
|
|
306
|
+
* @returns Newline-terminated Fish completion script registering subcommands and options for gruff-ts.
|
|
307
|
+
*/
|
|
203
308
|
function renderFishCompletion(context: CompletionContext): string {
|
|
204
309
|
return [
|
|
205
310
|
"complete -c gruff-ts -f",
|
|
@@ -209,8 +314,13 @@ function renderFishCompletion(context: CompletionContext): string {
|
|
|
209
314
|
].join("\n");
|
|
210
315
|
}
|
|
211
316
|
|
|
212
|
-
|
|
213
|
-
|
|
317
|
+
/**
|
|
318
|
+
* Render a Zsh completion script with a leading `#compdef` tag for completion discovery and
|
|
319
|
+
* `_arguments` state routing between subcommands and options.
|
|
320
|
+
*
|
|
321
|
+
* @param context - Completion context holding space-separated subcommands and global option flags.
|
|
322
|
+
* @returns Newline-terminated Zsh completion script defining `_gruff_ts`.
|
|
323
|
+
*/
|
|
214
324
|
function renderZshCompletion(context: CompletionContext): string {
|
|
215
325
|
return [
|
|
216
326
|
"#compdef gruff-ts",
|
|
@@ -228,8 +338,12 @@ function renderZshCompletion(context: CompletionContext): string {
|
|
|
228
338
|
].join("\n");
|
|
229
339
|
}
|
|
230
340
|
|
|
231
|
-
|
|
232
|
-
|
|
341
|
+
/**
|
|
342
|
+
* Render a Bash completion script registered with `complete -F`. The embedded `--format` and
|
|
343
|
+
* `--fail-on` value lists let the emitted script offer those values without loading the analyser.
|
|
344
|
+
*
|
|
345
|
+
* @returns Newline-terminated Bash completion script defining `_gruff_ts_completion`.
|
|
346
|
+
*/
|
|
233
347
|
function renderBashCompletion({ commands, options }: CompletionContext): string {
|
|
234
348
|
const commandsLine = ` commands=\"${commands}\"`;
|
|
235
349
|
const optionsLine = ` options=\"${options}\"`;
|
|
@@ -256,7 +370,13 @@ function renderBashCompletion({ commands, options }: CompletionContext): string
|
|
|
256
370
|
].join("\n");
|
|
257
371
|
}
|
|
258
372
|
|
|
259
|
-
|
|
373
|
+
/**
|
|
374
|
+
* Normalize a shell name to a supported completion target, selecting `"bash"` for any value
|
|
375
|
+
* other than exact `"fish"` or `"zsh"`.
|
|
376
|
+
*
|
|
377
|
+
* @param shellName - Raw shell name input to match against supported completion shells.
|
|
378
|
+
* @returns `"fish"` or `"zsh"` on an exact match, or `"bash"` otherwise.
|
|
379
|
+
*/
|
|
260
380
|
function completionShell(shellName: unknown): CompletionShell {
|
|
261
381
|
return shellName === "fish" || shellName === "zsh" ? shellName : "bash";
|
|
262
382
|
}
|