code-gauge 4.8.0 → 5.1.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 (66) hide show
  1. package/README.md +34 -9
  2. package/THIRD-PARTY-NOTICES.txt +1152 -798
  3. package/dist/cli.cjs +3 -3
  4. package/dist/cli.cjs.map +1 -1
  5. package/dist/cli.js +3 -3
  6. package/dist/cli.js.map +1 -1
  7. package/dist/cliConfig.cjs +1 -1
  8. package/dist/cliConfig.cjs.map +1 -1
  9. package/dist/cliConfig.d.ts +13 -3
  10. package/dist/cliConfig.js +1 -1
  11. package/dist/cliConfig.js.map +1 -1
  12. package/dist/diffCommand.cjs +3 -3
  13. package/dist/diffCommand.cjs.map +1 -1
  14. package/dist/diffCommand.js +3 -3
  15. package/dist/diffCommand.js.map +1 -1
  16. package/dist/duplication.cjs +1 -1
  17. package/dist/duplication.cjs.map +1 -1
  18. package/dist/duplication.js +1 -1
  19. package/dist/duplication.js.map +1 -1
  20. package/dist/exclusion.cjs +2 -0
  21. package/dist/exclusion.cjs.map +1 -0
  22. package/dist/exclusion.d.ts +30 -0
  23. package/dist/exclusion.js +2 -0
  24. package/dist/exclusion.js.map +1 -0
  25. package/dist/git.cjs +1 -1
  26. package/dist/git.cjs.map +1 -1
  27. package/dist/git.d.ts +16 -0
  28. package/dist/git.js +1 -1
  29. package/dist/git.js.map +1 -1
  30. package/dist/index.cjs +1 -1
  31. package/dist/index.d.ts +2 -0
  32. package/dist/index.js +1 -1
  33. package/dist/nativeMetrics.cjs +3 -3
  34. package/dist/nativeMetrics.cjs.map +1 -1
  35. package/dist/nativeMetrics.js +3 -3
  36. package/dist/nativeMetrics.js.map +1 -1
  37. package/dist/newDuplication.cjs +2 -0
  38. package/dist/newDuplication.cjs.map +1 -0
  39. package/dist/newDuplication.d.ts +40 -0
  40. package/dist/newDuplication.js +2 -0
  41. package/dist/newDuplication.js.map +1 -0
  42. package/dist/regressionGate.cjs +1 -1
  43. package/dist/regressionGate.cjs.map +1 -1
  44. package/dist/regressionGate.d.ts +8 -6
  45. package/dist/regressionGate.js +1 -1
  46. package/dist/regressionGate.js.map +1 -1
  47. package/dist/scan.cjs +1 -1
  48. package/dist/scan.cjs.map +1 -1
  49. package/dist/scan.d.ts +12 -4
  50. package/dist/scan.js +1 -1
  51. package/dist/scan.js.map +1 -1
  52. package/dist/worker.cjs +1 -1
  53. package/dist/worker.cjs.map +1 -1
  54. package/dist/worker.js +1 -1
  55. package/dist/worker.js.map +1 -1
  56. package/native/Cargo.lock +73 -73
  57. package/native/Cargo.toml +16 -21
  58. package/native/code-gauge.wasm +0 -0
  59. package/native/src/dep_degree.rs +6 -6
  60. package/native/src/duplication.rs +143 -14
  61. package/native/src/functions.rs +10 -7
  62. package/native/src/languages.rs +14 -13
  63. package/native/src/measure.rs +16 -8
  64. package/native/src/tree_index.rs +4 -4
  65. package/native/src/util.rs +9 -2
  66. package/package.json +9 -8
package/README.md CHANGED
@@ -27,8 +27,8 @@ code-gauge path/to/project
27
27
  ```
28
28
 
29
29
  The CLI scans JavaScript, JSX, TypeScript, TSX, Python, Go, Rust, Java, Kotlin, C#, Ruby, C, and
30
- C++ files. By default it skips generated, vendor, test, and tool directories and prints the top 10
31
- refactoring candidates:
30
+ C++ files. By default it skips generated, vendor, test, and tool directories as well as
31
+ [generated and excluded files](#excluded-files), and prints the top 10 refactoring candidates:
32
32
 
33
33
  ```
34
34
  Measured 123 files under /path/to/project (code LOC 45678, NCSS 23456, functions 1789)
@@ -78,8 +78,9 @@ code-gauge diff --base main src/api # gate only the changed files under src/api
78
78
  `code-gauge diff --base <ref>` measures every changed file at both revisions (working tree vs. the
79
79
  merge-base of `<ref>` and `HEAD`, read with `git cat-file` — no checkout, no persisted baseline, so
80
80
  it works identically in CI and locally) and reports **only violations**. When every gate passes it
81
- prints a single line and exits 0; violations print one line each — metric, base → head values, the
82
- `file:line` span, and a remediation direction — and exit 1 (2 when files cannot be measured).
81
+ prints a single line and exits 0; violations print one line each — the `file:line` span, the metric
82
+ with its value and allowed bound (base → head for ratchets), and a remediation direction — and exit
83
+ 1 (2 when files cannot be measured).
83
84
 
