@blundergoat/gruff-ts 0.1.1 → 0.3.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 (52) hide show
  1. package/CHANGELOG.md +55 -19
  2. package/README.md +103 -35
  3. package/docs/README.md +2 -0
  4. package/docs/agent-hook.md +80 -0
  5. package/docs/ci-integration.md +16 -0
  6. package/docs/configuration.md +60 -3
  7. package/docs/dashboard.md +7 -0
  8. package/docs/output-formats.md +11 -1
  9. package/docs/philosophy.md +21 -0
  10. package/docs/releasing.md +12 -11
  11. package/docs/reports-and-ci.md +5 -2
  12. package/docs/rules.md +24 -15
  13. package/package.json +5 -5
  14. package/scripts/bump-version.sh +20 -4
  15. package/scripts/preflight-checks.sh +4 -41
  16. package/src/analyser.ts +47 -34
  17. package/src/blocks.ts +82 -75
  18. package/src/changed-regions.ts +390 -0
  19. package/src/check-ignore.ts +49 -0
  20. package/src/class-rules.ts +80 -33
  21. package/src/cli-program.ts +209 -51
  22. package/src/comment-rules.ts +4 -0
  23. package/src/config-load-error.ts +18 -0
  24. package/src/config-parse.ts +458 -0
  25. package/src/config-preservation.ts +64 -0
  26. package/src/config.ts +311 -428
  27. package/src/constants.ts +10 -2
  28. package/src/context-doc-rules.ts +2 -4
  29. package/src/dashboard.ts +8 -5
  30. package/src/dead-code-rules.ts +60 -14
  31. package/src/discovery.ts +88 -32
  32. package/src/doc-rules.ts +3 -3
  33. package/src/findings-helpers.ts +58 -5
  34. package/src/fixtures/rule-catalogue-security-doctrine.ts +28 -0
  35. package/src/init-config.ts +94 -31
  36. package/src/line-rules.ts +58 -4
  37. package/src/naming-pushers.ts +42 -7
  38. package/src/pillar-summary.ts +129 -0
  39. package/src/profiles.ts +232 -0
  40. package/src/project-config-rules.ts +5 -5
  41. package/src/project-rules.ts +2 -1
  42. package/src/report-html.ts +404 -0
  43. package/src/report-renderers.ts +210 -397
  44. package/src/rule-list.ts +85 -1
  45. package/src/rules.ts +28 -27
  46. package/src/safety-rules.ts +22 -7
  47. package/src/scoring.ts +78 -8
  48. package/src/security-flow-rules.ts +533 -0
  49. package/src/sensitive-data-rules.ts +138 -2
  50. package/src/test-block-rules.ts +140 -7
  51. package/src/test-fixtures.ts +59 -13
  52. package/src/types.ts +108 -5
package/src/types.ts CHANGED
@@ -24,35 +24,108 @@ export type OutputFormat = "text" | "json" | "html" | "markdown" | "github" | "h
24
24
  /** Minimum severity that causes a non-zero CLI exit. */
25
25
  export type FailThreshold = "none" | "advisory" | "warning" | "error";
26
26
 
27
+ /** Changed-region filter precision for diff-aware analysis. */
28
+ export type ChangedScopeMode = "symbol" | "hunk";
29
+
27
30
  /** Public options contract consumed by the analyzer core and CLI. */
28
31
  export interface AnalysisOptions {
29
32
  paths: string[];
30
33
  config?: string;
34
+ /**
35
+ * Named built-in profile (`gruff.minimal` / `gruff.recommended` / `gruff.strict`) or a path to a
36
+ * profile file, from the `--profile` CLI flag. Wins over a config-file `profile:` block. Absent
37
+ * means "fall back to the config-file profile, else the default `recommended` (a no-op delta)".
38
+ */
39
+ profile?: string;
31
40
  shouldSkipConfig: boolean;
32
41
  format: OutputFormat;
33
42
  failOn: FailThreshold;
34
43
  shouldIncludeIgnored: boolean;
35
44
  diff?: string;
45
+ since?: string;
46
+ changedRanges?: string;
47
+ changedScope: ChangedScopeMode;
48
+ diffPatch?: string;
36
49
  historyFile?: string;
37
50
  baseline?: string;
38
51
  generateBaseline?: string;
39
52
  shouldSkipBaseline: boolean;
40
53
  }
