@blundergoat/gruff-ts 0.1.0 → 0.2.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.
Files changed (45) hide show
  1. package/CHANGELOG.md +35 -11
  2. package/CONTRIBUTING.md +3 -3
  3. package/README.md +141 -183
  4. package/docs/README.md +23 -0
  5. package/docs/ci-integration.md +63 -0
  6. package/docs/{CONFIGURATION.md → configuration.md} +41 -20
  7. package/docs/dashboard.md +36 -0
  8. package/docs/output-formats.md +65 -0
  9. package/docs/{RELEASING.md → releasing.md} +17 -14
  10. package/docs/{REPORTS_AND_CI.md → reports-and-ci.md} +5 -2
  11. package/docs/rules.md +177 -0
  12. package/package.json +2 -2
  13. package/scripts/bump-version.sh +83 -18
  14. package/scripts/dependency-install.sh +96 -0
  15. package/scripts/dependency-update.sh +177 -0
  16. package/scripts/preflight-checks.sh +38 -0
  17. package/src/analyser.ts +9 -24
  18. package/src/blocks.ts +66 -12
  19. package/src/class-rules.ts +5 -6
  20. package/src/cli-program.ts +216 -39
  21. package/src/cli.ts +4 -1
  22. package/src/comment-rules.ts +2 -0
  23. package/src/config-load-error.ts +18 -0
  24. package/src/config-preservation.ts +64 -0
  25. package/src/config.ts +155 -29
  26. package/src/constants.ts +10 -2
  27. package/src/dashboard.ts +1 -1
  28. package/src/dead-code-rules.ts +62 -16
  29. package/src/doc-rules.ts +3 -3
  30. package/src/findings-helpers.ts +17 -0
  31. package/src/init-config.ts +308 -0
  32. package/src/line-rules.ts +64 -12
  33. package/src/naming-pushers.ts +7 -32
  34. package/src/pillar-summary.ts +129 -0
  35. package/src/project-config-rules.ts +1 -1
  36. package/src/report-html.ts +404 -0
  37. package/src/report-renderers.ts +210 -406
  38. package/src/rule-list.ts +65 -1
  39. package/src/rules.ts +36 -37
  40. package/src/safety-rules.ts +9 -4
  41. package/src/scoring.ts +41 -9
  42. package/src/test-block-rules.ts +43 -1
  43. package/src/test-fixtures.ts +13 -7
  44. package/src/text-scans.ts +1 -152
  45. package/src/types.ts +32 -6