84
85
  Functions are matched across revisions by name and arity, then by name alone, and finally by
85
86
  normalized-token LCS similarity, so renames and moves don't appear as delete+add. The gates:
@@ -91,9 +92,14 @@ normalized-token LCS similarity, so renames and moves don't appear as delete+add
91
92
  - **New functions — absolute thresholds.** Functions with no base counterpart are the one place
92
93
  absolutes are required (SonarQube-style "Clean as You Code"): cognitive complexity ≤ 15, NCSS
93
94
  ≤ 60, nesting depth ≤ 4 by default.
94
- - **No new duplication.** A changed file's duplicated lines (within-file plus cross-file against
95
- the whole project, so copy-paste from unchanged code into new files is caught) must not exceed
96
- the base revision's count.
95
+ - **No new duplication.** The changed lines of a file must not newly duplicate code, within the
96
+ file or against the whole project (so copy-paste from unchanged code is caught where it was
97
+ pasted). Only added lines count, and only those whose normalized tokens a partner file repeats:
98
+ a file whose untouched code gained a copy elsewhere is not blamed for it, and an edit between
99
+ lines already duplicated with the same files, a clone rewritten in place against the same
100
+ files, or a clone moved elsewhere in the change is not new duplication, while code pasted next
101
+ to an existing clone, or replacing one with a copy of unrelated code, is. Added lines come from
102
+ `git diff`, like the hunks reviewers see.
97
103
  - **Anti-gaming backstops.** Splitting a function resets its entity identity and could hide a
98
104
  worsening behind the laxer new-code thresholds, so when a removed named function's content
99
105
  partially reappears in unmatched new code the file's max cognitive complexity and total NCSS
@@ -102,7 +108,9 @@ normalized-token LCS similarity, so renames and moves don't appear as delete+add
102
108
  `--full` additionally prints the base → head values of every checked function; `--json` prints a
103
109
  machine-readable report. The duplication flags and `--include-tests` work like the ranking command.
104
110
  The duplication universes contain only git-visible files (tracked or untracked non-ignored), so
105
- local ignored artifacts cannot skew the counts, and the Halstead volume allowance scales with the
111
+ local ignored artifacts cannot skew the counts. [Excluded files](#excluded-files) are neither gated
112
+ nor part of the universes; a base blob is judged by the git attributes of the merge-base, so code
113
+ that stops being generated gates as new code. The Halstead volume allowance scales with the
106
114
  base value (25%, floored at the configured tolerance) so it admits the same ~5-statement edit at
107
115
  every function size.
108
116
 
@@ -136,6 +144,7 @@ with `--config`). The following config reproduces every built-in default:
136
144
  },
137
145
  "matchSimilarityPercent": 70
138
146
  },
147
+ "exclude": [],
139
148
  "includeTests": false,
140
149
  "failOnError": false
141
150
  }
@@ -144,6 +153,21 @@ with `--config`). The following config reproduces every built-in default:
144
153
  The command line wins over the config file, which wins over the defaults. Unknown settings are
145
154
  rejected so stale configuration fails loudly.
146
155
 
156
+ ### Excluded files
157
+
158
+ Directory scans and the regression gate skip, besides the built-in directories and file names:
159
+
160
+ - files matching an `exclude` glob pattern (e.g. `"exclude": ["src/legacy/**", "**/*.pb.ts"]`),
161
+ relative to the config file's directory and matched with Node's `path.posix.matchesGlob` (forward slashes on every platform);
162
+ - files git attributes mark `linguist-generated` or `linguist-vendored` (the attributes GitHub
163
+ uses to collapse generated diffs, e.g. `src/api/** linguist-generated` in `.gitattributes`);
164
+ - files with a generated-code marker in their first 5 lines: an `@generated` tag or a line
165
+ mentioning "generated" followed by "do not edit" / "do not modify" (e.g. Go's
166
+ `// Code generated by <tool>. DO NOT EDIT.`). Mark a hand-written file `-linguist-generated` to
167
+ keep it measured despite such a line.
168
+
169
+ A file passed as the explicit target is always measured.
170
+
147
171
  ### Duplication detection settings
148
172
 
149
173
  The `duplication` section tunes how clones are detected:
@@ -190,7 +214,8 @@ The `duplication` section tunes how clones are detected:
190
214
  - Per-function parameter counts and locations (name, node type, line span)
191
215
  - Within-file duplication: copy-pasted blocks matched on normalized tokens (identifiers anonymized
192
216
  consistently, literals by kind, and literal-dense data tables excluded unless their values also
193
- match), with adjacent matches around a small edit merged into gapped (Type-3) clone groups and
217
+ match; dependency declarations such as imports, package clauses, `#include`s, re-exports, and
218
+ `require`s carry no tokens, since every module must spell out its own), with adjacent matches around a small edit merged into gapped (Type-3) clone groups and
194
219
  near-miss (Type-3) clones matched by token-LCS similarity (tolerating reordered statements and
195
220
  copies embedded in added code), plus duplicated line count and ratio
196
221
  - Cross-file duplication (via `measureCrossFileDuplication`): copy-pasted blocks shared between