41
54
 
42
- /** Loaded analyzer configuration derived from optional gruff config files. */
55
+ /** Command keys that participate in the `minimumSeverity:` config block. `dashboard` is omitted on purpose - it has no `--fail-on` flag and accepting it as a key would silently no-op. See ADR-004. */
56
+ export type MinimumSeverityCommand = "analyse" | "summary" | "report";
57
+
58
+ /**
59
+ * Loaded analyzer configuration derived from optional gruff config files. The schema invariant is
60
+ * that `schemaVersion` is fixed at the supported version and every field has a defined default in
61
+ * `defaultConfig()` so consumers can rely on the shape without per-field guards.
62
+ */
43
63
  export interface Config {
64
+ /**
65
+ * Required top-level config-schema version. Pre-1.0 break: every `.gruff-ts.yaml` must declare
66
+ * `schemaVersion: gruff-ts.config.v0.1` or loading throws. Lives in the `gruff-ts.config.*`
67
+ * namespace, distinct from the output schemas (`gruff.analysis.v2`, etc.). See ADR-004.
68
+ */
69
+ schemaVersion: "gruff-ts.config.v0.1";
44
70
  ignoredPaths: string[];
45
71
  acceptedAbbreviations: Set<string>;
46
72
  secretPreviews: Set<string>;
47
73
  bannedGenericNames: Set<string>;
74
+ acceptedBooleanNames: Set<string>;
48
75
  booleanPrefixes: Set<string>;
49
76
  hungarianPrefixes: Set<string>;
50
77
  placeholderNames: Set<string>;
51
78
  negativeBooleanAllowed: Set<string>;
52
79
  knownAcronyms: Set<string>;
80
+ /**
81
+ * Per-command default for `--fail-on`. Precedence: CLI flag > this map > binary default.
82
+ * `dashboard` is intentionally not a valid key (no `--fail-on` flag exists for it); the parser
83
+ * rejects `dashboard` with a documented error. See ADR-004.
84
+ */
85
+ minimumSeverity: Map<MinimumSeverityCommand, FailThreshold>;
53
86
  rules: Map<string, { enabled?: boolean; threshold?: number; severity?: Severity; options: Map<string, number> }>;
54
87
  }
55
88
 
89
+ /**
90
+ * One rule's settings inside a profile. Mirrors the per-rule knobs of the config `rules:` block
91
+ * (`enabled` defaults to true when omitted). `options` is optional here - built-in presets never set
92
+ * options - whereas the loaded `Config.rules` value always carries an (often empty) options map.
93
+ */
94
+ export interface ProfileRuleSetting {
95
+ enabled?: boolean;
96
+ threshold?: number;
97
+ severity?: Severity;
98
+ options?: Map<string, number>;
99
+ }
100
+
101
+ /**
102
+ * What a user writes for `profile:` (or passes to `--profile`): a built-in name / file path string,
103
+ * or an inline object that extends a base profile and layers per-rule and path overrides on top.
104
+ */
105
+ export type ProfileSpec = string | InlineProfileSpec;
106
+
107
+ /**
108
+ * The inline `profile:` object form. `extends` names the base (a built-in name or a relative file
109
+ * path; defaults to `gruff.recommended` when omitted); `rules` and `ignoredPaths` override the base
110
+ * with child-wins semantics - per-rule fields merge, and the `ignoredPaths` array replaces.
111
+ */
112
+ export interface InlineProfileSpec {
113
+ extends?: string;
114
+ rules?: Record<string, ProfileRuleSetting>;
115
+ ignoredPaths?: string[];
116
+ }
117
+
118
+ /**
119
+ * A fully resolved and flattened profile: the effective rule settings and ignored paths after the
120
+ * whole `extends:` chain has collapsed into one delta from the descriptor defaults. Enabled-at-default
121
+ * rules are omitted from `rules`, so `gruff.recommended` flattens to an empty map (the parity contract).
122
+ */
123
+ export interface ProfileDefinition {
124
+ name: string;
125
+ rules: Map<string, ProfileRuleSetting>;
126
+ ignoredPaths: string[];
127
+ }
128
+
56
129
  /** Stable analysis finding emitted by a rule. */