@@ -0,0 +1,96 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+
4
+ NPM_AUDIT_LEVEL="${NPM_AUDIT_LEVEL:-moderate}"
5
+ RUN_AUDIT=1
6
+ RUN_CHECK=0
7
+
8
+ usage() {
9
+ cat <<'USAGE'
10
+ Usage:
11
+ scripts/dependency-install.sh [options]
12
+
13
+ Installs dependencies from package-lock.json using npm ci.
14
+
15
+ Options:
16
+ --audit-level LEVEL npm audit threshold (default: moderate)
17
+ --no-audit Skip npm audit after install
18
+ --check Run npm run check after install and audit
19
+ --help, -h Show this help
20
+
21
+ Environment:
22
+ NPM_AUDIT_LEVEL Default audit threshold when --audit-level is omitted
23
+ USAGE
24
+ }
25
+
26
+ die() {
27
+ printf 'dependency-install: %s\n' "$*" >&2
28
+ exit 1
29
+ }
30
+
31
+ repo_root() {
32
+ local script_dir
33
+ script_dir="$(CDPATH='' cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
34
+ CDPATH='' cd -- "$script_dir/.." && pwd
35
+ }
36
+
37
+ parse_args() {
38
+ while [[ "$#" -gt 0 ]]; do
39
+ case "$1" in
40
+ --audit-level)
41
+ [[ "$#" -ge 2 ]] || die "--audit-level requires a value"
42
+ NPM_AUDIT_LEVEL="$2"
43
+ shift
44
+ ;;
45
+ --audit-level=*)
46
+ NPM_AUDIT_LEVEL="${1#*=}"
47
+ ;;
48
+ --no-audit)
49
+ RUN_AUDIT=0
50
+ ;;
51
+ --check)
52
+ RUN_CHECK=1
53
+ ;;
54
+ --help|-h)
55
+ usage
56
+ exit 0
57
+ ;;
58
+ *)
59
+ usage >&2
60
+ die "unknown option: $1"
61
+ ;;
62
+ esac
63
+ shift
64
+ done
65
+ }
66
+
67
+ require_tool() {
68
+ command -v "$1" >/dev/null 2>&1 || die "$1 is required"
69
+ }
70
+
71
+ main() {
72
+ parse_args "$@"
73
+ cd "$(repo_root)"
74
+
75
+ require_tool node
76
+ require_tool npm
77
+ [[ -f package.json ]] || die "package.json not found"
78
+ [[ -f package-lock.json ]] || die "package-lock.json not found"
79
+
80
+ echo "--- Install dependencies ---"
81
+ npm ci
82
+
83
+ if [[ "$RUN_AUDIT" -eq 1 ]]; then
84
+ echo ""
85
+ echo "--- Dependency audit ---"
86
+ npm audit --audit-level="$NPM_AUDIT_LEVEL"
87
+ fi
88
+
89
+ if [[ "$RUN_CHECK" -eq 1 ]]; then
90
+ echo ""
91
+ echo "--- TypeScript + tests ---"
92
+ npm run check
93
+ fi
94
+ }
95
+
96
+ main "$@"
@@ -0,0 +1,177 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+
4
+ NPM_AUDIT_LEVEL="${NPM_AUDIT_LEVEL:-moderate}"
5
+ DRY_RUN=0
6
+ LATEST=0
7
+ RUN_AUDIT=1
8
+ RUN_CHECK=1
9
+
10
+ usage() {
11
+ cat <<'USAGE'
12
+ Usage:
13
+ scripts/dependency-update.sh [options]
14
+
15
+ Updates npm dependencies, then verifies the result.
16
+
17
+ Default behavior:
18
+ - npm update
19
+ - npm audit --audit-level=moderate
20
+ - npm run check
21
+
22
+ Options:
23
+ --dry-run Show npm outdated output without changing files
24
+ --latest Update direct dependencies/devDependencies to @latest
25
+ --audit-level LEVEL npm audit threshold (default: moderate)
26
+ --no-audit Skip npm audit after update
27
+ --no-check Skip npm run check after update
28
+ --help, -h Show this help
29
+
30
+ Environment:
31
+ NPM_AUDIT_LEVEL Default audit threshold when --audit-level is omitted
32
+ USAGE
33
+ }
34
+
35
+ die() {
36
+ printf 'dependency-update: %s\n' "$*" >&2
37
+ exit 1
38
+ }
39
+
40
+ repo_root() {
41
+ local script_dir
42
+ script_dir="$(CDPATH='' cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
43
+ CDPATH='' cd -- "$script_dir/.." && pwd
44
+ }
45
+
46
+ parse_args() {
47
+ while [[ "$#" -gt 0 ]]; do
48
+ case "$1" in
49
+ --dry-run)
50
+ DRY_RUN=1
51
+ ;;
52
+ --latest)
53
+ LATEST=1
54
+ ;;
55
+ --audit-level)
56
+ [[ "$#" -ge 2 ]] || die "--audit-level requires a value"
57
+ NPM_AUDIT_LEVEL="$2"
58
+ shift
59
+ ;;
60
+ --audit-level=*)
61
+ NPM_AUDIT_LEVEL="${1#*=}"
62
+ ;;
63
+ --no-audit)
64
+ RUN_AUDIT=0
65
+ ;;
66
+ --no-check)
67
+ RUN_CHECK=0
68
+ ;;
69
+ --help|-h)
70
+ usage
71
+ exit 0
72
+ ;;
73
+ *)
74
+ usage >&2
75
+ die "unknown option: $1"
76
+ ;;
77
+ esac
78
+ shift
79
+ done
80
+ }
81
+
82
+ require_tool() {
83
+ command -v "$1" >/dev/null 2>&1 || die "$1 is required"
84
+ }
85
+
86
+ print_outdated() {
87
+ local output
88
+ local status
89
+
90
+ if output=$(npm outdated --long 2>&1); then
91
+ printf '%s\n' "$output"
92
+ echo "All dependencies are current within the configured ranges."
93
+ return 0
94
+ else
95
+ status=$?
96
+ fi
97
+
98
+ # npm outdated exits non-zero when it finds outdated dependencies.
99
+ if [[ -n "$output" ]]; then
100
+ printf '%s\n' "$output"
101
+ fi
102
+ if ((status == 1)); then
103
+ return 0
104
+ fi
105
+
106
+ return "$status"
107
+ }
108
+
109
+ read_direct_dependencies() {
110
+ local field="$1"
111
+ # Print one key per line, nothing for an empty section. `console.log(keys.join("\n"))` would
112
+ # emit a lone newline when the section is empty, and `mapfile -t` would then read a single
113
+ # empty element, causing the install loop below to run `npm install --save-prod @latest`.
114
+ node -e "const pkg = require('./package.json'); for (const key of Object.keys(pkg['$field'] || {})) console.log(key);"
115
+ }
116
+
117
+ install_latest_dependencies() {
118
+ local -a dependencies=()
119
+ local -a dev_dependencies=()
120
+ local dependency
121
+
122
+ mapfile -t dependencies < <(read_direct_dependencies dependencies)
123
+ mapfile -t dev_dependencies < <(read_direct_dependencies devDependencies)
124
+
125
+ if [[ "${#dependencies[@]}" -gt 0 ]]; then
126
+ for dependency in "${dependencies[@]}"; do
127
+ dependency="${dependency}@latest"
128
+ echo "Updating production dependency: $dependency"
129
+ npm install --save-prod "$dependency"
130
+ done
131
+ fi
132
+
133
+ if [[ "${#dev_dependencies[@]}" -gt 0 ]]; then
134
+ for dependency in "${dev_dependencies[@]}"; do
135
+ dependency="${dependency}@latest"
136
+ echo "Updating development dependency: $dependency"
137
+ npm install --save-dev "$dependency"
138
+ done
139
+ fi
140
+ }
141
+
142
+ main() {
143
+ parse_args "$@"
144
+ cd "$(repo_root)"
145
+
146
+ require_tool node
147
+ require_tool npm
148
+ [[ -f package.json ]] || die "package.json not found"
149
+ [[ -f package-lock.json ]] || die "package-lock.json not found"
150
+
151
+ if [[ "$DRY_RUN" -eq 1 ]]; then
152
+ echo "--- Outdated dependencies ---"
153
+ print_outdated
154
+ exit 0
155
+ fi
156
+
157
+ echo "--- Update dependencies ---"
158
+ if [[ "$LATEST" -eq 1 ]]; then
159
+ install_latest_dependencies
160
+ else
161
+ npm update
162
+ fi
163
+
164
+ if [[ "$RUN_AUDIT" -eq 1 ]]; then
165
+ echo ""
166
+ echo "--- Dependency audit ---"
167
+ npm audit --audit-level="$NPM_AUDIT_LEVEL"
168
+ fi
169
+
170
+ if [[ "$RUN_CHECK" -eq 1 ]]; then
171
+ echo ""
172
+ echo "--- TypeScript + tests ---"
173
+ npm run check
174
+ fi
175
+ }
176
+
177
+ main "$@"
@@ -33,6 +33,7 @@ FAILED=0
33
33
  FAILURES=()
