@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.
Files changed (77) hide show
  1. package/CHANGELOG.md +123 -1
  2. package/CONTRIBUTING.md +32 -25
  3. package/README.md +55 -46
  4. package/SECURITY.md +18 -30
  5. package/UPGRADING.md +101 -0
  6. package/bin/gruff-ts +3 -0
  7. package/docs/README.md +11 -13
  8. package/docs/agent-hook.md +33 -24
  9. package/docs/ci-integration.md +38 -24
  10. package/docs/configuration.md +173 -71
  11. package/docs/dashboard.md +12 -13
  12. package/docs/output-formats.md +100 -25
  13. package/docs/philosophy.md +2 -2
  14. package/docs/reports-and-ci.md +14 -157
  15. package/docs/rules.md +140 -106
  16. package/package.json +10 -8
  17. package/src/analyser.ts +886 -282
  18. package/src/baseline-file.ts +867 -0
  19. package/src/baseline-identity.ts +463 -0
  20. package/src/baseline-options.ts +139 -34
  21. package/src/baseline.ts +85 -55
  22. package/src/blocks.ts +579 -364
  23. package/src/changed-regions.ts +414 -65
  24. package/src/check-ignore.ts +28 -13
  25. package/src/class-rules.ts +461 -302
  26. package/src/cli-program.ts +956 -166
  27. package/src/cli.ts +9 -2
  28. package/src/comment-rules.ts +277 -414
  29. package/src/comment-scanner.ts +363 -44
  30. package/src/complexity-metrics.ts +320 -0
  31. package/src/config-load-error.ts +17 -8
  32. package/src/config-parse.ts +291 -98
  33. package/src/config-preservation.ts +81 -26
  34. package/src/config.ts +778 -210
  35. package/src/constants.ts +7 -6
  36. package/src/context-doc-rules.ts +188 -61
  37. package/src/dashboard.ts +88 -23
  38. package/src/dead-code-rules.ts +153 -74
  39. package/src/discovery.ts +521 -148
  40. package/src/doc-rules.ts +592 -147
  41. package/src/duplicate-test-group-rules.ts +359 -0
  42. package/src/findings-helpers.ts +240 -89
  43. package/src/findings.ts +48 -24
  44. package/src/fixture-purpose-rules.ts +226 -48
  45. package/src/github-actions-event-guards.ts +331 -0
  46. package/src/github-actions-rules.ts +336 -106
  47. package/src/hook-contract.ts +708 -211
  48. package/src/init-config.ts +169 -114
  49. package/src/inline-suppressions.ts +340 -0
  50. package/src/limit-band.ts +56 -0
  51. package/src/line-rules.ts +331 -419
  52. package/src/migrate-config.ts +670 -0
  53. package/src/naming-pushers.ts +33 -107
  54. package/src/parsed-script.ts +1206 -0
  55. package/src/pillar-summary.ts +56 -40
  56. package/src/profiles.ts +97 -71
  57. package/src/project-config-rules.ts +335 -146
  58. package/src/project-rules.ts +237 -115
  59. package/src/public-exports.ts +284 -0
  60. package/src/report-html.ts +217 -85
  61. package/src/report-renderers.ts +864 -195
  62. package/src/rule-list.ts +166 -46
  63. package/src/rules.ts +100 -104
  64. package/src/safety-rules.ts +191 -132
  65. package/src/scoring.ts +255 -52
  66. package/src/security-flow-rules.ts +930 -109
  67. package/src/selectors.ts +169 -0
  68. package/src/sensitive-data-rules.ts +502 -375
  69. package/src/sensitive-exclusions.ts +435 -0
  70. package/src/source-text.ts +380 -148
  71. package/src/static-analysis-redundant-rules.ts +298 -41
  72. package/src/test-block-rules.ts +422 -228
  73. package/src/text-scans.ts +67 -9
  74. package/src/types.ts +222 -71
  75. package/tsconfig.json +2 -1
  76. package/src/process-exec-metadata.ts +0 -153
  77. package/src/test-fixtures.ts +0 -668
