@kevinrabun/judges 3.60.0 → 3.62.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/CHANGELOG.md +14 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +112 -0
- package/dist/cli.js.map +1 -1
- package/dist/commands/ai-provenance.d.ts +5 -0
- package/dist/commands/ai-provenance.d.ts.map +1 -0
- package/dist/commands/ai-provenance.js +248 -0
- package/dist/commands/ai-provenance.js.map +1 -0
- package/dist/commands/batch-review.d.ts +5 -0
- package/dist/commands/batch-review.d.ts.map +1 -0
- package/dist/commands/batch-review.js +181 -0
- package/dist/commands/batch-review.js.map +1 -0
- package/dist/commands/blame-review.d.ts +5 -0
- package/dist/commands/blame-review.d.ts.map +1 -0
- package/dist/commands/blame-review.js +270 -0
- package/dist/commands/blame-review.js.map +1 -0
- package/dist/commands/custom-rule.d.ts +5 -0
- package/dist/commands/custom-rule.d.ts.map +1 -0
- package/dist/commands/custom-rule.js +211 -0
- package/dist/commands/custom-rule.js.map +1 -0
- package/dist/commands/diff-review.d.ts +5 -0
- package/dist/commands/diff-review.d.ts.map +1 -0
- package/dist/commands/diff-review.js +191 -0
- package/dist/commands/diff-review.js.map +1 -0
- package/dist/commands/evidence-chain.d.ts +5 -0
- package/dist/commands/evidence-chain.d.ts.map +1 -0
- package/dist/commands/evidence-chain.js +310 -0
- package/dist/commands/evidence-chain.js.map +1 -0
- package/dist/commands/focus-area.d.ts +6 -0
- package/dist/commands/focus-area.d.ts.map +1 -0
- package/dist/commands/focus-area.js +193 -0
- package/dist/commands/focus-area.js.map +1 -0
- package/dist/commands/merge-verdict.d.ts +5 -0
- package/dist/commands/merge-verdict.d.ts.map +1 -0
- package/dist/commands/merge-verdict.js +288 -0
- package/dist/commands/merge-verdict.js.map +1 -0
- package/dist/commands/quick-check.d.ts +5 -0
- package/dist/commands/quick-check.d.ts.map +1 -0
- package/dist/commands/quick-check.js +174 -0
- package/dist/commands/quick-check.js.map +1 -0
- package/dist/commands/review-compare.d.ts +5 -0
- package/dist/commands/review-compare.d.ts.map +1 -0
- package/dist/commands/review-compare.js +201 -0
- package/dist/commands/review-compare.js.map +1 -0
- package/dist/commands/review-contract.d.ts +5 -0
- package/dist/commands/review-contract.d.ts.map +1 -0
- package/dist/commands/review-contract.js +200 -0
- package/dist/commands/review-contract.js.map +1 -0
- package/dist/commands/review-explain.d.ts +6 -0
- package/dist/commands/review-explain.d.ts.map +1 -0
- package/dist/commands/review-explain.js +195 -0
- package/dist/commands/review-explain.js.map +1 -0
- package/dist/commands/review-gate.d.ts +5 -0
- package/dist/commands/review-gate.d.ts.map +1 -0
- package/dist/commands/review-gate.js +213 -0
- package/dist/commands/review-gate.js.map +1 -0
- package/dist/commands/review-handoff.d.ts +5 -0
- package/dist/commands/review-handoff.d.ts.map +1 -0
- package/dist/commands/review-handoff.js +209 -0
- package/dist/commands/review-handoff.js.map +1 -0
- package/dist/commands/review-receipt.d.ts +5 -0
- package/dist/commands/review-receipt.d.ts.map +1 -0
- package/dist/commands/review-receipt.js +221 -0
- package/dist/commands/review-receipt.js.map +1 -0
- package/dist/commands/severity-tune.d.ts +5 -0
- package/dist/commands/severity-tune.d.ts.map +1 -0
- package/dist/commands/severity-tune.js +209 -0
- package/dist/commands/severity-tune.js.map +1 -0
- package/dist/commands/trend-report.d.ts +5 -0
- package/dist/commands/trend-report.d.ts.map +1 -0
- package/dist/commands/trend-report.js +149 -0
- package/dist/commands/trend-report.js.map +1 -0
- package/package.json +1 -1
- package/server.json +2 -2
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Blame-review — git-blame integrated historical finding attribution.
|
|
3
|
+
*/
|
|
4
|
+
import { execSync } from "child_process";
|
|
5
|
+
import { readFileSync, readdirSync, statSync } from "fs";
|
|
6
|
+
import { join, extname } from "path";
|
|
7
|
+
// ─── Known patterns to detect ──────────────────────────────────────────────
|
|
8
|
+
const PATTERNS = [
|
|
9
|
+
{
|
|
10
|
+
name: "hardcoded-secret",
|
|
11
|
+
severity: "critical",
|
|
12
|
+
regex: /(?:password|secret|api_key|token)\s*[:=]\s*["'][^"']{8,}/i,
|
|
13
|
+
},
|
|
14
|
+
{ name: "eval-usage", severity: "critical", regex: /\beval\s*\(/ },
|
|
15
|
+
{ name: "sql-concat", severity: "critical", regex: /(?:query|execute)\s*\(\s*["'`].*\+/ },
|
|
16
|
+
{ name: "empty-catch", severity: "medium", regex: /catch\s*\([^)]*\)\s*\{\s*\}/ },
|
|
17
|
+
{ name: "console-log", severity: "low", regex: /console\.log\s*\(/ },
|
|
18
|
+
{ name: "todo-fixme", severity: "low", regex: /\/\/\s*(?:TODO|FIXME|HACK|XXX)\b/i },
|
|
19
|
+
{ name: "any-type", severity: "medium", regex: /:\s*any\b/ },
|
|
20
|
+
{ name: "deprecated-api", severity: "medium", regex: /new\s+Buffer\s*\(|\.substr\s*\(|\.addListener\s*\(/i },
|
|
21
|
+
{ name: "unsafe-regex", severity: "high", regex: /new\s+RegExp\s*\([^)]*\+/ },
|
|
22
|
+
{ name: "missing-await", severity: "high", regex: /(?:return|=)\s+(?!await\b)[a-zA-Z]+\.(then|catch)\s*\(/ },
|
|
23
|
+
];
|
|
24
|
+
// ─── Helpers ────────────────────────────────────────────────────────────────
|
|
25
|
+
function isGitRepo() {
|
|
26
|
+
try {
|
|
27
|
+
execSync("git rev-parse --is-inside-work-tree", { stdio: "pipe", timeout: 5000 });
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function gitBlameFile(filePath, since) {
|
|
35
|
+
try {
|
|
36
|
+
const sinceArg = since ? ` --since="${since}"` : "";
|
|
37
|
+
const out = execSync(`git blame --line-porcelain${sinceArg} -- "${filePath}"`, {
|
|
38
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
39
|
+
timeout: 15000,
|
|
40
|
+
maxBuffer: 10 * 1024 * 1024,
|
|
41
|
+
}).toString();
|
|
42
|
+
const entries = [];
|
|
43
|
+
const lines = out.split("\n");
|
|
44
|
+
let commit = "";
|
|
45
|
+
let author = "";
|
|
46
|
+
let date = "";
|
|
47
|
+
let lineNum = 0;
|
|
48
|
+
for (const line of lines) {
|
|
49
|
+
const commitMatch = /^([0-9a-f]{40})\s+\d+\s+(\d+)/.exec(line);
|
|
50
|
+
if (commitMatch) {
|
|
51
|
+
commit = commitMatch[1];
|
|
52
|
+
lineNum = parseInt(commitMatch[2], 10);
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
if (line.startsWith("author ")) {
|
|
56
|
+
author = line.slice(7);
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
if (line.startsWith("author-time ")) {
|
|
60
|
+
const ts = parseInt(line.slice(12), 10);
|
|
61
|
+
date = new Date(ts * 1000).toISOString().slice(0, 10);
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
if (line.startsWith("\t")) {
|
|
65
|
+
entries.push({
|
|
66
|
+
commit: commit.slice(0, 8),
|
|
67
|
+
author,
|
|
68
|
+
date,
|
|
69
|
+
lineNumber: lineNum,
|
|
70
|
+
content: line.slice(1),
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return entries;
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
return [];
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
function collectSourceFiles(dir) {
|
|
81
|
+
const exts = new Set([".ts", ".js", ".tsx", ".jsx", ".py", ".java", ".go", ".rs", ".cs", ".rb", ".php"]);
|
|
82
|
+
const files = [];
|
|
83
|
+
const skipDirs = new Set(["node_modules", ".git", "dist", "build", "coverage", ".next"]);
|
|
84
|
+
function walk(d) {
|
|
85
|
+
let entries;
|
|
86
|
+
try {
|
|
87
|
+
entries = readdirSync(d);
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
for (const name of entries) {
|
|
93
|
+
if (skipDirs.has(name))
|
|
94
|
+
continue;
|
|
95
|
+
const full = join(d, name);
|
|
96
|
+
try {
|
|
97
|
+
const st = statSync(full);
|
|
98
|
+
if (st.isDirectory())
|
|
99
|
+
walk(full);
|
|
100
|
+
else if (exts.has(extname(name)))
|
|
101
|
+
files.push(full);
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
// skip inaccessible
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
walk(dir);
|
|
109
|
+
return files;
|
|
110
|
+
}
|
|
111
|
+
function daysBetween(dateStr) {
|
|
112
|
+
const then = new Date(dateStr).getTime();
|
|
113
|
+
const now = Date.now();
|
|
114
|
+
return Math.floor((now - then) / (1000 * 60 * 60 * 24));
|
|
115
|
+
}
|
|
116
|
+
// ─── Core analysis ─────────────────────────────────────────────────────────
|
|
117
|
+
function analyzeBlame(files, since, authorFilter) {
|
|
118
|
+
const attributions = [];
|
|
119
|
+
for (const filePath of files) {
|
|
120
|
+
let content;
|
|
121
|
+
try {
|
|
122
|
+
content = readFileSync(filePath, "utf-8");
|
|
123
|
+
}
|
|
124
|
+
catch {
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
const fileLines = content.split("\n");
|
|
128
|
+
// Quick pattern scan first
|
|
129
|
+
const lineHits = [];
|
|
130
|
+
for (let i = 0; i < fileLines.length; i++) {
|
|
131
|
+
for (const pat of PATTERNS) {
|
|
132
|
+
if (pat.regex.test(fileLines[i])) {
|
|
133
|
+
lineHits.push({ line: i + 1, pattern: pat.name, severity: pat.severity });
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (lineHits.length === 0)
|
|
138
|
+
continue;
|
|
139
|
+
// Get blame data
|
|
140
|
+
const blameEntries = gitBlameFile(filePath, since);
|
|
141
|
+
const blameByLine = new Map();
|
|
142
|
+
for (const entry of blameEntries) {
|
|
143
|
+
blameByLine.set(entry.lineNumber, entry);
|
|
144
|
+
}
|
|
145
|
+
for (const hit of lineHits) {
|
|
146
|
+
const blame = blameByLine.get(hit.line);
|
|
147
|
+
if (!blame)
|
|
148
|
+
continue;
|
|
149
|
+
if (authorFilter && blame.author !== authorFilter)
|
|
150
|
+
continue;
|
|
151
|
+
attributions.push({
|
|
152
|
+
finding: hit.pattern,
|
|
153
|
+
severity: hit.severity,
|
|
154
|
+
introducedBy: blame.commit,
|
|
155
|
+
author: blame.author,
|
|
156
|
+
date: blame.date,
|
|
157
|
+
lineNumber: hit.line,
|
|
158
|
+
ageInDays: daysBetween(blame.date),
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
// Build author summaries
|
|
163
|
+
const authorMap = new Map();
|
|
164
|
+
for (const attr of attributions) {
|
|
165
|
+
let summary = authorMap.get(attr.author);
|
|
166
|
+
if (!summary) {
|
|
167
|
+
summary = { author: attr.author, totalFindings: 0, critical: 0, high: 0, medium: 0, low: 0 };
|
|
168
|
+
authorMap.set(attr.author, summary);
|
|
169
|
+
}
|
|
170
|
+
summary.totalFindings++;
|
|
171
|
+
if (attr.severity === "critical")
|
|
172
|
+
summary.critical++;
|
|
173
|
+
else if (attr.severity === "high")
|
|
174
|
+
summary.high++;
|
|
175
|
+
else if (attr.severity === "medium")
|
|
176
|
+
summary.medium++;
|
|
177
|
+
else
|
|
178
|
+
summary.low++;
|
|
179
|
+
}
|
|
180
|
+
const sorted = [...attributions].sort((a, b) => b.ageInDays - a.ageInDays);
|
|
181
|
+
const totalAge = attributions.reduce((sum, a) => sum + a.ageInDays, 0);
|
|
182
|
+
return {
|
|
183
|
+
totalFindings: attributions.length,
|
|
184
|
+
attributions,
|
|
185
|
+
authorSummaries: [...authorMap.values()].sort((a, b) => b.totalFindings - a.totalFindings),
|
|
186
|
+
oldestFinding: sorted.length > 0 ? sorted[0] : null,
|
|
187
|
+
newestFinding: sorted.length > 0 ? sorted[sorted.length - 1] : null,
|
|
188
|
+
averageAgeDays: attributions.length > 0 ? Math.round(totalAge / attributions.length) : 0,
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
// ─── CLI ────────────────────────────────────────────────────────────────────
|
|
192
|
+
export function runBlameReview(argv) {
|
|
193
|
+
if (argv.includes("--help") || argv.includes("-h")) {
|
|
194
|
+
console.log(`
|
|
195
|
+
judges blame-review — Git-blame integrated finding attribution
|
|
196
|
+
|
|
197
|
+
Usage:
|
|
198
|
+
judges blame-review [dir] Analyze current directory
|
|
199
|
+
judges blame-review --since "3 months" Sprint-scoped analysis
|
|
200
|
+
judges blame-review --author "Jane" Author-focused coaching
|
|
201
|
+
judges blame-review --format json JSON output
|
|
202
|
+
|
|
203
|
+
Options:
|
|
204
|
+
[dir] Target directory (default: .)
|
|
205
|
+
--since <period> Only consider commits since period
|
|
206
|
+
--author <name> Filter to specific author
|
|
207
|
+
--format json JSON output
|
|
208
|
+
--help, -h Show this help
|
|
209
|
+
|
|
210
|
+
Attributes findings to the commits and authors that introduced them.
|
|
211
|
+
Shows tech debt accrual timeline and author coaching summaries.
|
|
212
|
+
`);
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
if (!isGitRepo()) {
|
|
216
|
+
console.error("Error: Not inside a git repository.");
|
|
217
|
+
process.exitCode = 1;
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
const format = argv.find((_a, i) => argv[i - 1] === "--format") || "text";
|
|
221
|
+
const since = argv.find((_a, i) => argv[i - 1] === "--since");
|
|
222
|
+
const authorFilter = argv.find((_a, i) => argv[i - 1] === "--author");
|
|
223
|
+
const dir = argv.find((a) => !a.startsWith("-") &&
|
|
224
|
+
argv.indexOf(a) > 0 &&
|
|
225
|
+
argv[argv.indexOf(a) - 1] !== "--format" &&
|
|
226
|
+
argv[argv.indexOf(a) - 1] !== "--since" &&
|
|
227
|
+
argv[argv.indexOf(a) - 1] !== "--author") || ".";
|
|
228
|
+
const files = collectSourceFiles(dir);
|
|
229
|
+
if (files.length === 0) {
|
|
230
|
+
console.log("No source files found.");
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
const report = analyzeBlame(files, since, authorFilter);
|
|
234
|
+
if (format === "json") {
|
|
235
|
+
console.log(JSON.stringify(report, null, 2));
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
console.log(`\n Blame Review\n ─────────────────────────────`);
|
|
239
|
+
console.log(` Files scanned: ${files.length}`);
|
|
240
|
+
console.log(` Findings attributed: ${report.totalFindings}`);
|
|
241
|
+
console.log(` Average age: ${report.averageAgeDays} days`);
|
|
242
|
+
if (report.oldestFinding) {
|
|
243
|
+
console.log(`\n Oldest finding:`);
|
|
244
|
+
console.log(` ${report.oldestFinding.finding} (${report.oldestFinding.severity}) — ${report.oldestFinding.date} by ${report.oldestFinding.author} (${report.oldestFinding.ageInDays} days)`);
|
|
245
|
+
}
|
|
246
|
+
if (report.newestFinding) {
|
|
247
|
+
console.log(`\n Newest finding:`);
|
|
248
|
+
console.log(` ${report.newestFinding.finding} (${report.newestFinding.severity}) — ${report.newestFinding.date} by ${report.newestFinding.author} (${report.newestFinding.ageInDays} days)`);
|
|
249
|
+
}
|
|
250
|
+
if (report.authorSummaries.length > 0) {
|
|
251
|
+
console.log(`\n Author Attribution:`);
|
|
252
|
+
for (const author of report.authorSummaries) {
|
|
253
|
+
const breakdown = [];
|
|
254
|
+
if (author.critical > 0)
|
|
255
|
+
breakdown.push(`${author.critical} critical`);
|
|
256
|
+
if (author.high > 0)
|
|
257
|
+
breakdown.push(`${author.high} high`);
|
|
258
|
+
if (author.medium > 0)
|
|
259
|
+
breakdown.push(`${author.medium} medium`);
|
|
260
|
+
if (author.low > 0)
|
|
261
|
+
breakdown.push(`${author.low} low`);
|
|
262
|
+
console.log(` ${author.author}: ${author.totalFindings} findings (${breakdown.join(", ")})`);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
if (report.totalFindings === 0) {
|
|
266
|
+
console.log("\n ✅ No pattern-based findings detected in scanned files.");
|
|
267
|
+
}
|
|
268
|
+
console.log();
|
|
269
|
+
}
|
|
270
|
+
//# sourceMappingURL=blame-review.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blame-review.js","sourceRoot":"","sources":["../../src/commands/blame-review.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AACzD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAwCrC,8EAA8E;AAE9E,MAAM,QAAQ,GAAwD;IACpE;QACE,IAAI,EAAE,kBAAkB;QACxB,QAAQ,EAAE,UAAU;QACpB,KAAK,EAAE,2DAA2D;KACnE;IACD,EAAE,IAAI,EAAE,YAAY,EAAE,QAAQ,EAAE,UAAU,EAAE,KAAK,EAAE,aAAa,EAAE;IAClE,EAAE,IAAI,EAAE,YAAY,EAAE,QAAQ,EAAE,UAAU,EAAE,KAAK,EAAE,oCAAoC,EAAE;IACzF,EAAE,IAAI,EAAE,aAAa,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,6BAA6B,EAAE;IACjF,EAAE,IAAI,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,mBAAmB,EAAE;IACpE,EAAE,IAAI,EAAE,YAAY,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,mCAAmC,EAAE;IACnF,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,WAAW,EAAE;IAC5D,EAAE,IAAI,EAAE,gBAAgB,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,qDAAqD,EAAE;IAC5G,EAAE,IAAI,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,0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AAE,MAAM,EAAE,GAAG,IAAI,CAoFlD"}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom-rule — Load and run user-defined custom review rules from local config.
|
|
3
|
+
*/
|
|
4
|
+
import { readFileSync, existsSync, writeFileSync, readdirSync, statSync } from "fs";
|
|
5
|
+
import { join, extname } from "path";
|
|
6
|
+
// ─── Rule loading ──────────────────────────────────────────────────────────
|
|
7
|
+
function loadCustomRules(configPath) {
|
|
8
|
+
if (!existsSync(configPath))
|
|
9
|
+
return [];
|
|
10
|
+
try {
|
|
11
|
+
const raw = JSON.parse(readFileSync(configPath, "utf-8"));
|
|
12
|
+
if (Array.isArray(raw.rules)) {
|
|
13
|
+
return raw.rules.filter((r) => r.id && r.pattern);
|
|
14
|
+
}
|
|
15
|
+
return [];
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
return [];
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function defaultRulesTemplate() {
|
|
22
|
+
return {
|
|
23
|
+
rules: [
|
|
24
|
+
{
|
|
25
|
+
id: "no-fixme",
|
|
26
|
+
description: "Disallow FIXME comments in production code",
|
|
27
|
+
severity: "medium",
|
|
28
|
+
pattern: "//\\s*FIXME\\b",
|
|
29
|
+
fileTypes: [".ts", ".js", ".tsx", ".jsx"],
|
|
30
|
+
message: "FIXME comment found — resolve before merging",
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
id: "no-console-error",
|
|
34
|
+
description: "Disallow console.error in production code",
|
|
35
|
+
severity: "low",
|
|
36
|
+
pattern: "console\\.error\\s*\\(",
|
|
37
|
+
fileTypes: [".ts", ".js"],
|
|
38
|
+
message: "Use a structured logger instead of console.error",
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
id: "no-any-cast",
|
|
42
|
+
description: "Disallow 'as any' type casts",
|
|
43
|
+
severity: "medium",
|
|
44
|
+
pattern: "as\\s+any\\b",
|
|
45
|
+
fileTypes: [".ts", ".tsx"],
|
|
46
|
+
message: "Avoid 'as any' — use proper type assertions or generics",
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
// ─── File collection ───────────────────────────────────────────────────────
|
|
52
|
+
function collectSourceFiles(dir, fileTypes) {
|
|
53
|
+
const files = [];
|
|
54
|
+
const skipDirs = new Set(["node_modules", ".git", "dist", "build", "coverage"]);
|
|
55
|
+
function walk(d) {
|
|
56
|
+
let entries;
|
|
57
|
+
try {
|
|
58
|
+
entries = readdirSync(d);
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
for (const name of entries) {
|
|
64
|
+
if (skipDirs.has(name))
|
|
65
|
+
continue;
|
|
66
|
+
const full = join(d, name);
|
|
67
|
+
try {
|
|
68
|
+
const st = statSync(full);
|
|
69
|
+
if (st.isDirectory())
|
|
70
|
+
walk(full);
|
|
71
|
+
else if (fileTypes.has(extname(name)))
|
|
72
|
+
files.push(full);
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
// skip
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
walk(dir);
|
|
80
|
+
return files;
|
|
81
|
+
}
|
|
82
|
+
// ─── Analysis ──────────────────────────────────────────────────────────────
|
|
83
|
+
function runCustomRules(rules, dir) {
|
|
84
|
+
// Collect all relevant file types
|
|
85
|
+
const allFileTypes = new Set();
|
|
86
|
+
for (const rule of rules) {
|
|
87
|
+
for (const ft of rule.fileTypes)
|
|
88
|
+
allFileTypes.add(ft);
|
|
89
|
+
}
|
|
90
|
+
const files = collectSourceFiles(dir, allFileTypes);
|
|
91
|
+
const matches = [];
|
|
92
|
+
for (const filePath of files) {
|
|
93
|
+
const ext = extname(filePath);
|
|
94
|
+
let content;
|
|
95
|
+
try {
|
|
96
|
+
content = readFileSync(filePath, "utf-8");
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
const lines = content.split("\n");
|
|
102
|
+
for (const rule of rules) {
|
|
103
|
+
if (!rule.fileTypes.includes(ext))
|
|
104
|
+
continue;
|
|
105
|
+
let regex;
|
|
106
|
+
try {
|
|
107
|
+
regex = new RegExp(rule.pattern, "i");
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
for (let i = 0; i < lines.length; i++) {
|
|
113
|
+
if (regex.test(lines[i])) {
|
|
114
|
+
matches.push({
|
|
115
|
+
ruleId: rule.id,
|
|
116
|
+
severity: rule.severity || "medium",
|
|
117
|
+
message: rule.message || rule.description,
|
|
118
|
+
file: filePath,
|
|
119
|
+
line: i + 1,
|
|
120
|
+
content: lines[i].trim().slice(0, 100),
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
const counts = { critical: 0, high: 0, medium: 0, low: 0, total: matches.length };
|
|
127
|
+
for (const m of matches) {
|
|
128
|
+
if (m.severity === "critical")
|
|
129
|
+
counts.critical++;
|
|
130
|
+
else if (m.severity === "high")
|
|
131
|
+
counts.high++;
|
|
132
|
+
else if (m.severity === "medium")
|
|
133
|
+
counts.medium++;
|
|
134
|
+
else
|
|
135
|
+
counts.low++;
|
|
136
|
+
}
|
|
137
|
+
return { rulesLoaded: rules.length, filesScanned: files.length, matches, counts };
|
|
138
|
+
}
|
|
139
|
+
// ─── CLI ────────────────────────────────────────────────────────────────────
|
|
140
|
+
export function runCustomRule(argv) {
|
|
141
|
+
if (argv.includes("--help") || argv.includes("-h")) {
|
|
142
|
+
console.log(`
|
|
143
|
+
judges custom-rule — Load and run user-defined custom review rules
|
|
144
|
+
|
|
145
|
+
Usage:
|
|
146
|
+
judges custom-rule [dir] Run custom rules on directory
|
|
147
|
+
judges custom-rule init Create template custom-rules.json
|
|
148
|
+
judges custom-rule --config rules.json Use specific config file
|
|
149
|
+
judges custom-rule --format json JSON output
|
|
150
|
+
|
|
151
|
+
Options:
|
|
152
|
+
[dir] Target directory (default: .)
|
|
153
|
+
init Create a template custom-rules.json
|
|
154
|
+
--config <path> Path to custom rules file (default: custom-rules.json)
|
|
155
|
+
--format json JSON output
|
|
156
|
+
--help, -h Show this help
|
|
157
|
+
|
|
158
|
+
Custom rules are defined in a JSON file with pattern (regex), severity,
|
|
159
|
+
file types, and a message. Rules are applied to matching files locally.
|
|
160
|
+
`);
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
const format = argv.find((_a, i) => argv[i - 1] === "--format") || "text";
|
|
164
|
+
const configPath = argv.find((_a, i) => argv[i - 1] === "--config") || "custom-rules.json";
|
|
165
|
+
// Check for init subcommand
|
|
166
|
+
const hasInit = argv.some((a) => a === "init" && !argv[argv.indexOf(a) - 1]?.startsWith("--"));
|
|
167
|
+
if (hasInit) {
|
|
168
|
+
if (existsSync(configPath)) {
|
|
169
|
+
console.error(`Error: ${configPath} already exists.`);
|
|
170
|
+
process.exitCode = 1;
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
writeFileSync(configPath, JSON.stringify(defaultRulesTemplate(), null, 2), "utf-8");
|
|
174
|
+
console.log(`Created ${configPath} with example rules. Edit to add your own.`);
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
const dir = argv.find((a) => !a.startsWith("-") &&
|
|
178
|
+
a !== "custom-rule" &&
|
|
179
|
+
a !== "init" &&
|
|
180
|
+
argv[argv.indexOf(a) - 1] !== "--format" &&
|
|
181
|
+
argv[argv.indexOf(a) - 1] !== "--config") || ".";
|
|
182
|
+
const rules = loadCustomRules(configPath);
|
|
183
|
+
if (rules.length === 0) {
|
|
184
|
+
console.log(`No custom rules found in ${configPath}. Run 'judges custom-rule init' to create a template.`);
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
const result = runCustomRules(rules, dir);
|
|
188
|
+
if (format === "json") {
|
|
189
|
+
console.log(JSON.stringify(result, null, 2));
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
console.log(`\n Custom Rule Review\n ─────────────────────────────`);
|
|
193
|
+
console.log(` Rules loaded: ${result.rulesLoaded}`);
|
|
194
|
+
console.log(` Files scanned: ${result.filesScanned}`);
|
|
195
|
+
console.log(` Matches: ${result.counts.total} (C:${result.counts.critical} H:${result.counts.high} M:${result.counts.medium} L:${result.counts.low})`);
|
|
196
|
+
if (result.matches.length > 0) {
|
|
197
|
+
console.log("\n Matches:");
|
|
198
|
+
for (const m of result.matches.slice(0, 30)) {
|
|
199
|
+
const sevIcon = m.severity === "critical" ? "🔴" : m.severity === "high" ? "🟠" : m.severity === "medium" ? "🟡" : "🔵";
|
|
200
|
+
console.log(` ${sevIcon} [${m.ruleId}] ${m.message}`);
|
|
201
|
+
console.log(` ${m.file}:${m.line}`);
|
|
202
|
+
}
|
|
203
|
+
if (result.matches.length > 30)
|
|
204
|
+
console.log(` ... +${result.matches.length - 30} more`);
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
console.log("\n ✅ No custom rule violations found.");
|
|
208
|
+
}
|
|
209
|
+
console.log();
|
|
210
|
+
}
|
|
211
|
+
//# sourceMappingURL=custom-rule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"custom-rule.js","sourceRoot":"","sources":["../../src/commands/custom-rule.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AACpF,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AA6BrC,8EAA8E;AAE9E,SAAS,eAAe,CAAC,UAAkB;IACzC,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC;QAAE,OAAO,EAAE,CAAC;IACvC,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,UAAU,EAA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