code-gauge 4.7.1 → 5.0.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.
- package/README.md +35 -10
- package/THIRD-PARTY-NOTICES.txt +595 -29
- package/dist/cli.cjs +3 -3
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +3 -3
- package/dist/cli.js.map +1 -1
- package/dist/cliConfig.cjs +1 -1
- package/dist/cliConfig.cjs.map +1 -1
- package/dist/cliConfig.d.ts +13 -3
- package/dist/cliConfig.js +1 -1
- package/dist/cliConfig.js.map +1 -1
- package/dist/crossFileDuplication.cjs +1 -1
- package/dist/crossFileDuplication.cjs.map +1 -1
- package/dist/crossFileDuplication.js +1 -1
- package/dist/crossFileDuplication.js.map +1 -1
- package/dist/crossFileNearMiss.cjs +1 -1
- package/dist/crossFileNearMiss.cjs.map +1 -1
- package/dist/crossFileNearMiss.js +1 -1
- package/dist/crossFileNearMiss.js.map +1 -1
- package/dist/diffCommand.cjs +3 -3
- package/dist/diffCommand.cjs.map +1 -1
- package/dist/diffCommand.js +3 -3
- package/dist/diffCommand.js.map +1 -1
- package/dist/duplicateSelection.cjs +1 -1
- package/dist/duplicateSelection.cjs.map +1 -1
- package/dist/duplicateSelection.js +1 -1
- package/dist/duplicateSelection.js.map +1 -1
- package/dist/duplication.cjs +1 -1
- package/dist/duplication.cjs.map +1 -1
- package/dist/duplication.js +1 -1
- package/dist/duplication.js.map +1 -1
- package/dist/exclusion.cjs +2 -0
- package/dist/exclusion.cjs.map +1 -0
- package/dist/exclusion.d.ts +30 -0
- package/dist/exclusion.js +2 -0
- package/dist/exclusion.js.map +1 -0
- package/dist/git.cjs +1 -1
- package/dist/git.cjs.map +1 -1
- package/dist/git.d.ts +16 -0
- package/dist/git.js +1 -1
- package/dist/git.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -1
- package/dist/languages.cjs +1 -1
- package/dist/languages.cjs.map +1 -1
- package/dist/languages.js +1 -1
- package/dist/languages.js.map +1 -1
- package/dist/newDuplication.cjs +2 -0
- package/dist/newDuplication.cjs.map +1 -0
- package/dist/newDuplication.d.ts +40 -0
- package/dist/newDuplication.js +2 -0
- package/dist/newDuplication.js.map +1 -0
- package/dist/regressionGate.cjs +1 -1
- package/dist/regressionGate.cjs.map +1 -1
- package/dist/regressionGate.d.ts +8 -6
- package/dist/regressionGate.js +1 -1
- package/dist/regressionGate.js.map +1 -1
- package/dist/scan.cjs +1 -1
- package/dist/scan.cjs.map +1 -1
- package/dist/scan.d.ts +12 -3
- package/dist/scan.js +1 -1
- package/dist/scan.js.map +1 -1
- package/dist/worker.cjs +1 -1
- package/dist/worker.cjs.map +1 -1
- package/dist/worker.js +1 -1
- package/dist/worker.js.map +1 -1
- package/native/Cargo.lock +47 -15
- package/native/Cargo.toml +9 -9
- package/native/code-gauge.wasm +0 -0
- package/native/src/complexity.rs +26 -33
- package/native/src/dep_degree.rs +43 -32
- package/native/src/duplication.rs +158 -40
- package/native/src/functions.rs +20 -62
- package/native/src/languages.rs +28 -7
- package/native/src/measure.rs +16 -27
- package/native/src/ncss.rs +32 -23
- package/native/src/tree_index.rs +9 -0
- package/native/src/util.rs +12 -57
- package/package.json +10 -10
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
[](https://github.com/WillBooster/code-gauge/actions/workflows/test.yml)
|
|
6
6
|
[](https://github.com/WillBooster/code-gauge/actions/workflows/test-rust.yml)
|
|
7
7
|
[](https://github.com/semantic-release/semantic-release)
|
|
8
|
-
[](https://github.com/WillBooster/shared/tree/main/packages/wbfy)
|
|
9
9
|
|
|
10
10
|
A command-line tool that ranks the files of a project by refactoring priority and gates changes
|
|
11
11
|
against metric regressions, built for AI-agent workflows: an agent asked to "refactor this
|
|
@@ -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
|
|
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 —
|
|
82
|
-
|
|
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.**
|
|
95
|
-
the whole project
|
|
96
|
-
|
|
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
|
|
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
|
|
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
|