@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.
Files changed (77) hide show
  1. package/CHANGELOG.md +82 -0
  2. package/CONTRIBUTING.md +32 -25
  3. package/README.md +49 -50
  4. package/SECURITY.md +18 -31
  5. package/UPGRADING.md +101 -0
  6. package/bin/gruff-ts +3 -0
  7. package/docs/README.md +11 -10
  8. package/docs/agent-hook.md +32 -35
  9. package/docs/ci-integration.md +38 -24
  10. package/docs/configuration.md +160 -89
  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 -172
  15. package/docs/rules.md +126 -98
  16. package/package.json +10 -8
  17. package/src/analyser.ts +817 -323
  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 +62 -68
  22. package/src/blocks.ts +512 -336
  23. package/src/changed-regions.ts +380 -79
  24. package/src/check-ignore.ts +28 -13
  25. package/src/class-rules.ts +445 -436
  26. package/src/cli-program.ts +915 -172
  27. package/src/cli.ts +9 -3
  28. package/src/comment-rules.ts +236 -418
  29. package/src/comment-scanner.ts +339 -47
  30. package/src/complexity-metrics.ts +111 -35
  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 +751 -223
  35. package/src/constants.ts +7 -6
  36. package/src/context-doc-rules.ts +182 -54
  37. package/src/dashboard.ts +88 -23
  38. package/src/dead-code-rules.ts +153 -74
  39. package/src/discovery.ts +493 -140
  40. package/src/doc-rules.ts +602 -126
  41. package/src/duplicate-test-group-rules.ts +359 -0
  42. package/src/findings-helpers.ts +134 -109
  43. package/src/findings.ts +47 -27
  44. package/src/fixture-purpose-rules.ts +194 -50
  45. package/src/github-actions-event-guards.ts +331 -0
  46. package/src/github-actions-rules.ts +328 -121
  47. package/src/hook-contract.ts +681 -255
  48. package/src/init-config.ts +163 -118
  49. package/src/inline-suppressions.ts +340 -0
  50. package/src/limit-band.ts +56 -0
  51. package/src/line-rules.ts +331 -468
  52. package/src/migrate-config.ts +670 -0
  53. package/src/naming-pushers.ts +32 -127
  54. package/src/parsed-script.ts +868 -314
  55. package/src/pillar-summary.ts +56 -40
  56. package/src/profiles.ts +86 -74
  57. package/src/project-config-rules.ts +324 -140
  58. package/src/project-rules.ts +237 -115
  59. package/src/public-exports.ts +102 -38
  60. package/src/report-html.ts +217 -85
  61. package/src/report-renderers.ts +821 -203
  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 +249 -55
  66. package/src/security-flow-rules.ts +791 -115
  67. package/src/selectors.ts +169 -0
  68. package/src/sensitive-data-rules.ts +460 -387
  69. package/src/sensitive-exclusions.ts +435 -0
  70. package/src/source-text.ts +378 -104
  71. package/src/static-analysis-redundant-rules.ts +298 -41
  72. package/src/test-block-rules.ts +343 -253
  73. package/src/text-scans.ts +62 -11
  74. package/src/types.ts +220 -71
  75. package/tsconfig.json +2 -1
  76. package/src/process-exec-metadata.ts +0 -163
  77. package/src/test-fixtures.ts +0 -671
@@ -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(