34
34
  TMP_FILES=()
35
35
  START_TIME=$(date +%s%N)
36
+ NPM_AUDIT_LEVEL="${NPM_AUDIT_LEVEL:-moderate}"
36
37
 
37
38
  usage() {
38
39
  cat <<'USAGE'
@@ -40,12 +41,15 @@ Usage:
40
41
  scripts/preflight-checks.sh
41
42
 
42
43
  Runs the local preflight gate:
44
+ - version surfaces (package.json, package-lock.json, src/constants.ts, CHANGELOG.md) agree
45
+ - npm dependency audit
43
46
  - npm run check (TypeScript compile plus unit tests)
44
47
  - gruff-ts full-project scan
45
48
  - shellcheck for scripts/*.sh when shellcheck is installed
46
49
 
47
50
  Environment:
48
51
  GRUFF_TS_FAIL_ON gruff-ts severity that fails static analysis (default: advisory)
52
+ NPM_AUDIT_LEVEL npm audit threshold (default: moderate)
49
53
  USAGE
50
54
  }
51
55
 
@@ -176,6 +180,36 @@ make_temp_file() {
176
180
  printf '%s\n' "$temp_file"
177
181
  }
178
182
 
183
+ version_consistency_check() {
184
+ local output
185
+ local status
186
+
187
+ output=$(bash scripts/bump-version.sh --check 2>&1)
188
+ status=$?
189
+ if ((status != 0)); then
190
+ printf '%s\n' "$output"
191
+ return "$status"
192
+ fi
193
+ printf '%s' "$output"
194
+ }
195
+
196
+ npm_audit_check() {
197
+ local output
198
+ local status
199
+ local summary
200
+
201
+ output=$(npm audit --audit-level="$NPM_AUDIT_LEVEL" 2>&1)
202
+ status=$?
203
+ if ((status != 0)); then
204
+ printf '%s\n' "$output"
205
+ return "$status"
206
+ fi
207
+
208
+ summary=$(printf '%s\n' "$output" | awk '/found .* vulnerabilities|audited .* packages/ { line = $0 } END { print line }')
209
+ printf '%s' "${summary:-completed}"
210
+ return 0
211
+ }
212
+
179
213
  npm_check() {
180
214
  local output
181
215
  local status
@@ -340,6 +374,10 @@ main() {
340
374
  return 127
341
375
  fi
342
376
 
377
+ run_step "Version consistency" version_consistency_check
378
+
379
+ run_step "Dependency audit" npm_audit_check
380
+
343
381
  run_step "TypeScript + tests" npm_check
344
382
 
345
383
  run_step "Gruff full-project scan" gruff_ts_check
package/src/analyser.ts CHANGED
@@ -1,6 +1,6 @@
1
- // Analyser pipeline: walks discovered sources, runs every rule pass (size, complexity, dead-code,
2
- // waste, naming, documentation, modernisation, security, sensitive-data, test-quality, design),
3
- // aggregates findings into the `gruff.analysis.v1` schema, and exposes `analyse` to the CLI shell.
1
+ // Analyser pipeline: walks discovered sources, runs every rule pass (complexity, dead-code, design,
2
+ // documentation, maintainability, modernisation, naming, security, sensitive-data, size, test-quality),
3
+ // aggregates findings into the `gruff.analysis.v2` schema, and exposes `analyse` to the CLI shell.
4
4
  import { existsSync, readFileSync } from "node:fs";
5
5
  import { cwd } from "node:process";
6
6
  import { basename, join } from "node:path";
@@ -18,18 +18,17 @@ import { analyseDeadCode, analyseUnreachable, analyseUnusedImports } from "./dea
18
18
  import { analyseCommentQualityRules } from "./comment-rules.ts";
19
19
  import { analyseDocRules, analyseFileOverviewDoc, analyseInterfaceDocs } from "./doc-rules.ts";
20
20
  import { analyseLineRules } from "./line-rules.ts";
21
- import { pushAbbreviationAt, pushBooleanPrefixAt, pushIdentifierQualityAt, pushNegativeBooleanAt, pushShortVariableAt } from "./naming-pushers.ts";
21
+ import { pushBooleanPrefixAt, pushIdentifierQualityAt, pushNegativeBooleanAt, pushShortVariableAt } from "./naming-pushers.ts";
22
22
  import { analyseTestBlock } from "./test-block-rules.ts";
23
23
  import { analyseGithubActionsRules } from "./github-actions-rules.ts";
24
24
  import { analyseProjectConfigRules } from "./project-config-rules.ts";
25
25
  import { scoreReport, summarize } from "./scoring.ts";
26
26
  import { analyseSensitiveData } from "./sensitive-data-rules.ts";
27
27
  import { maskNonCode, maskTemplateLiteralBodies, parseDiagnostics } from "./source-text.ts";
28
- import { todoMarkerSummary } from "./text-scans.ts";
29
28
  import type { AnalysisOptions, AnalysisReport, Config, Finding, RunDiagnostic } from "./types.ts";
30
29
 
31
30
  /**
32
- * Analyse the configured paths and return the stable gruff.analysis.v1 report contract.
31
+ * Analyse the configured paths and return the stable gruff.analysis.v2 report contract.
33
32
  *
34
33
  * @param options Normalised analysis options from the CLI or direct callers.
35
34
  * @returns Versioned report with fingerprinted findings, diagnostics, paths, and score data.
@@ -65,7 +64,7 @@ function buildAnalysisReport(
65
64
  ): AnalysisReport {
66
65
  const findings = baselineResult.findings;
67
66
  return {
68
- schemaVersion: "gruff.analysis.v1",
67
+ schemaVersion: "gruff.analysis.v2",
69
68
  tool: { name: "gruff-ts", version: VERSION },
70
69
  run: {
71
70
  projectRoot,
@@ -103,7 +102,7 @@ interface SourceScanResult {
103
102
 
104
103
  /*
105
104
  * Result of applying a baseline (suppression) or generating a new one. The optional `baseline`
106
- * matches the `gruff.analysis.v1` schema's baseline metadata - present only when a baseline file
105
+ * matches the `gruff.analysis.v2` schema's baseline metadata - present only when a baseline file
107
106
  * was actually used or generated, so the report stays stable across baseline-disabled runs.
108
107
  */
109
108
  interface BaselineApplication {
@@ -308,18 +307,6 @@ function analyseTextRules(file: SourceFile, source: string, config: Config, find
308
307
  }
309
308
  }
310
309
 
311
- /*
312
- * Opt-in by default per M38 (.goat-flow/tasks/0.1/M38-css-metrics-and-todo-density-calibration.md):
313
- * raw marker density produced too many false positives in other gruff projects; prefer the
314
- * context-aware docs.todo-without-tracking rule when task-marker scanning matters.
315
- */
316
- if (config.rules.get("docs.todo-density")?.enabled === true) {
317
- const todoMarkers = todoMarkerSummary(source, file.isScript);
318
- if (todoMarkers.count >= threshold(config, "docs.todo-density", 4)) {
319
- findings.push(finding({ ruleId: "docs.todo-density", message: `File contains ${todoMarkers.count} TODO/FIXME markers.`, file, line: todoMarkers.firstLine, severity: ruleSeverity(config, "docs.todo-density", "advisory"), pillar: "documentation" }));
320
- }
321
- }
322
-
323
310
  analyseSensitiveData(file, source, config, findings);
324
311
  analyseGithubActionsRules(file, source, findings);
325
312
  analyseProjectConfigRules(file, source, findings);
@@ -390,9 +377,8 @@ function analyseBlocks(file: SourceFile, blocks: FunctionBlock[], config: Config
390
377
  }
391
378
 
392
379
  /*
393
- * Per-parameter naming-rule fanout. Each parameter is checked for short-name / opaque-abbreviation
394
- * / placeholder forms; typed booleans get the extra prefix and negative-name checks. Reports findings
395
- * to the shared sink.
380
+ * Per-parameter naming-rule fanout. Each parameter is checked for short-name / placeholder forms;
381
+ * typed booleans get the extra prefix and negative-name checks. Reports findings to the shared sink.
396
382
  */
397
383
  function pushParameterNamingFindings(context: BlockRuleContext): void {
398
384
  const line = context.block.declarationLine;
@@ -400,7 +386,6 @@ function pushParameterNamingFindings(context: BlockRuleContext): void {
400
386
  for (const parameter of params) {
401
387
  pushShortVariableAt(context.file, line, parameter.name, context.config, context.findings, "parameter");
402
388
  pushIdentifierQualityAt(context.file, line, parameter.name, context.config, context.findings, "parameter");
403
- pushAbbreviationAt(context.file, line, parameter.name, context.config, context.findings, "parameter");
404
389
  if (isBooleanParameter(parameter.raw)) {
405
390
  pushBooleanPrefixAt(context.file, line, parameter.name, context.config, context.findings, "parameter");
406
391
  pushNegativeBooleanAt(context.file, line, parameter.name, context.config, context.findings, "parameter");
package/src/blocks.ts CHANGED
@@ -22,17 +22,27 @@ export interface FunctionBlock {
22
22
  body: string;
23
23
  codeBody: string;
24
24
  isPublic: boolean;
25
+ // True when the function declaration line itself starts with `export`. Distinct from `isPublic`,
26
+ // which also matches class `public` modifiers - exports are the top-level API surface, while a
27
+ // public class method is internal to an exported (or unexported) class. The doc rule splits
28
+ // severity on this distinction: exported functions warrant warning-tier doc requirements,
29
+ // internal helpers stay advisory.
30
+ isExported: boolean;
25
31
  isTest: boolean;
26
32
  hasLeadingComment: boolean;
27
33
  declarationLine: number;
28
34
  }
29
35
 
30
36
  // Working state for the function-block parser. Patterns are precompiled once per file so each
31
- // callable detection doesn't re-instantiate the same RegExp objects.
37
+ // callable detection doesn't re-instantiate the same RegExp objects. `reExportedNames` carries
38
+ // the file-level scan of `export { foo }` / `export default foo` so a declaration like
39
+ // `function foo() {}` later re-exported via `export { foo }` is still classified as exported
40
+ // (the line-local `^export` check alone would miss this common pattern).
32
41
  interface FunctionBlockScan {
33
42
  lines: string[];
34
43
  codeLines: string[];
35
44
  patterns: RegExp[];
45
+ reExportedNames: ReadonlySet<string>;
36
46
  }
37
47
 
38
48
  const FUNCTION_BLOCK_PATTERNS = functionBlockPatterns();
@@ -208,12 +218,20 @@ function pushGenericFunctionFinding(context: BlockRuleContext): void {
208
218
  }
209
219
  }
210
220
 
211
- // Every non-test function must carry a leading comment. Test blocks are exempted because their
212
- // `test("name", …)` description already documents intent. Reports `docs.missing-function-doc`.
221
+ /*
222
+ * Every non-test function must carry a leading comment. Test blocks are exempted because their
223
+ * `test("name", …)` description already documents intent. Reports
224
+ * `docs.missing-exported-function-doc` (warning, higher cost of omission on the public API
225
+ * surface) when `isExported` is true, `docs.missing-internal-function-doc` (advisory) otherwise.
226
+ */
213
227
  function pushMissingFunctionDocFinding(context: BlockRuleContext): void {
214
- if (!context.block.isTest && !context.block.hasLeadingComment) {
215
- context.findings.push(blockFinding({ ruleId: "docs.missing-function-doc", message: `Function \`${context.block.name}\` is missing a leading maintainer comment.`, file: context.file, block: context.block, severity: "advisory", pillar: "documentation" }));
228
+ if (context.block.isTest || context.block.hasLeadingComment) {
229
+ return;
216
230
  }
231
+ const ruleId = context.block.isExported ? "docs.missing-exported-function-doc" : "docs.missing-internal-function-doc";
232
+ const severity = context.block.isExported ? "warning" : "advisory";
233
+ const audience = context.block.isExported ? "exported" : "internal";
234
+ context.findings.push(blockFinding({ ruleId, message: `${audience === "exported" ? "Exported" : "Internal"} function \`${context.block.name}\` is missing a leading maintainer comment.`, file: context.file, block: context.block, severity, pillar: "documentation" }));
217
235
  }
218
236
 
219
237
  // Empty bodies are sometimes intentional placeholders, hence the advisory severity rather than
@@ -223,7 +241,7 @@ function pushEmptyFunctionFinding(context: BlockRuleContext): void {
223
241
  return;
224
242
  }
225
243
  if (isEmptyFunctionBody(context.block.codeBody)) {
226
- context.findings.push(blockFinding({ ruleId: "waste.empty-function", message: `Function \`${context.block.name}\` has no executable body.`, file: context.file, block: context.block, severity: "advisory", pillar: "waste" }));
244
+ context.findings.push(blockFinding({ ruleId: "waste.empty-function", message: `Function \`${context.block.name}\` has no executable body.`, file: context.file, block: context.block, severity: "advisory", pillar: "maintainability" }));
227
245
  }
228
246
  }
229
247
 
@@ -287,7 +305,7 @@ function unusedParameterFinding(context: BlockRuleContext, parameterName: string
287
305
  filePath: context.file.displayPath,
288
306
  line: context.block.startLine,
289
307
  severity: "advisory",
290
- pillar: "waste",
308
+ pillar: "maintainability",
291
309
  confidence: "medium",
292
310
  symbol: context.block.name,
293
311
  remediation: "Remove the parameter or prefix it with _ if it is intentionally unused.",
@@ -306,7 +324,7 @@ function pushRedundantVariableFindings(context: BlockRuleContext): void {
306
324
  filePath: context.file.displayPath,
307
325
  line: context.block.startLine + redundant.lineOffset,
308
326
  severity: "advisory",
309
- pillar: "waste",
327
+ pillar: "maintainability",
310
328
  confidence: "medium",
311
329
  symbol: redundant.name,
312
330
  remediation: "Return the expression directly.",
@@ -327,7 +345,7 @@ function pushUselessReturnFindings(context: BlockRuleContext): void {
327
345
  filePath: context.file.displayPath,
328
346
  line: context.block.startLine + lineOffset,
329
347
  severity: "advisory",
330
- pillar: "waste",
348
+ pillar: "maintainability",
331
349
  confidence: "medium",
332
350
  symbol: context.block.name,
333
351
  remediation: "Remove the final return statement.",
@@ -453,6 +471,7 @@ export function functionBlocks(source: string, codeSource = source): FunctionBlo
453
471
  lines: source.split(/\r?\n/),
454
472
  codeLines: codeSource.split(/\r?\n/),
455
473
  patterns: FUNCTION_BLOCK_PATTERNS,
474
+ reExportedNames: collectReExportedNames(codeSource),
456
475
  };
457
476
  const blocks: FunctionBlock[] = [];
458
477
  scan.codeLines.forEach((line, index) => {
@@ -465,15 +484,49 @@ export function functionBlocks(source: string, codeSource = source): FunctionBlo
465
484
  return blocks;
466
485
  }
467
486
 
487
+ /*
488
+ * File-level scan for re-exported local declarations. Matches `export { foo }`, `export { foo as
489
+ * bar }` (the local name `foo` is recorded, not the renamed `bar`), and `export default foo`
490
+ * (bare-identifier form - `export default function ...` is matched via pattern 2 in
491
+ * functionBlockPatterns instead, then classified exported because the line itself starts with
492
+ * `export`). Re-export-from clauses (`export { foo } from "./other"`) are intentionally skipped
493
+ * via the negative lookahead: those names are not local declarations of this file, so promoting
494
+ * a same-named local to "exported" would emit a false missing-public-doc finding.
495
+ *
496
+ * Operates on the masked codeSource so `export { foo }` inside a string literal or comment is
497
+ * skipped. Multi-line export blocks work because `[^}]+` spans newlines, and the lookahead
498
+ * spans whitespace and blanked-comment runs that the masker collapses to spaces.
499
+ */
500
+ function collectReExportedNames(codeSource: string): ReadonlySet<string> {
501
+ const names = new Set<string>();
502
+ for (const match of codeSource.matchAll(/export\s*\{([^}]+)\}(?!\s*from\b)/g)) {
503
+ for (const entry of (match[1] ?? "").split(",")) {
504
+ const local = entry.trim().split(/\s+as\s+/)[0]?.trim();
505
+ if (local && /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(local)) {
506
+ names.add(local);
507
+ }
508
+ }
509
+ }
510
+ for (const match of codeSource.matchAll(/^\s*export\s+default\s+([A-Za-z_$][A-Za-z0-9_$]*)\s*;?\s*$/gm)) {
511
+ if (match[1]) {
512
+ names.add(match[1]);
513
+ }
514
+ }
515
+ return names;
516
+ }
517
+
468
518
  // Four callable shapes in the order `functionBlockMatch` tries them: `test()` / `it()` bodies,
469
519
  // `function` declarations, class methods, and arrow assignments. Pattern[0] is intentionally
470
- // first because test bodies must match before the generic arrow pattern claims them.
520
+ // first because test bodies must match before the generic arrow pattern claims them. Pattern[1]
521
+ // accepts an optional `default` after `export` so `export default function foo() {}` parses into
522
+ // a FunctionBlock - the CHANGELOG's exported-doc-rule contract advertises that shape and the
523
+ // missing `default` token previously made those declarations invisible to every block-level rule.
471
524
  function functionBlockPatterns(): RegExp[] {
472
525
  return [
473
526
  /^\s*(?:test|it)\s*\(\s*["'`]([^"'`]+)["'`]\s*,\s*(?:async\s*)?\(([^)]*)\)\s*=>/,
474
- /^\s*(?:export\s+)?(?:async\s+)?function\s+([A-Za-z_$][A-Za-z0-9_$]*)\s*\(([^)]*)\)/,
527
+ /^\s*(?:export\s+(?:default\s+)?)?(?:async\s+)?function\s+([A-Za-z_$][A-Za-z0-9_$]*)\s*\(([^)]*)\)/,
475
528
  /^\s*(?:public|private|protected)?\s*(?:async\s+)?([A-Za-z_$][A-Za-z0-9_$]*)\s*\(([^)]*)\)\s*[:{]/,
476
- /^\s*(?:const|let)\s+([A-Za-z_$][A-Za-z0-9_$]*)\s*=\s*(?:async\s*)?\(([^)]*)\)\s*=>/,
529
+ /^\s*(?:export\s+)?(?:const|let)\s+([A-Za-z_$][A-Za-z0-9_$]*)\s*=\s*(?:async\s*)?\(([^)]*)\)\s*=>/,
477
530
  ];
478
531
  }
479
532
 
@@ -523,6 +576,7 @@ function functionBlockFromMatch(scan: FunctionBlockScan, match: RegExpMatchArray
523
576
  body,
524
577
  codeBody,
525
578
  isPublic: /\bexport\b|\bpublic\b/.test(scan.codeLines.slice(start, index + 1).join("\n")),
579
+ isExported: /^\s*export\b/.test(scan.codeLines[index] ?? "") || scan.reExportedNames.has(match[1] ?? ""),
526
580
  isTest: isTestInvocationLine(scan.codeLines[index] ?? ""),
527
581
  hasLeadingComment: hasLeadingCommentBeforeLines(scan.lines, index + 1),
528
582
  declarationLine: index + 1,
@@ -7,7 +7,7 @@ import { type ExportedDeclaration, exportedDeclarations, pushMissingPublicDocFin
7
7
  import { type SourceFile } from "./discovery.ts";
8
8
  import { makeFinding } from "./findings.ts";
9
9
  import { fileBaseName, finding, normalizedIdentifier } from "./findings-helpers.ts";
10
- import { pushAbbreviationAt, pushBooleanPrefixAt, pushNegativeBooleanAt } from "./naming-pushers.ts";
10
+ import { pushBooleanPrefixAt, pushNegativeBooleanAt } from "./naming-pushers.ts";
11
11
  import { byteLine } from "./text-scans.ts";
12
12
  import type { Config, Finding } from "./types.ts";
13
13
 
@@ -46,7 +46,7 @@ export function collectDeclaredIdentifiers(source: string, codeSource: string, b
46
46
  }
47
47
 
48
48
  // Walks every interface body line and matches the field declaration regex. Used both for the
49
- // naming inventory (above) and for the per-field interface rules (boolean prefix, abbreviation).
49
+ // naming inventory (above) and for the per-field interface rules (boolean prefix, negative-boolean).
50
50
  function collectInterfaceFieldDeclarations(source: string, codeSource: string): DeclaredIdentifier[] {
51
51
  const fieldRegex = /^[ \t]*(?:readonly\s+)?([A-Za-z_$][A-Za-z0-9_$]*)\??\s*:/;
52
52
  const out: DeclaredIdentifier[] = [];
@@ -190,9 +190,9 @@ function isFixtureIdentifier(name: string): boolean {
190
190
  }
191
191
 
192
192
  /*
193
- * Walks every interface field and runs three checks per field: abbreviation, boolean prefix,
194
- * negative boolean. The stable ordering matches `pushAbbreviationAt` → `pushBooleanPrefixAt` →
195
- * `pushNegativeBooleanAt` so multiple findings on one field surface in a deterministic sequence.
193
+ * Walks every interface field and runs two checks per boolean field: boolean prefix and
194
+ * negative boolean. The stable ordering matches `pushBooleanPrefixAt` → `pushNegativeBooleanAt`
195
+ * so multiple findings on one field surface in a deterministic sequence.
196
196
  */
197
197
  export function analyseInterfaceFields(file: SourceFile, source: string, codeSource: string, config: Config, findings: Finding[]): void {
198
198
  const fieldRegex = /^[ \t]*(?:readonly\s+)?([A-Za-z_$][A-Za-z0-9_$]*)\??\s*:\s*([^;]+)/;
@@ -200,7 +200,6 @@ export function analyseInterfaceFields(file: SourceFile, source: string, codeSou
200
200
  const match = sourceLine.match(fieldRegex);
201
201
  const name = match?.[1] ?? "";
202
202
  if (!name) continue;
203
- pushAbbreviationAt(file, lineIndex + 1, name, config, findings, "interface-field");
204
203
  if (/^\s*boolean\b/.test(match?.[2] ?? "")) {
205
204
  pushBooleanPrefixAt(file, lineIndex + 1, name, config, findings, "interface-field");
206
205
  pushNegativeBooleanAt(file, lineIndex + 1, name, config, findings, "interface-field");