57
130
  export interface Finding {
58
131
  ruleId: string;
@@ -80,19 +153,41 @@ export interface RunDiagnostic {
80
153
  line?: number;
81
154
  }
82
155
 
83
- /** Stable gruff.analysis.v1 report schema returned by analyse and JSON report commands. */
156
+ /**
157
+ * Source that excluded a path from analysis. `config` (`paths.ignore`) is authoritative in every
158
+ * invocation mode - explicit file operands and diff/changed-region runs included - and is never
159
+ * overridden by `--include-ignored`. `gitignore` and `default` are discovery-walk ignores: they are
160
+ * suppressed by `--include-ignored` and bypassed for an explicitly supplied file operand (ADR-003).
161
+ */
162
+ export type IgnoreSource = "config" | "gitignore" | "default";
163
+
164
+ /** One path excluded from analysis, with the ignore source and the exact pattern that matched. */
165
+ export interface SkippedPath {
166
+ path: string;
167
+ source: IgnoreSource;
168
+ pattern: string;
169
+ }
170
+
171
+ /**
172
+ * Stable gruff.analysis.v2 report schema returned by analyse and JSON report commands.
173
+ *
174
+ * `paths.skipped` (added in 0.3.0, ADR-007) is an additive field: each entry carries the excluded
175
+ * `path`, the ignore `source`, and the matching `pattern`. `paths.ignoredPaths` is retained as the
176
+ * back-compatible `string[]` of the same paths, so existing v2 consumers keep working without change.
177
+ */
84
178
  export interface AnalysisReport {
85
- schemaVersion: "gruff.analysis.v1";
179
+ schemaVersion: "gruff.analysis.v2";
86
180
  tool: { name: "gruff-ts"; version: string };
87
181
  run: { projectRoot: string; format: OutputFormat; failOn: FailThreshold; generatedAt: string };
88
182
  summary: { advisory: number; warning: number; error: number; total: number };
89
- paths: { analysedFiles: number; ignoredPaths: string[]; missingPaths: string[] };
183
+ paths: { analysedFiles: number; ignoredPaths: string[]; skipped: SkippedPath[]; missingPaths: string[] };
90
184
  diagnostics: RunDiagnostic[];
91
185
  findings: Finding[];
186
+ suppressedCount?: number;
92
187
  score: {
93
188
  composite: number;
94
189
  grade: string;
95
- pillars: Array<{ pillar: Pillar; score: number; findings: number }>;
190
+ pillars: Array<{ pillar: Pillar; score: number; penalty: number; findings: number }>;
96
191
  topOffenders: Array<{ filePath: string; score: number; findings: number }>;
97
192
  };
98
193
  baseline?: { path: string; source: string; suppressed: number; generated: boolean };
@@ -108,5 +203,13 @@ export interface RuleDescriptor {
108
203
  remediation: string;
109
204
  threshold?: number;
110
205
  optionKeys?: readonly string[];
206
+ /**
207
+ * Names of `allowlists.*` keys in `.gruff-ts.yaml` that override or extend the rule's
208
+ * behaviour. Mirrors the `optionKeys` shape but targets the cross-pillar allowlist surface
209
+ * (e.g. `naming.boolean-prefix` consults `allowlists.booleanPrefixes`). Surfaced in the
210
+ * `list-rules --format=json` payload and the per-rule remediation text so operators don't
211
+ * have to grep `.gruff-ts.yaml` and `src/config.ts` to find the override knob.
212
+ */
213
+ allowlistKeys?: readonly string[];
111
214
  fixtureExemption?: string;
112
215
  }