@@ -1,8 +1,8 @@
1
- // `check-ignore` command core: classify each path through the shared discovery ignore engine and
2
- // render the verdict. No analysis is performed - this is an O(1)-per-path config/gitignore/default
3
- // lookup that mirrors `git check-ignore` exit semantics, so a coding-agent hook can ask "will gruff
4
- // skip this changed file?" before running a scan. Single source of truth: `classifyPathIgnore` is the
5
- // exact engine `analyse` discovery uses; this module only loads config and formats the output.
1
+ // Powers `gruff-ts check-ignore`, answering whether gruff would skip each path without running analysis.
2
+ //
3
+ // Reuses `classifyPathIgnore` from `discovery.ts` so `check-ignore` and `analyse` never disagree:
4
+ // - mirrors `git check-ignore` exit codes (0 = at least one ignored, 1 = none ignored, 2 = config error);
5
+ // - lets coding-agent hooks and CI scripts check ignore policy in O(1) per path before scanning.
6
6
  import { cwd } from "node:process";
7
7
  import { loadConfig } from "./config.ts";
8
8
  import { classifyPathIgnore, type PathIgnoreClassification } from "./discovery.ts";
@@ -11,24 +11,39 @@ import type { AnalysisOptions } from "./types.ts";
11
11
  /** Output encodings supported by the `check-ignore` command. */
12
12
  export type CheckIgnoreFormat = "text" | "json";
13
13
 
14
- // Resolves config exactly as `analyse` does (`--config` / `--no-config`), then classifies each input
15
- // path. Config `paths.ignore` is authoritative; default and gitignore matches are reported with their
16
- // source too so the caller sees why a path would be skipped.
14
+ /**
15
+ * Reads config using the current working directory and classifies each path through discovery ignore rules.
16
+ * Config paths.ignore takes precedence over other ignore sources.
17
+ *
18
+ * @param inputs - File or directory paths to classify against the ignore rules.
19
+ * @param options - Analysis options that select config and control whether ordinary ignore rules are bypassed.
20
+ * @returns One classification per input path in input order, reporting the matching source and pattern when ignored.
21
+ */
17
22
  export function checkIgnore(inputs: string[], options: AnalysisOptions): PathIgnoreClassification[] {
18
23
  const projectRoot = cwd();
19
24
  const config = loadConfig(projectRoot, options);
20
25
  return inputs.map((input) => classifyPathIgnore(projectRoot, input, options, config));
21
26
  }
22
27
 
23
- // Mirrors `git check-ignore`: exit 0 when at least one path is ignored, 1 when none are. Exit 2 is
24
- // reserved for config/usage errors and is set by the CLI layer via `runWithConfigErrorHandling`.
28
+ /**
29
+ * Converts path classifications to the `git check-ignore` exit status.
30
+ * The CLI's `runWithConfigErrorHandling` assigns exit 2 for configuration failures.
31
+ *
32
+ * @param results - Path ignore classifications produced by `checkIgnore`.
33
+ * @returns `0` if any path in `results` is ignored, and `1` otherwise, including for an empty list.
34
+ */
25
35
  export function checkIgnoreExitCode(results: PathIgnoreClassification[]): number {
26
36
  return results.some((result) => result.isIgnored) ? 0 : 1;
27
37
  }
28
38
 
29
- // JSON is the agent-facing contract: every input path as `{ path, ignored, source, pattern }`, with
30
- // `source`/`pattern` null when the path is not ignored. Text lists only the ignored paths as
31
- // `<path>\t<source>:<pattern>`, matching `git check-ignore`'s "print the matches" behaviour.
39
+ /**
40
+ * Formats path classifications as JSON or tab-delimited text.
41
+ * JSON includes every path with `null` for missing match details; text lists ignored paths with a tab before `source:pattern`.
42
+ *
43
+ * @param results - Path ignore classifications to format.
44
+ * @param format - Output format (`"json"` for all paths, `"text"` for ignored paths only).
45
+ * @returns Formatted classification output, or an empty string in `"text"` format when no path is ignored.
46
+ */
32
47
  export function renderCheckIgnore(results: PathIgnoreClassification[], format: CheckIgnoreFormat): string {
33
48
  if (format === "json") {
34
49
  return JSON.stringify(