slopbrick 0.21.2 → 0.24.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 +72 -0
- package/dist/engine/worker.cjs +1532 -72
- package/dist/engine/worker.js +1532 -72
- package/dist/index.cjs +1826 -33
- package/dist/index.js +1822 -30
- package/package.json +5 -2
package/dist/engine/worker.cjs
CHANGED
|
@@ -34405,6 +34405,232 @@ var importPathMismatchRule = createRule({
|
|
|
34405
34405
|
}
|
|
34406
34406
|
});
|
|
34407
34407
|
|
|
34408
|
+
// src/rules/cpp/c-style-cast.ts
|
|
34409
|
+
var C_STYLE_CAST_REGEX = /\(\s*(?:int|long|short|char|float|double|bool|unsigned\s+\w+|signed\s+\w+|size_t|[A-Za-z_]\w*(?:\s*[*,&][^)]*)?)\s*\)\s*(\w+|[^a-zA-Z_])/g;
|
|
34410
|
+
var NAMED_CAST_PREFIX_REGEX = /\b(?:static|reinterpret|const|dynamic)_cast\s*<[^>]*>\s*\($/;
|
|
34411
|
+
var cppCStyleCastRule = createRule({
|
|
34412
|
+
id: "cpp/c-style-cast",
|
|
34413
|
+
category: "typo",
|
|
34414
|
+
severity: "low",
|
|
34415
|
+
aiSpecific: true,
|
|
34416
|
+
description: "C-style cast `(int)x` \u2014 use static_cast / reinterpret_cast / const_cast so the kind is greppable.",
|
|
34417
|
+
create(_context) {
|
|
34418
|
+
return {};
|
|
34419
|
+
},
|
|
34420
|
+
analyze(_context, facts) {
|
|
34421
|
+
const issues = [];
|
|
34422
|
+
const source = facts.v2?._source;
|
|
34423
|
+
if (!source) return issues;
|
|
34424
|
+
if (!/\.(cpp|cc|cxx|h|hpp|hh|hxx|H)$/i.test(facts.filePath)) return issues;
|
|
34425
|
+
let m;
|
|
34426
|
+
C_STYLE_CAST_REGEX.lastIndex = 0;
|
|
34427
|
+
while ((m = C_STYLE_CAST_REGEX.exec(source)) !== null) {
|
|
34428
|
+
const innerMatch = /\(\s*([^)]+?)\s*\)/.exec(m[0]) ?? [];
|
|
34429
|
+
const inner = (innerMatch[1] ?? "").trim();
|
|
34430
|
+
const looksLikeCast = /\b(?:int|long|short|char|float|double|bool|unsigned|signed|size_t)\b/.test(inner) || /[*&]/.test(inner);
|
|
34431
|
+
if (!looksLikeCast) continue;
|
|
34432
|
+
const before = source.slice(Math.max(0, m.index - 40), m.index);
|
|
34433
|
+
if (NAMED_CAST_PREFIX_REGEX.test(before)) continue;
|
|
34434
|
+
const line = source.slice(0, m.index).split("\n").length;
|
|
34435
|
+
issues.push({
|
|
34436
|
+
ruleId: "cpp/c-style-cast",
|
|
34437
|
+
category: "typo",
|
|
34438
|
+
severity: "low",
|
|
34439
|
+
aiSpecific: true,
|
|
34440
|
+
message: `C-style cast at line ${line} \u2014 use static_cast / reinterpret_cast / const_cast`,
|
|
34441
|
+
line,
|
|
34442
|
+
column: 1,
|
|
34443
|
+
advice: "Use the named cast that matches the intent: `static_cast<int>(x)`, `reinterpret_cast<MyClass*>(p)`, `const_cast<...>(ref)`, or `dynamic_cast<Derived*>(base)` for runtime-checked downcasts. C-style casts silently pick whichever the compiler needs \u2014 `static_cast`, `reinterpret_cast`, OR `const_cast` \u2014 which makes them impossible to grep for and impossible to review. The C++ Core Guidelines (ES.49) call this out by name. AI agents reach for `(int)x` because of training-data C textbooks. Reference: cpp/c-style-cast v0.24."
|
|
34444
|
+
});
|
|
34445
|
+
}
|
|
34446
|
+
return issues;
|
|
34447
|
+
}
|
|
34448
|
+
});
|
|
34449
|
+
|
|
34450
|
+
// src/rules/cpp/magic-numbers.ts
|
|
34451
|
+
var MAGIC_NUMBER_REGEX = /\b(\d+(?:\.\d+)?)\b/g;
|
|
34452
|
+
var COMPARE_OR_RETURN_REGEX = /\b(?:if|while|return|for)\s*[\(\s]?[^;]*[<>=!][^;]*/;
|
|
34453
|
+
var cppMagicNumbersRule = createRule({
|
|
34454
|
+
id: "cpp/magic-numbers",
|
|
34455
|
+
category: "typo",
|
|
34456
|
+
severity: "low",
|
|
34457
|
+
aiSpecific: true,
|
|
34458
|
+
description: "Magic-number literal in a comparison / return \u2014 name it: `constexpr int MAX = 1024;`.",
|
|
34459
|
+
create(_context) {
|
|
34460
|
+
return {};
|
|
34461
|
+
},
|
|
34462
|
+
analyze(_context, facts) {
|
|
34463
|
+
const issues = [];
|
|
34464
|
+
const source = facts.v2?._source;
|
|
34465
|
+
if (!source) return issues;
|
|
34466
|
+
if (!/\.(cpp|cc|cxx|h|hpp|hh|hxx|H)$/i.test(facts.filePath)) return issues;
|
|
34467
|
+
const lines = source.split("\n");
|
|
34468
|
+
const allowSet = /* @__PURE__ */ new Set([
|
|
34469
|
+
"1024",
|
|
34470
|
+
"65535",
|
|
34471
|
+
"65536",
|
|
34472
|
+
"86400",
|
|
34473
|
+
"3600",
|
|
34474
|
+
"1000",
|
|
34475
|
+
"100.0",
|
|
34476
|
+
"60",
|
|
34477
|
+
"24",
|
|
34478
|
+
"7",
|
|
34479
|
+
"365",
|
|
34480
|
+
"256",
|
|
34481
|
+
"255",
|
|
34482
|
+
"0",
|
|
34483
|
+
"1",
|
|
34484
|
+
"2",
|
|
34485
|
+
"3",
|
|
34486
|
+
"4",
|
|
34487
|
+
"5"
|
|
34488
|
+
]);
|
|
34489
|
+
for (let i = 0; i < lines.length; i++) {
|
|
34490
|
+
const line = lines[i] ?? "";
|
|
34491
|
+
if (!COMPARE_OR_RETURN_REGEX.test(line)) continue;
|
|
34492
|
+
let m;
|
|
34493
|
+
MAGIC_NUMBER_REGEX.lastIndex = 0;
|
|
34494
|
+
while ((m = MAGIC_NUMBER_REGEX.exec(line)) !== null) {
|
|
34495
|
+
const literal = m[0] ?? "";
|
|
34496
|
+
if (allowSet.has(literal)) continue;
|
|
34497
|
+
if (/\b(?:constexpr|const)\s+\w+\s*=\s*$/.test(line.slice(0, m.index).trimEnd())) continue;
|
|
34498
|
+
const prevLine = i > 0 ? lines[i - 1] ?? "" : "";
|
|
34499
|
+
if (/\b(?:constexpr|const)\s+\w+\s*=\s*$/.test(prevLine.trim())) continue;
|
|
34500
|
+
issues.push({
|
|
34501
|
+
ruleId: "cpp/magic-numbers",
|
|
34502
|
+
category: "typo",
|
|
34503
|
+
severity: "low",
|
|
34504
|
+
aiSpecific: true,
|
|
34505
|
+
message: `magic number ${literal} at line ${i + 1} \u2014 name it: constexpr int MAX = ${literal};`,
|
|
34506
|
+
line: i + 1,
|
|
34507
|
+
column: 1,
|
|
34508
|
+
advice: 'Replace the bare literal with a named constant declared as `constexpr int MAX_SIZE = 1024;` (or `static constexpr`). The named constant lives next to its value, can be searched, and forces the reader to mean what they say. Magic numbers in comparisons hide intent ("7" against what?). AI agents produce magic-number-heavy code because their training-data examples rarely bother to name the constant. Reference: cpp/magic-numbers v0.24.'
|
|
34509
|
+
});
|
|
34510
|
+
}
|
|
34511
|
+
}
|
|
34512
|
+
return issues;
|
|
34513
|
+
}
|
|
34514
|
+
});
|
|
34515
|
+
|
|
34516
|
+
// src/rules/cpp/printf-debug.ts
|
|
34517
|
+
var PRINTF_FAMILY_REGEX = /\b(?:printf|fprintf|sprintf|snprintf)\s*\(/g;
|
|
34518
|
+
var COUT_LITERAL_REGEX = /std\s*::\s*(?:cout|cerr|clog)\s*<<\s*"[^"]*"/g;
|
|
34519
|
+
var STD_COUT_BARE_REGEX = /std\s*::\s*(?:cout|cerr|clog)\s*<<\s*'[^']*'/g;
|
|
34520
|
+
var THRESHOLD_DEFAULT = 1;
|
|
34521
|
+
var cppPrintfDebugRule = createRule({
|
|
34522
|
+
id: "cpp/printf-debug",
|
|
34523
|
+
category: "typo",
|
|
34524
|
+
severity: "low",
|
|
34525
|
+
aiSpecific: true,
|
|
34526
|
+
description: "printf family or std::cout debug printing \u2014 use spdlog / glog / AbslLog for level-controlled output.",
|
|
34527
|
+
create(_context) {
|
|
34528
|
+
return { threshold: THRESHOLD_DEFAULT };
|
|
34529
|
+
},
|
|
34530
|
+
analyze(context, facts) {
|
|
34531
|
+
const issues = [];
|
|
34532
|
+
const source = facts.v2?._source;
|
|
34533
|
+
if (!source) return issues;
|
|
34534
|
+
if (!/\.(cpp|cc|cxx|h|hpp|hh|hxx|H)$/i.test(facts.filePath)) return issues;
|
|
34535
|
+
const printfCount = (source.match(PRINTF_FAMILY_REGEX) ?? []).length;
|
|
34536
|
+
let viaPrintf = false;
|
|
34537
|
+
if (printfCount > context.threshold) {
|
|
34538
|
+
const line = source.indexOf("printf");
|
|
34539
|
+
if (line !== -1) viaPrintf = true;
|
|
34540
|
+
}
|
|
34541
|
+
const coutHit = COUT_LITERAL_REGEX.test(source) || STD_COUT_BARE_REGEX.test(source);
|
|
34542
|
+
if (!viaPrintf && !coutHit) return issues;
|
|
34543
|
+
issues.push({
|
|
34544
|
+
ruleId: "cpp/printf-debug",
|
|
34545
|
+
category: "typo",
|
|
34546
|
+
severity: "low",
|
|
34547
|
+
aiSpecific: true,
|
|
34548
|
+
message: viaPrintf ? `${printfCount} printf-family calls \u2014 use spdlog / glog / AbslLog` : "std::cout/cerr/clog with a string literal \u2014 use spdlog / glog / AbslLog",
|
|
34549
|
+
line: 1,
|
|
34550
|
+
column: 1,
|
|
34551
|
+
advice: "Replace with `spdlog::info(...)`, `LOG(INFO) << ...` (glog), or `ABSL_LOG(INFO) << ...` (Abseil). All of these are level-aware and have a configurable sink, and they route to stderr by default. `printf` / `std::cout` have no levels, no redaction, no sink routing, and can't be silenced in release builds. AI agents reach for these because their training data has countless C++ textbook examples with them. Reference: cpp/printf-debug v0.24."
|
|
34552
|
+
});
|
|
34553
|
+
return issues;
|
|
34554
|
+
}
|
|
34555
|
+
});
|
|
34556
|
+
|
|
34557
|
+
// src/rules/cpp/raw-new-delete.ts
|
|
34558
|
+
var NEW_TYPE_REGEX = /\bnew\s+[A-Za-z_]\w*\s*\(/g;
|
|
34559
|
+
var DELETE_REGEX = /\bdelete\s+/g;
|
|
34560
|
+
var MIN_PAIRS_DEFAULT = 1;
|
|
34561
|
+
var cppRawNewDeleteRule = createRule({
|
|
34562
|
+
id: "cpp/raw-new-delete",
|
|
34563
|
+
category: "typo",
|
|
34564
|
+
severity: "low",
|
|
34565
|
+
aiSpecific: true,
|
|
34566
|
+
description: "Manual `new` / `delete` pairing \u2014 use std::make_unique / std::unique_ptr instead.",
|
|
34567
|
+
create(_context) {
|
|
34568
|
+
return { minPairs: MIN_PAIRS_DEFAULT };
|
|
34569
|
+
},
|
|
34570
|
+
analyze(context, facts) {
|
|
34571
|
+
const issues = [];
|
|
34572
|
+
const source = facts.v2?._source;
|
|
34573
|
+
if (!source) return issues;
|
|
34574
|
+
if (!/\.(cpp|cc|cxx|h|hpp|hh|hxx|H)$/i.test(facts.filePath)) return issues;
|
|
34575
|
+
let newCount = 0;
|
|
34576
|
+
let m;
|
|
34577
|
+
NEW_TYPE_REGEX.lastIndex = 0;
|
|
34578
|
+
while ((m = NEW_TYPE_REGEX.exec(source)) !== null) newCount++;
|
|
34579
|
+
let deleteCount = 0;
|
|
34580
|
+
DELETE_REGEX.lastIndex = 0;
|
|
34581
|
+
while ((m = DELETE_REGEX.exec(source)) !== null) deleteCount++;
|
|
34582
|
+
if (newCount <= context.minPairs) return issues;
|
|
34583
|
+
if (deleteCount <= context.minPairs) return issues;
|
|
34584
|
+
issues.push({
|
|
34585
|
+
ruleId: "cpp/raw-new-delete",
|
|
34586
|
+
category: "typo",
|
|
34587
|
+
severity: "low",
|
|
34588
|
+
aiSpecific: true,
|
|
34589
|
+
message: `manual new/delete pairing (${newCount} new, ${deleteCount} delete) \u2014 wrap in std::unique_ptr`,
|
|
34590
|
+
line: 1,
|
|
34591
|
+
column: 1,
|
|
34592
|
+
advice: "Replace `T* p = new T(...); ... delete p;` with `auto p = std::make_unique<T>(...);`. Smart pointers delete on scope exit, never leak on early return / exception, never double-free on copy. The C++ Core Guidelines R.20-R.23 call out raw `new` / `delete` as something to avoid in application code. AI agents reach for `new` / `delete` because their training data was written for pre-C++11 idioms. Reference: cpp/raw-new-delete v0.24."
|
|
34593
|
+
});
|
|
34594
|
+
return issues;
|
|
34595
|
+
}
|
|
34596
|
+
});
|
|
34597
|
+
|
|
34598
|
+
// src/rules/cpp/using-namespace-std.ts
|
|
34599
|
+
var USING_NAMESPACE_STD_REGEX = /\busing\s+namespace\s+std\s*;/g;
|
|
34600
|
+
var cppUsingNamespaceStdRule = createRule({
|
|
34601
|
+
id: "cpp/using-namespace-std",
|
|
34602
|
+
category: "logic",
|
|
34603
|
+
severity: "medium",
|
|
34604
|
+
aiSpecific: true,
|
|
34605
|
+
description: "`using namespace std;` in a header \u2014 pollutes every consumer. Use `using std::foo;` or qualify names.",
|
|
34606
|
+
create(_context) {
|
|
34607
|
+
return {};
|
|
34608
|
+
},
|
|
34609
|
+
analyze(_context, facts) {
|
|
34610
|
+
const issues = [];
|
|
34611
|
+
const source = facts.v2?._source;
|
|
34612
|
+
if (!source) return issues;
|
|
34613
|
+
if (!/\.(cpp|cc|cxx|h|hpp|hh|hxx|H)$/i.test(facts.filePath)) return issues;
|
|
34614
|
+
if (!/\.(h|hpp|hh|hxx|H)$/i.test(facts.filePath)) return issues;
|
|
34615
|
+
let m;
|
|
34616
|
+
USING_NAMESPACE_STD_REGEX.lastIndex = 0;
|
|
34617
|
+
while ((m = USING_NAMESPACE_STD_REGEX.exec(source)) !== null) {
|
|
34618
|
+
const line = source.slice(0, m.index).split("\n").length;
|
|
34619
|
+
issues.push({
|
|
34620
|
+
ruleId: "cpp/using-namespace-std",
|
|
34621
|
+
category: "logic",
|
|
34622
|
+
severity: "medium",
|
|
34623
|
+
aiSpecific: true,
|
|
34624
|
+
message: `using namespace std; at line ${line} \u2014 pollutes every consumer of this header`,
|
|
34625
|
+
line,
|
|
34626
|
+
column: 1,
|
|
34627
|
+
advice: "Remove the directive and qualify names with `std::`, or use a targeted `using std::cout;` / `using std::string;` for the few names that recur. The C++ Core Guidelines (SF.6 / SF.7) explicitly forbid `using namespace` in header files. A single `using namespace std;` in a widely-included header pulls 200+ names into every translation unit \u2014 downstream code, name-lookup, and ADL silently change. AI agents default to `using namespace std;` because their training snippets include countless copy-pasteable textbook examples that start with it. Reference: cpp/using-namespace-std v0.24."
|
|
34628
|
+
});
|
|
34629
|
+
}
|
|
34630
|
+
return issues;
|
|
34631
|
+
}
|
|
34632
|
+
});
|
|
34633
|
+
|
|
34408
34634
|
// src/rules/db/duplicate-index.ts
|
|
34409
34635
|
var import_pgsql_parser = require("pgsql-parser");
|
|
34410
34636
|
var moduleReady = (0, import_pgsql_parser.loadModule)();
|
|
@@ -36137,6 +36363,480 @@ var dupIdenticalBlockRule = createRule({
|
|
|
36137
36363
|
}
|
|
36138
36364
|
});
|
|
36139
36365
|
|
|
36366
|
+
// src/engine/dedup/tokenize.ts
|
|
36367
|
+
var import_node_crypto = require("crypto");
|
|
36368
|
+
var DEFAULT_CONFIG = { k: 5 };
|
|
36369
|
+
function stripComments(source) {
|
|
36370
|
+
let out = "";
|
|
36371
|
+
let i = 0;
|
|
36372
|
+
while (i < source.length) {
|
|
36373
|
+
const ch = source[i];
|
|
36374
|
+
const next = source[i + 1];
|
|
36375
|
+
if (ch === "/" && next === "/") {
|
|
36376
|
+
while (i < source.length && source[i] !== "\n") i++;
|
|
36377
|
+
continue;
|
|
36378
|
+
}
|
|
36379
|
+
if (ch === "/" && next === "*") {
|
|
36380
|
+
i += 2;
|
|
36381
|
+
while (i < source.length && !(source[i] === "*" && source[i + 1] === "/")) i++;
|
|
36382
|
+
i += 2;
|
|
36383
|
+
continue;
|
|
36384
|
+
}
|
|
36385
|
+
out += ch;
|
|
36386
|
+
i++;
|
|
36387
|
+
}
|
|
36388
|
+
return out;
|
|
36389
|
+
}
|
|
36390
|
+
function tokenize(source) {
|
|
36391
|
+
return source.toLowerCase().split(/[^a-z0-9_]+/u).filter((t) => t.length > 0);
|
|
36392
|
+
}
|
|
36393
|
+
function shingleHash(shingle) {
|
|
36394
|
+
const h = (0, import_node_crypto.createHash)("sha1").update(shingle).digest();
|
|
36395
|
+
return (h[0] ?? 0) << 24 | (h[1] ?? 0) << 16 | (h[2] ?? 0) << 8 | (h[3] ?? 0);
|
|
36396
|
+
}
|
|
36397
|
+
function shingleSet(source, config = {}) {
|
|
36398
|
+
const { k } = { ...DEFAULT_CONFIG, ...config };
|
|
36399
|
+
const tokens = tokenize(stripComments(source));
|
|
36400
|
+
if (tokens.length === 0) return /* @__PURE__ */ new Set();
|
|
36401
|
+
if (tokens.length < k) {
|
|
36402
|
+
return /* @__PURE__ */ new Set([shingleHash(tokens.join(" "))]);
|
|
36403
|
+
}
|
|
36404
|
+
const out = /* @__PURE__ */ new Set();
|
|
36405
|
+
for (let i = 0; i + k <= tokens.length; i++) {
|
|
36406
|
+
out.add(shingleHash(tokens.slice(i, i + k).join(" ")));
|
|
36407
|
+
}
|
|
36408
|
+
return out;
|
|
36409
|
+
}
|
|
36410
|
+
|
|
36411
|
+
// src/engine/dedup/minhash.ts
|
|
36412
|
+
var import_node_crypto2 = require("crypto");
|
|
36413
|
+
var PRIME = (1n << 61n) - 1n;
|
|
36414
|
+
function mix64(x) {
|
|
36415
|
+
x ^= x >> 33n;
|
|
36416
|
+
x = x * 0xff51afd7ed558ccdn & 0xffffffffffffffffn;
|
|
36417
|
+
x ^= x >> 33n;
|
|
36418
|
+
x = x * 0xc4ceb9fe1a85ec53n & 0xffffffffffffffffn;
|
|
36419
|
+
x ^= x >> 33n;
|
|
36420
|
+
return x;
|
|
36421
|
+
}
|
|
36422
|
+
function bmod(a, m) {
|
|
36423
|
+
const r = a % m;
|
|
36424
|
+
return r < 0n ? r + m : r;
|
|
36425
|
+
}
|
|
36426
|
+
function hashParams(i) {
|
|
36427
|
+
const a = mix64(BigInt(i) * 0x9e3779b97f4a7c15n) & 0xffffffffffffffffn | 1n;
|
|
36428
|
+
const b = mix64(BigInt(i) * 0xbf58476d1ce4e5b9n) & 0xffffffffffffffffn;
|
|
36429
|
+
return [a, b];
|
|
36430
|
+
}
|
|
36431
|
+
function hashAt(i, x) {
|
|
36432
|
+
const [a, b] = hashParams(i);
|
|
36433
|
+
const xb = BigInt(x >>> 0);
|
|
36434
|
+
const combined = a * xb + b;
|
|
36435
|
+
const h = Number(bmod(combined, PRIME) & 0xffffffffn);
|
|
36436
|
+
return h >>> 0;
|
|
36437
|
+
}
|
|
36438
|
+
var DEFAULT_CONFIG2 = {
|
|
36439
|
+
numHashes: 128
|
|
36440
|
+
};
|
|
36441
|
+
function minHash(tokens, config = {}) {
|
|
36442
|
+
const { numHashes } = { ...DEFAULT_CONFIG2, ...config };
|
|
36443
|
+
const sig = new Uint32Array(numHashes);
|
|
36444
|
+
sig.fill(4294967295);
|
|
36445
|
+
const tokenIter = tokens instanceof Set ? tokens : Array.from(tokens);
|
|
36446
|
+
for (const t of tokenIter) {
|
|
36447
|
+
for (let i = 0; i < numHashes; i++) {
|
|
36448
|
+
const h = hashAt(i, t);
|
|
36449
|
+
if (h < (sig[i] ?? 4294967295)) sig[i] = h;
|
|
36450
|
+
}
|
|
36451
|
+
}
|
|
36452
|
+
return sig;
|
|
36453
|
+
}
|
|
36454
|
+
function minHashSimilarity(a, b) {
|
|
36455
|
+
if (a.length !== b.length) {
|
|
36456
|
+
throw new Error(`minHashSimilarity: length mismatch ${a.length} vs ${b.length}`);
|
|
36457
|
+
}
|
|
36458
|
+
if (a.length === 0) return 1;
|
|
36459
|
+
let matches = 0;
|
|
36460
|
+
for (let i = 0; i < a.length; i++) {
|
|
36461
|
+
if (a[i] === b[i]) matches++;
|
|
36462
|
+
}
|
|
36463
|
+
return matches / a.length;
|
|
36464
|
+
}
|
|
36465
|
+
|
|
36466
|
+
// src/rules/dup/near-duplicate.ts
|
|
36467
|
+
var DEFAULT_CONTEXT = {
|
|
36468
|
+
threshold: 0.7,
|
|
36469
|
+
k: 5
|
|
36470
|
+
};
|
|
36471
|
+
var signatureCache = /* @__PURE__ */ new Map();
|
|
36472
|
+
var nearDuplicateRule = createRule({
|
|
36473
|
+
id: "dup/near-duplicate",
|
|
36474
|
+
category: "logic",
|
|
36475
|
+
severity: "medium",
|
|
36476
|
+
aiSpecific: true,
|
|
36477
|
+
description: "Near-duplicate file (Type-2 clone) \u2014 token-set Jaccard similarity > 0.7 after MinHash. Catches AI whitespace/comment refactors.",
|
|
36478
|
+
create(_context) {
|
|
36479
|
+
return { ...DEFAULT_CONTEXT };
|
|
36480
|
+
},
|
|
36481
|
+
analyze(context, facts) {
|
|
36482
|
+
const ctx = { ...DEFAULT_CONTEXT, ...context };
|
|
36483
|
+
const issues = [];
|
|
36484
|
+
const source = facts.v2?._source;
|
|
36485
|
+
if (!source) return issues;
|
|
36486
|
+
const filePath = facts.filePath;
|
|
36487
|
+
if (!filePath) return issues;
|
|
36488
|
+
const shingles = shingleSet(source, { k: ctx.k });
|
|
36489
|
+
if (shingles.size === 0) return issues;
|
|
36490
|
+
const sig = minHash(shingles);
|
|
36491
|
+
const matched = [];
|
|
36492
|
+
for (const [prevPath, prevSig] of signatureCache.entries()) {
|
|
36493
|
+
const sim = minHashSimilarity(sig, prevSig);
|
|
36494
|
+
if (sim >= ctx.threshold) {
|
|
36495
|
+
matched.push({ path: prevPath, similarity: sim });
|
|
36496
|
+
}
|
|
36497
|
+
}
|
|
36498
|
+
if (matched.length > 0) {
|
|
36499
|
+
matched.sort((a, b) => b.similarity - a.similarity);
|
|
36500
|
+
const best = matched[0];
|
|
36501
|
+
issues.push({
|
|
36502
|
+
ruleId: "dup/near-duplicate",
|
|
36503
|
+
category: "logic",
|
|
36504
|
+
severity: "medium",
|
|
36505
|
+
aiSpecific: true,
|
|
36506
|
+
message: `Near-duplicate of ${best.path} (Jaccard ${(best.similarity * 100).toFixed(1)}%, threshold ${(ctx.threshold * 100).toFixed(0)}%)`,
|
|
36507
|
+
line: 1,
|
|
36508
|
+
column: 1,
|
|
36509
|
+
advice: "Refactor to share the implementation, or rename/restructure to make the difference intentional. AI agents produce near-duplicates when iterating \u2014 this is the v0.23.0 Type-2 clone detector. Reference: dup/near-duplicate v0.23."
|
|
36510
|
+
});
|
|
36511
|
+
}
|
|
36512
|
+
signatureCache.set(filePath, sig);
|
|
36513
|
+
return issues;
|
|
36514
|
+
}
|
|
36515
|
+
});
|
|
36516
|
+
|
|
36517
|
+
// src/engine/dedup/lsh.ts
|
|
36518
|
+
var import_node_crypto3 = require("crypto");
|
|
36519
|
+
|
|
36520
|
+
// src/engine/dedup/structural-clone.ts
|
|
36521
|
+
function stripComments2(source) {
|
|
36522
|
+
let out = "";
|
|
36523
|
+
let i = 0;
|
|
36524
|
+
while (i < source.length) {
|
|
36525
|
+
const ch = source[i];
|
|
36526
|
+
const next = source[i + 1];
|
|
36527
|
+
if (ch === "/" && next === "/") {
|
|
36528
|
+
while (i < source.length && source[i] !== "\n") i++;
|
|
36529
|
+
continue;
|
|
36530
|
+
}
|
|
36531
|
+
if (ch === "/" && next === "*") {
|
|
36532
|
+
i += 2;
|
|
36533
|
+
while (i < source.length && !(source[i] === "*" && source[i + 1] === "/")) i++;
|
|
36534
|
+
i += 2;
|
|
36535
|
+
continue;
|
|
36536
|
+
}
|
|
36537
|
+
out += ch;
|
|
36538
|
+
i++;
|
|
36539
|
+
}
|
|
36540
|
+
return out;
|
|
36541
|
+
}
|
|
36542
|
+
var TOKEN_REGEX = /([A-Za-z_$][A-Za-z0-9_$]*)|(0[xX][0-9A-Fa-f]+|\d+(?:\.\d+)?(?:[eE][+-]?\d+)?[fFdDlL]?)|([(){}\[\];,.<>=+\-*/%!&|^?:])|"((?:[^"\\\n]|\\.)*)"|'((?:[^'\\\n]|\\.)*)'|`((?:[^`\\]|\\.)*)`/g;
|
|
36543
|
+
var BOOL_TOKENS = /* @__PURE__ */ new Set(["true", "false", "null", "none", "nil"]);
|
|
36544
|
+
var KEYWORDS = /* @__PURE__ */ new Set([
|
|
36545
|
+
// Control flow
|
|
36546
|
+
"if",
|
|
36547
|
+
"else",
|
|
36548
|
+
"for",
|
|
36549
|
+
"while",
|
|
36550
|
+
"do",
|
|
36551
|
+
"switch",
|
|
36552
|
+
"case",
|
|
36553
|
+
"default",
|
|
36554
|
+
"break",
|
|
36555
|
+
"continue",
|
|
36556
|
+
"return",
|
|
36557
|
+
"goto",
|
|
36558
|
+
// Declarations
|
|
36559
|
+
"function",
|
|
36560
|
+
"class",
|
|
36561
|
+
"interface",
|
|
36562
|
+
"struct",
|
|
36563
|
+
"enum",
|
|
36564
|
+
"trait",
|
|
36565
|
+
"def",
|
|
36566
|
+
"fn",
|
|
36567
|
+
"fun",
|
|
36568
|
+
"func",
|
|
36569
|
+
"var",
|
|
36570
|
+
"let",
|
|
36571
|
+
"const",
|
|
36572
|
+
"val",
|
|
36573
|
+
"mod",
|
|
36574
|
+
"use",
|
|
36575
|
+
"pub",
|
|
36576
|
+
"impl",
|
|
36577
|
+
"package",
|
|
36578
|
+
"module",
|
|
36579
|
+
"lambda",
|
|
36580
|
+
// Modifiers / visibility
|
|
36581
|
+
"public",
|
|
36582
|
+
"private",
|
|
36583
|
+
"protected",
|
|
36584
|
+
"static",
|
|
36585
|
+
"abstract",
|
|
36586
|
+
"final",
|
|
36587
|
+
"sealed",
|
|
36588
|
+
"override",
|
|
36589
|
+
"virtual",
|
|
36590
|
+
"readonly",
|
|
36591
|
+
"async",
|
|
36592
|
+
"await",
|
|
36593
|
+
"synchronized",
|
|
36594
|
+
"volatile",
|
|
36595
|
+
"transient",
|
|
36596
|
+
"native",
|
|
36597
|
+
"strictfp",
|
|
36598
|
+
"inline",
|
|
36599
|
+
"external",
|
|
36600
|
+
"export",
|
|
36601
|
+
"import",
|
|
36602
|
+
// Type system
|
|
36603
|
+
"type",
|
|
36604
|
+
"interface",
|
|
36605
|
+
"record",
|
|
36606
|
+
"object",
|
|
36607
|
+
"enum",
|
|
36608
|
+
"data",
|
|
36609
|
+
// Pattern / dispatch
|
|
36610
|
+
"match",
|
|
36611
|
+
"select",
|
|
36612
|
+
"when",
|
|
36613
|
+
"where",
|
|
36614
|
+
// Error handling
|
|
36615
|
+
"try",
|
|
36616
|
+
"catch",
|
|
36617
|
+
"finally",
|
|
36618
|
+
"throw",
|
|
36619
|
+
"throws",
|
|
36620
|
+
"raise",
|
|
36621
|
+
"rescue",
|
|
36622
|
+
"ensure",
|
|
36623
|
+
"except",
|
|
36624
|
+
// Logical connectives and tests
|
|
36625
|
+
"and",
|
|
36626
|
+
"or",
|
|
36627
|
+
"not",
|
|
36628
|
+
"in",
|
|
36629
|
+
"is",
|
|
36630
|
+
"as",
|
|
36631
|
+
"instanceof",
|
|
36632
|
+
"typeof",
|
|
36633
|
+
"delete",
|
|
36634
|
+
"void",
|
|
36635
|
+
"new",
|
|
36636
|
+
"this",
|
|
36637
|
+
"super",
|
|
36638
|
+
"self",
|
|
36639
|
+
"yield",
|
|
36640
|
+
// Misc
|
|
36641
|
+
"with",
|
|
36642
|
+
"without",
|
|
36643
|
+
"pass",
|
|
36644
|
+
"assert",
|
|
36645
|
+
"mut",
|
|
36646
|
+
"move",
|
|
36647
|
+
"ref",
|
|
36648
|
+
"out",
|
|
36649
|
+
"params",
|
|
36650
|
+
"operator",
|
|
36651
|
+
"sizeof",
|
|
36652
|
+
"typedef",
|
|
36653
|
+
"union",
|
|
36654
|
+
"register",
|
|
36655
|
+
"extern",
|
|
36656
|
+
"volatile",
|
|
36657
|
+
"goto",
|
|
36658
|
+
// Python-specific
|
|
36659
|
+
"elif",
|
|
36660
|
+
"global",
|
|
36661
|
+
"nonlocal",
|
|
36662
|
+
"del",
|
|
36663
|
+
"with",
|
|
36664
|
+
// Ruby-specific
|
|
36665
|
+
"unless",
|
|
36666
|
+
"until",
|
|
36667
|
+
"begin",
|
|
36668
|
+
"next",
|
|
36669
|
+
"then",
|
|
36670
|
+
"end",
|
|
36671
|
+
"alias",
|
|
36672
|
+
"defined",
|
|
36673
|
+
"super",
|
|
36674
|
+
"yield",
|
|
36675
|
+
"self",
|
|
36676
|
+
// Kotlin-specific
|
|
36677
|
+
"suspend",
|
|
36678
|
+
"lateinit",
|
|
36679
|
+
"companion",
|
|
36680
|
+
"internal",
|
|
36681
|
+
"open",
|
|
36682
|
+
// Rust-specific
|
|
36683
|
+
"unsafe",
|
|
36684
|
+
"dyn",
|
|
36685
|
+
"box",
|
|
36686
|
+
"crate",
|
|
36687
|
+
"where",
|
|
36688
|
+
// Swift-specific
|
|
36689
|
+
"guard",
|
|
36690
|
+
"defer",
|
|
36691
|
+
"repeat",
|
|
36692
|
+
"init",
|
|
36693
|
+
"deinit",
|
|
36694
|
+
"extension",
|
|
36695
|
+
"protocol",
|
|
36696
|
+
"throws",
|
|
36697
|
+
"rethrows",
|
|
36698
|
+
"weak",
|
|
36699
|
+
"unowned",
|
|
36700
|
+
"lazy"
|
|
36701
|
+
]);
|
|
36702
|
+
function canonicalTokens(source) {
|
|
36703
|
+
const stripped = stripComments2(source);
|
|
36704
|
+
const out = [];
|
|
36705
|
+
TOKEN_REGEX.lastIndex = 0;
|
|
36706
|
+
let m;
|
|
36707
|
+
while ((m = TOKEN_REGEX.exec(stripped)) !== null) {
|
|
36708
|
+
const [, ident, num, punct, dq, sq, bq] = m;
|
|
36709
|
+
if (ident !== void 0) {
|
|
36710
|
+
const lower = ident.toLowerCase();
|
|
36711
|
+
if (BOOL_TOKENS.has(lower)) {
|
|
36712
|
+
out.push("bool");
|
|
36713
|
+
} else if (KEYWORDS.has(lower)) {
|
|
36714
|
+
out.push(lower);
|
|
36715
|
+
} else {
|
|
36716
|
+
out.push("id");
|
|
36717
|
+
}
|
|
36718
|
+
continue;
|
|
36719
|
+
}
|
|
36720
|
+
if (num !== void 0) {
|
|
36721
|
+
out.push("num");
|
|
36722
|
+
continue;
|
|
36723
|
+
}
|
|
36724
|
+
if (punct !== void 0) {
|
|
36725
|
+
out.push(punct);
|
|
36726
|
+
continue;
|
|
36727
|
+
}
|
|
36728
|
+
if (dq !== void 0 || sq !== void 0 || bq !== void 0) {
|
|
36729
|
+
out.push("str");
|
|
36730
|
+
continue;
|
|
36731
|
+
}
|
|
36732
|
+
}
|
|
36733
|
+
return out;
|
|
36734
|
+
}
|
|
36735
|
+
function shingleHash2(shingle) {
|
|
36736
|
+
let h = 2166136261;
|
|
36737
|
+
for (let i = 0; i < shingle.length; i++) {
|
|
36738
|
+
h ^= shingle.charCodeAt(i);
|
|
36739
|
+
h = Math.imul(h, 16777619) >>> 0;
|
|
36740
|
+
}
|
|
36741
|
+
return h >>> 0;
|
|
36742
|
+
}
|
|
36743
|
+
var DEFAULT_STRUCTURAL_CONFIG = {
|
|
36744
|
+
k: 8,
|
|
36745
|
+
minTokens: 60
|
|
36746
|
+
};
|
|
36747
|
+
function structuralShingles(source, config = {}) {
|
|
36748
|
+
const { k, minTokens } = { ...DEFAULT_STRUCTURAL_CONFIG, ...config };
|
|
36749
|
+
const tokens = canonicalTokens(source);
|
|
36750
|
+
if (tokens.length < minTokens) return /* @__PURE__ */ new Set();
|
|
36751
|
+
if (tokens.length < k) {
|
|
36752
|
+
return /* @__PURE__ */ new Set([shingleHash2(tokens.join(" "))]);
|
|
36753
|
+
}
|
|
36754
|
+
const out = /* @__PURE__ */ new Set();
|
|
36755
|
+
for (let i = 0; i + k <= tokens.length; i++) {
|
|
36756
|
+
out.add(shingleHash2(tokens.slice(i, i + k).join(" ")));
|
|
36757
|
+
}
|
|
36758
|
+
return out;
|
|
36759
|
+
}
|
|
36760
|
+
function structuralSignature(source, config = {}) {
|
|
36761
|
+
return minHash(structuralShingles(source, config));
|
|
36762
|
+
}
|
|
36763
|
+
|
|
36764
|
+
// src/rules/dup/structural-clone.ts
|
|
36765
|
+
var DEFAULT_CONTEXT2 = {
|
|
36766
|
+
structuralThreshold: 0.55,
|
|
36767
|
+
verifyThreshold: 0.45,
|
|
36768
|
+
kStruct: 8,
|
|
36769
|
+
kIdent: 5,
|
|
36770
|
+
minTokens: 60,
|
|
36771
|
+
minHits: 1
|
|
36772
|
+
};
|
|
36773
|
+
var structuralCache = /* @__PURE__ */ new Map();
|
|
36774
|
+
var identifierCache = /* @__PURE__ */ new Map();
|
|
36775
|
+
var structuralCloneRule = createRule({
|
|
36776
|
+
id: "dup/structural-clone",
|
|
36777
|
+
category: "logic",
|
|
36778
|
+
severity: "medium",
|
|
36779
|
+
aiSpecific: true,
|
|
36780
|
+
defaultOff: true,
|
|
36781
|
+
description: "Structural clone (Type-3) \u2014 same shape after identifier canonicalization with possible added/removed statements. Two-stage MinHash: canonical + identifier.",
|
|
36782
|
+
create(_context) {
|
|
36783
|
+
return { ...DEFAULT_CONTEXT2 };
|
|
36784
|
+
},
|
|
36785
|
+
analyze(context, facts) {
|
|
36786
|
+
const ctx = { ...DEFAULT_CONTEXT2, ...context };
|
|
36787
|
+
const issues = [];
|
|
36788
|
+
const source = facts.v2?._source;
|
|
36789
|
+
if (!source) return issues;
|
|
36790
|
+
const filePath = facts.filePath;
|
|
36791
|
+
if (!filePath) return issues;
|
|
36792
|
+
const sigStruct = structuralSignature(source, {
|
|
36793
|
+
k: ctx.kStruct,
|
|
36794
|
+
minTokens: ctx.minTokens
|
|
36795
|
+
});
|
|
36796
|
+
if (sigStruct.every((v) => v === 4294967295)) return issues;
|
|
36797
|
+
const identShingles = shingleSet(source, { k: ctx.kIdent });
|
|
36798
|
+
if (identShingles.size === 0) return issues;
|
|
36799
|
+
const sigIdent = minHash(identShingles);
|
|
36800
|
+
const matched = [];
|
|
36801
|
+
for (const [prevPath, prevStruct] of structuralCache.entries()) {
|
|
36802
|
+
if (prevPath === filePath) continue;
|
|
36803
|
+
const simStruct = minHashSimilarity(sigStruct, prevStruct);
|
|
36804
|
+
if (simStruct < ctx.structuralThreshold) continue;
|
|
36805
|
+
const prevIdent = identifierCache.get(prevPath);
|
|
36806
|
+
if (!prevIdent) continue;
|
|
36807
|
+
const simIdent = minHashSimilarity(sigIdent, prevIdent);
|
|
36808
|
+
if (simIdent <= 0) continue;
|
|
36809
|
+
const score = 2 * simStruct * simIdent / (simStruct + simIdent + 1e-9);
|
|
36810
|
+
if (score >= ctx.verifyThreshold) {
|
|
36811
|
+
matched.push({ path: prevPath, score, simStruct, simIdent });
|
|
36812
|
+
}
|
|
36813
|
+
}
|
|
36814
|
+
if (matched.length >= ctx.minHits) {
|
|
36815
|
+
matched.sort((a, b) => b.score - a.score);
|
|
36816
|
+
const best = matched[0];
|
|
36817
|
+
issues.push({
|
|
36818
|
+
ruleId: "dup/structural-clone",
|
|
36819
|
+
category: "logic",
|
|
36820
|
+
severity: "medium",
|
|
36821
|
+
aiSpecific: true,
|
|
36822
|
+
message: `Structural clone of ${best.path} (canonical Jaccard ${(best.simStruct * 100).toFixed(1)}%, identifier Jaccard ${(best.simIdent * 100).toFixed(1)}%, blend ${(best.score * 100).toFixed(1)}% \u2014 threshold ${(ctx.verifyThreshold * 100).toFixed(0)}%)`,
|
|
36823
|
+
line: 1,
|
|
36824
|
+
column: 1,
|
|
36825
|
+
advice: "Refactor to a shared helper. This is a Type-3 clone \u2014 two files share canonical shape after identifier normalization and likely a few added/removed statements. AI agents produce Type-3 clones when iterating on a function: same control flow, different names, a few lines added. (v0.24.0 \u2014 two-stage MinHash on canonical k=8 + identifier k=5 shingles.)",
|
|
36826
|
+
extras: {
|
|
36827
|
+
structuralDuplicateOf: {
|
|
36828
|
+
file: best.path,
|
|
36829
|
+
score: best.score
|
|
36830
|
+
}
|
|
36831
|
+
}
|
|
36832
|
+
});
|
|
36833
|
+
}
|
|
36834
|
+
structuralCache.set(filePath, sigStruct);
|
|
36835
|
+
identifierCache.set(filePath, sigIdent);
|
|
36836
|
+
return issues;
|
|
36837
|
+
}
|
|
36838
|
+
});
|
|
36839
|
+
|
|
36140
36840
|
// src/rules/go/error-wrap-without-context.ts
|
|
36141
36841
|
var ERR_WRAP_REGEX = /fmt\.Errorf\(\s*"((?:[^"\\]|\\.)*)"\s*,\s*([^)]+)\)/g;
|
|
36142
36842
|
var GENERIC_PREFIX_REGEX = /^\s*(?:error|err|failed|wrap(?:ping)?|invalid)\s*(?::\s*)?%w\b/i;
|
|
@@ -36394,84 +37094,255 @@ var javaLegacyDateApiRule = createRule({
|
|
|
36394
37094
|
advice: "Replace `java.util.Date` / `java.util.Calendar` with `java.time` (`LocalDate`, `LocalDateTime`, `Instant`, `ZonedDateTime`). java.time is immutable, thread-safe, and has a much better API. AI agents default to the legacy API because their training data predates Java 8 (2014). Reference: java/legacy-date-api v0.20."
|
|
36395
37095
|
});
|
|
36396
37096
|
}
|
|
36397
|
-
LEGACY_USAGE_REGEX.lastIndex = 0;
|
|
36398
|
-
while ((m = LEGACY_USAGE_REGEX.exec(source)) !== null) {
|
|
36399
|
-
const line = source.slice(0, m.index).split("\n").length;
|
|
36400
|
-
if (flagged.has(line)) continue;
|
|
37097
|
+
LEGACY_USAGE_REGEX.lastIndex = 0;
|
|
37098
|
+
while ((m = LEGACY_USAGE_REGEX.exec(source)) !== null) {
|
|
37099
|
+
const line = source.slice(0, m.index).split("\n").length;
|
|
37100
|
+
if (flagged.has(line)) continue;
|
|
37101
|
+
issues.push({
|
|
37102
|
+
ruleId: "java/legacy-date-api",
|
|
37103
|
+
category: "typo",
|
|
37104
|
+
severity: "low",
|
|
37105
|
+
aiSpecific: true,
|
|
37106
|
+
message: `new Date() / GregorianCalendar at line ${line} \u2014 use java.time`,
|
|
37107
|
+
line,
|
|
37108
|
+
column: 1,
|
|
37109
|
+
advice: "Replace with `LocalDate.now()`, `Instant.now()`, or `ZonedDateTime.now()`. Reference: java/legacy-date-api v0.20."
|
|
37110
|
+
});
|
|
37111
|
+
}
|
|
37112
|
+
CALENDAR_GET_INSTANCE_REGEX.lastIndex = 0;
|
|
37113
|
+
while ((m = CALENDAR_GET_INSTANCE_REGEX.exec(source)) !== null) {
|
|
37114
|
+
const line = source.slice(0, m.index).split("\n").length;
|
|
37115
|
+
if (flagged.has(line)) continue;
|
|
37116
|
+
issues.push({
|
|
37117
|
+
ruleId: "java/legacy-date-api",
|
|
37118
|
+
category: "typo",
|
|
37119
|
+
severity: "low",
|
|
37120
|
+
aiSpecific: true,
|
|
37121
|
+
message: `Calendar.getInstance() at line ${line} \u2014 use java.time`,
|
|
37122
|
+
line,
|
|
37123
|
+
column: 1,
|
|
37124
|
+
advice: "Replace with `LocalDate.now()` (date-only) or `ZonedDateTime.now()`. Reference: java/legacy-date-api v0.20."
|
|
37125
|
+
});
|
|
37126
|
+
}
|
|
37127
|
+
return issues;
|
|
37128
|
+
}
|
|
37129
|
+
});
|
|
37130
|
+
|
|
37131
|
+
// src/rules/java/raw-type-overuse.ts
|
|
37132
|
+
var RAW_TYPE_REGEX = /\b(List|Map|Set|Collection|Iterable)\s+(?![<A-Z])(\w+)/g;
|
|
37133
|
+
var javaRawTypeOveruseRule = createRule({
|
|
37134
|
+
id: "java/raw-type-overuse",
|
|
37135
|
+
category: "typo",
|
|
37136
|
+
severity: "low",
|
|
37137
|
+
aiSpecific: true,
|
|
37138
|
+
description: "Raw type usage (List, Map, Set) \u2014 use generics (Effective Java, Item 23)",
|
|
37139
|
+
create(_context) {
|
|
37140
|
+
return {};
|
|
37141
|
+
},
|
|
37142
|
+
analyze(_context, facts) {
|
|
37143
|
+
const issues = [];
|
|
37144
|
+
const source = facts.v2?._source;
|
|
37145
|
+
if (!source) return issues;
|
|
37146
|
+
if (!/\.java$/i.test(facts.filePath)) return issues;
|
|
37147
|
+
let m;
|
|
37148
|
+
RAW_TYPE_REGEX.lastIndex = 0;
|
|
37149
|
+
while ((m = RAW_TYPE_REGEX.exec(source)) !== null) {
|
|
37150
|
+
const typeName = m[1];
|
|
37151
|
+
const line = source.slice(0, m.index).split("\n").length;
|
|
37152
|
+
issues.push({
|
|
37153
|
+
ruleId: "java/raw-type-overuse",
|
|
37154
|
+
category: "typo",
|
|
37155
|
+
severity: "low",
|
|
37156
|
+
aiSpecific: true,
|
|
37157
|
+
message: `Raw type ${typeName} at line ${line} \u2014 add type parameters`,
|
|
37158
|
+
line,
|
|
37159
|
+
column: 1,
|
|
37160
|
+
advice: `Replace raw \`${typeName}\` with \`${typeName}<...>\`. Raw types disable generic type checking. Effective Java, Item 23: 'Don't use raw types in new code'. AI agents default to raw types when unsure of the correct generic parameters. Reference: java/raw-type-overuse v0.20.`
|
|
37161
|
+
});
|
|
37162
|
+
}
|
|
37163
|
+
return issues;
|
|
37164
|
+
}
|
|
37165
|
+
});
|
|
37166
|
+
|
|
37167
|
+
// src/rules/java/string-concat-loop.ts
|
|
37168
|
+
var STRING_CONCAT_REGEX = /(\b\w+)\s*=\s*\1\s*\+\s*[^;]+;|(\b\w+)\s*\+=\s*['"`]/g;
|
|
37169
|
+
var javaStringConcatLoopRule = createRule({
|
|
37170
|
+
id: "java/string-concat-loop",
|
|
37171
|
+
category: "perf",
|
|
37172
|
+
severity: "low",
|
|
37173
|
+
aiSpecific: true,
|
|
37174
|
+
description: "String concatenation in a loop \u2014 use StringBuilder",
|
|
37175
|
+
create(_context) {
|
|
37176
|
+
return {};
|
|
37177
|
+
},
|
|
37178
|
+
analyze(_context, facts) {
|
|
37179
|
+
const issues = [];
|
|
37180
|
+
const source = facts.v2?._source;
|
|
37181
|
+
if (!source) return issues;
|
|
37182
|
+
if (!/\.java$/i.test(facts.filePath)) return issues;
|
|
37183
|
+
if (!/\b(for|while|do)\b/.test(source)) return issues;
|
|
37184
|
+
let m;
|
|
37185
|
+
STRING_CONCAT_REGEX.lastIndex = 0;
|
|
37186
|
+
while ((m = STRING_CONCAT_REGEX.exec(source)) !== null) {
|
|
37187
|
+
const line = source.slice(0, m.index).split("\n").length;
|
|
37188
|
+
issues.push({
|
|
37189
|
+
ruleId: "java/string-concat-loop",
|
|
37190
|
+
category: "perf",
|
|
37191
|
+
severity: "low",
|
|
37192
|
+
aiSpecific: true,
|
|
37193
|
+
message: `String concatenation in a loop at line ${line} \u2014 use StringBuilder`,
|
|
37194
|
+
line,
|
|
37195
|
+
column: 1,
|
|
37196
|
+
advice: "Declare a `StringBuilder` outside the loop: `StringBuilder sb = new StringBuilder(); sb.append(...);` then `return sb.toString();` after the loop. String concatenation in a loop is O(n\xB2) \u2014 each iteration copies the prior string. AI agents concatenate strings in loops because of training-data examples. Reference: java/string-concat-loop v0.20."
|
|
37197
|
+
});
|
|
37198
|
+
}
|
|
37199
|
+
return issues;
|
|
37200
|
+
}
|
|
37201
|
+
});
|
|
37202
|
+
|
|
37203
|
+
// src/rules/java/system-out-println.ts
|
|
37204
|
+
var PRINTLN_REGEX = /System\.out\.println\s*\(/g;
|
|
37205
|
+
var DEFAULT_THRESHOLD = 1;
|
|
37206
|
+
var javaSystemOutPrintlnRule = createRule({
|
|
37207
|
+
id: "java/system-out-println",
|
|
37208
|
+
category: "typo",
|
|
37209
|
+
severity: "low",
|
|
37210
|
+
aiSpecific: true,
|
|
37211
|
+
description: "System.out.println in production code \u2014 use a logger (SLF4J, Log4j, etc.)",
|
|
37212
|
+
create(_context) {
|
|
37213
|
+
return { threshold: DEFAULT_THRESHOLD };
|
|
37214
|
+
},
|
|
37215
|
+
analyze(context, facts) {
|
|
37216
|
+
const issues = [];
|
|
37217
|
+
const source = facts.v2?._source;
|
|
37218
|
+
if (!source) return issues;
|
|
37219
|
+
if (!/\.java$/i.test(facts.filePath)) return issues;
|
|
37220
|
+
const matches = [];
|
|
37221
|
+
let m;
|
|
37222
|
+
PRINTLN_REGEX.lastIndex = 0;
|
|
37223
|
+
while ((m = PRINTLN_REGEX.exec(source)) !== null) {
|
|
37224
|
+
matches.push(m.index);
|
|
37225
|
+
}
|
|
37226
|
+
if (matches.length <= context.threshold) return issues;
|
|
37227
|
+
const cap = Math.min(matches.length, 10);
|
|
37228
|
+
for (let i = 0; i < cap; i++) {
|
|
37229
|
+
const idx = matches[i];
|
|
37230
|
+
const line = source.slice(0, idx).split("\n").length;
|
|
36401
37231
|
issues.push({
|
|
36402
|
-
ruleId: "java/
|
|
37232
|
+
ruleId: "java/system-out-println",
|
|
36403
37233
|
category: "typo",
|
|
36404
37234
|
severity: "low",
|
|
36405
37235
|
aiSpecific: true,
|
|
36406
|
-
message: `
|
|
37236
|
+
message: `System.out.println at line ${line} \u2014 use a logger for production output`,
|
|
36407
37237
|
line,
|
|
36408
37238
|
column: 1,
|
|
36409
|
-
advice: "Replace with `
|
|
37239
|
+
advice: "Replace with `private static final Logger log = LoggerFactory.getLogger(...);` then `log.info(...)`. AI agents default to println because their training data has countless textbook examples. Real Java code uses a logger. Reference: java/system-out-println v0.20."
|
|
36410
37240
|
});
|
|
36411
37241
|
}
|
|
36412
|
-
|
|
36413
|
-
|
|
37242
|
+
return issues;
|
|
37243
|
+
}
|
|
37244
|
+
});
|
|
37245
|
+
|
|
37246
|
+
// src/rules/kotlin/coroutine-global-scope.ts
|
|
37247
|
+
var GLOBAL_SCOPE_REGEX = /GlobalScope\s*\.\s*(?:launch|async|runBlocking)\s*[({]/g;
|
|
37248
|
+
var kotlinCoroutineGlobalScopeRule = createRule({
|
|
37249
|
+
id: "kotlin/coroutine-global-scope",
|
|
37250
|
+
category: "logic",
|
|
37251
|
+
severity: "medium",
|
|
37252
|
+
aiSpecific: true,
|
|
37253
|
+
description: "GlobalScope.launch/async/runBlocking \u2014 bypasses structured concurrency. Use viewModelScope / lifecycleScope / coroutineScope {}.",
|
|
37254
|
+
create(_context) {
|
|
37255
|
+
return {};
|
|
37256
|
+
},
|
|
37257
|
+
analyze(_context, facts) {
|
|
37258
|
+
const issues = [];
|
|
37259
|
+
const source = facts.v2?._source;
|
|
37260
|
+
if (!source) return issues;
|
|
37261
|
+
if (!/\.kt$/i.test(facts.filePath)) return issues;
|
|
37262
|
+
let m;
|
|
37263
|
+
GLOBAL_SCOPE_REGEX.lastIndex = 0;
|
|
37264
|
+
while ((m = GLOBAL_SCOPE_REGEX.exec(source)) !== null) {
|
|
36414
37265
|
const line = source.slice(0, m.index).split("\n").length;
|
|
36415
|
-
if (flagged.has(line)) continue;
|
|
36416
37266
|
issues.push({
|
|
36417
|
-
ruleId: "
|
|
36418
|
-
category: "
|
|
36419
|
-
severity: "
|
|
37267
|
+
ruleId: "kotlin/coroutine-global-scope",
|
|
37268
|
+
category: "logic",
|
|
37269
|
+
severity: "medium",
|
|
36420
37270
|
aiSpecific: true,
|
|
36421
|
-
message: `
|
|
37271
|
+
message: `GlobalScope.${m[0].split(".")[1]?.split("(")[0]}() at line ${line} \u2014 bypasses structured concurrency`,
|
|
36422
37272
|
line,
|
|
36423
37273
|
column: 1,
|
|
36424
|
-
advice:
|
|
37274
|
+
advice: 'Replace with `viewModelScope.launch { ... }` (Android view models), `lifecycleScope.launch { ... }` (Android activities / fragments), or `coroutineScope { ... }` inside a suspending function. GlobalScope bypasses cancellation, exception propagation, and lifetime binding. The kotlinx.coroutines docs explicitly call GlobalScope "delicate API". AI agents default to it for "fire-and-forget" work because of training-data snippets. Reference: kotlin/coroutine-global-scope v0.24.'
|
|
36425
37275
|
});
|
|
36426
37276
|
}
|
|
36427
37277
|
return issues;
|
|
36428
37278
|
}
|
|
36429
37279
|
});
|
|
36430
37280
|
|
|
36431
|
-
// src/rules/
|
|
36432
|
-
var
|
|
36433
|
-
var
|
|
36434
|
-
|
|
37281
|
+
// src/rules/kotlin/data-class-defaults-overuse.ts
|
|
37282
|
+
var DATA_CLASS_HEAD_REGEX = /\bdata\s+class\s+\w+\s*\(/g;
|
|
37283
|
+
var DEFAULT_PARAM_REGEX = /=\s*(?:null|true|false|"[^"]*"|'[^']*'|[+-]?\d+(?:\.\d+)?\w*|emptyList\(\)|emptyMap\(\)|emptySet\(\)|listOf\(\)|mapOf\(\)|setOf\(\))/g;
|
|
37284
|
+
var DEFAULT_MIN_DEFAULTS = 3;
|
|
37285
|
+
var kotlinDataClassDefaultsOveruseRule = createRule({
|
|
37286
|
+
id: "kotlin/data-class-defaults-overuse",
|
|
36435
37287
|
category: "typo",
|
|
36436
37288
|
severity: "low",
|
|
36437
37289
|
aiSpecific: true,
|
|
36438
|
-
description: "
|
|
37290
|
+
description: "data class with 3+ literal defaults \u2014 AI defaults every field rather than only the genuinely optional ones",
|
|
36439
37291
|
create(_context) {
|
|
36440
|
-
return {};
|
|
37292
|
+
return { minDefaults: DEFAULT_MIN_DEFAULTS };
|
|
36441
37293
|
},
|
|
36442
|
-
analyze(
|
|
37294
|
+
analyze(context, facts) {
|
|
36443
37295
|
const issues = [];
|
|
36444
37296
|
const source = facts.v2?._source;
|
|
36445
37297
|
if (!source) return issues;
|
|
36446
|
-
if (!/\.
|
|
37298
|
+
if (!/\.kt$/i.test(facts.filePath)) return issues;
|
|
36447
37299
|
let m;
|
|
36448
|
-
|
|
36449
|
-
while ((m =
|
|
36450
|
-
const
|
|
36451
|
-
const
|
|
37300
|
+
DATA_CLASS_HEAD_REGEX.lastIndex = 0;
|
|
37301
|
+
while ((m = DATA_CLASS_HEAD_REGEX.exec(source)) !== null) {
|
|
37302
|
+
const headStart = m.index;
|
|
37303
|
+
const openParen = source.indexOf("(", headStart);
|
|
37304
|
+
if (openParen === -1) continue;
|
|
37305
|
+
let depth = 1;
|
|
37306
|
+
let i = openParen + 1;
|
|
37307
|
+
while (i < source.length && depth > 0) {
|
|
37308
|
+
const ch = source.charAt(i);
|
|
37309
|
+
if (ch === "(") depth++;
|
|
37310
|
+
else if (ch === ")") depth--;
|
|
37311
|
+
i++;
|
|
37312
|
+
}
|
|
37313
|
+
if (depth !== 0) continue;
|
|
37314
|
+
const paramBlock = source.slice(openParen + 1, i - 1);
|
|
37315
|
+
DEFAULT_PARAM_REGEX.lastIndex = 0;
|
|
37316
|
+
let defaults = 0;
|
|
37317
|
+
let dm;
|
|
37318
|
+
while ((dm = DEFAULT_PARAM_REGEX.exec(paramBlock)) !== null) {
|
|
37319
|
+
defaults++;
|
|
37320
|
+
}
|
|
37321
|
+
if (defaults < context.minDefaults) continue;
|
|
37322
|
+
const line = source.slice(0, headStart).split("\n").length;
|
|
36452
37323
|
issues.push({
|
|
36453
|
-
ruleId: "
|
|
37324
|
+
ruleId: "kotlin/data-class-defaults-overuse",
|
|
36454
37325
|
category: "typo",
|
|
36455
37326
|
severity: "low",
|
|
36456
37327
|
aiSpecific: true,
|
|
36457
|
-
message: `
|
|
37328
|
+
message: `data class with ${defaults} literal defaults at line ${line} \u2014 only optional fields should have defaults`,
|
|
36458
37329
|
line,
|
|
36459
37330
|
column: 1,
|
|
36460
|
-
advice:
|
|
37331
|
+
advice: "Audit which fields are genuinely optional. Real Kotlin uses defaults sparingly (1-2 callbacks, the rest required). Defaulting every field makes the no-arg constructor callable for every data class and obscures intent. AI agents default every field because they imitate Java/Swift optional patterns. Reference: kotlin/data-class-defaults-overuse v0.24."
|
|
36461
37332
|
});
|
|
36462
37333
|
}
|
|
36463
37334
|
return issues;
|
|
36464
37335
|
}
|
|
36465
37336
|
});
|
|
36466
37337
|
|
|
36467
|
-
// src/rules/
|
|
36468
|
-
var
|
|
36469
|
-
var
|
|
36470
|
-
id: "
|
|
36471
|
-
category: "
|
|
36472
|
-
severity: "
|
|
37338
|
+
// src/rules/kotlin/object-singleton-misuse.ts
|
|
37339
|
+
var OBJECT_DECL_REGEX = /\bobject\s+(?!\w*Companion\b)(\w+)\s*\{/g;
|
|
37340
|
+
var kotlinObjectSingletonMisuseRule = createRule({
|
|
37341
|
+
id: "kotlin/object-singleton-misuse",
|
|
37342
|
+
category: "logic",
|
|
37343
|
+
severity: "medium",
|
|
36473
37344
|
aiSpecific: true,
|
|
36474
|
-
description: "
|
|
37345
|
+
description: "Kotlin object singleton holding mutable `var` state \u2014 hidden shared state. Use DI or a repository.",
|
|
36475
37346
|
create(_context) {
|
|
36476
37347
|
return {};
|
|
36477
37348
|
},
|
|
@@ -36479,48 +37350,62 @@ var javaStringConcatLoopRule = createRule({
|
|
|
36479
37350
|
const issues = [];
|
|
36480
37351
|
const source = facts.v2?._source;
|
|
36481
37352
|
if (!source) return issues;
|
|
36482
|
-
if (!/\.
|
|
36483
|
-
if (!/\b(for|while|do)\b/.test(source)) return issues;
|
|
37353
|
+
if (!/\.kt$/i.test(facts.filePath)) return issues;
|
|
36484
37354
|
let m;
|
|
36485
|
-
|
|
36486
|
-
while ((m =
|
|
36487
|
-
const
|
|
37355
|
+
OBJECT_DECL_REGEX.lastIndex = 0;
|
|
37356
|
+
while ((m = OBJECT_DECL_REGEX.exec(source)) !== null) {
|
|
37357
|
+
const declStart = m.index;
|
|
37358
|
+
const openBrace = source.indexOf("{", declStart);
|
|
37359
|
+
if (openBrace === -1) continue;
|
|
37360
|
+
let depth = 1;
|
|
37361
|
+
let i = openBrace + 1;
|
|
37362
|
+
while (i < source.length && depth > 0) {
|
|
37363
|
+
const ch = source.charAt(i);
|
|
37364
|
+
if (ch === "{") depth++;
|
|
37365
|
+
else if (ch === "}") depth--;
|
|
37366
|
+
i++;
|
|
37367
|
+
}
|
|
37368
|
+
if (depth !== 0) continue;
|
|
37369
|
+
const body = source.slice(openBrace + 1, i - 1);
|
|
37370
|
+
if (!/\bvar\s+\w+\s*[:=]/m.test(body)) continue;
|
|
37371
|
+
const line = source.slice(0, declStart).split("\n").length;
|
|
37372
|
+
const name = m[1] ?? "<unknown>";
|
|
36488
37373
|
issues.push({
|
|
36489
|
-
ruleId: "
|
|
36490
|
-
category: "
|
|
36491
|
-
severity: "
|
|
37374
|
+
ruleId: "kotlin/object-singleton-misuse",
|
|
37375
|
+
category: "logic",
|
|
37376
|
+
severity: "medium",
|
|
36492
37377
|
aiSpecific: true,
|
|
36493
|
-
message: `
|
|
37378
|
+
message: `object ${name} at line ${line} holds mutable state \u2014 singleton + var = hidden shared state`,
|
|
36494
37379
|
line,
|
|
36495
37380
|
column: 1,
|
|
36496
|
-
advice: "
|
|
37381
|
+
advice: "Replace with a class injected via DI, a Repository, or a `MutableStateFlow` with explicit synchronization. The Kotlin `object` keyword gives you a thread-safe singleton handle, but it does NOT make `var` fields inside that singleton thread-safe \u2014 mutable singleton state is a classic source of race conditions. AI agents reach for `object Cache { var data = ... }` because their training snippets make it look natural. Reference: kotlin/object-singleton-misuse v0.24."
|
|
36497
37382
|
});
|
|
36498
37383
|
}
|
|
36499
37384
|
return issues;
|
|
36500
37385
|
}
|
|
36501
37386
|
});
|
|
36502
37387
|
|
|
36503
|
-
// src/rules/
|
|
36504
|
-
var
|
|
36505
|
-
var
|
|
36506
|
-
var
|
|
36507
|
-
id: "
|
|
37388
|
+
// src/rules/kotlin/println-debug.ts
|
|
37389
|
+
var PRINTLN_REGEX2 = /^\s*println\s*\(/gm;
|
|
37390
|
+
var DEFAULT_THRESHOLD2 = 1;
|
|
37391
|
+
var kotlinPrintlnDebugRule = createRule({
|
|
37392
|
+
id: "kotlin/println-debug",
|
|
36508
37393
|
category: "typo",
|
|
36509
37394
|
severity: "low",
|
|
36510
37395
|
aiSpecific: true,
|
|
36511
|
-
description: "
|
|
37396
|
+
description: "println(...) in production code \u2014 use Timber, android.util.Log, or an SLF4J facade",
|
|
36512
37397
|
create(_context) {
|
|
36513
|
-
return { threshold:
|
|
37398
|
+
return { threshold: DEFAULT_THRESHOLD2 };
|
|
36514
37399
|
},
|
|
36515
37400
|
analyze(context, facts) {
|
|
36516
37401
|
const issues = [];
|
|
36517
37402
|
const source = facts.v2?._source;
|
|
36518
37403
|
if (!source) return issues;
|
|
36519
|
-
if (!/\.
|
|
37404
|
+
if (!/\.kt$/i.test(facts.filePath)) return issues;
|
|
36520
37405
|
const matches = [];
|
|
36521
37406
|
let m;
|
|
36522
|
-
|
|
36523
|
-
while ((m =
|
|
37407
|
+
PRINTLN_REGEX2.lastIndex = 0;
|
|
37408
|
+
while ((m = PRINTLN_REGEX2.exec(source)) !== null) {
|
|
36524
37409
|
matches.push(m.index);
|
|
36525
37410
|
}
|
|
36526
37411
|
if (matches.length <= context.threshold) return issues;
|
|
@@ -36529,14 +37414,52 @@ var javaSystemOutPrintlnRule = createRule({
|
|
|
36529
37414
|
const idx = matches[i];
|
|
36530
37415
|
const line = source.slice(0, idx).split("\n").length;
|
|
36531
37416
|
issues.push({
|
|
36532
|
-
ruleId: "
|
|
37417
|
+
ruleId: "kotlin/println-debug",
|
|
36533
37418
|
category: "typo",
|
|
36534
37419
|
severity: "low",
|
|
36535
37420
|
aiSpecific: true,
|
|
36536
|
-
message: `
|
|
37421
|
+
message: `println(...) at line ${line} \u2014 use Timber or android.util.Log for production output`,
|
|
36537
37422
|
line,
|
|
36538
37423
|
column: 1,
|
|
36539
|
-
advice: "Replace with `
|
|
37424
|
+
advice: "Replace with `Timber.plant(Timber.DebugTree())` then `Timber.d(...)`, or with an SLF4J facade. `println` writes to stdout with no level / no redaction and cannot be silenced in production. Multiple `println` calls in one file is an AI fingerprint \u2014 agents default to it because their training data has many copy-pasteable Kotlin examples. A single println in a `main` function is fine; 2+ is not. Reference: kotlin/println-debug v0.24."
|
|
37425
|
+
});
|
|
37426
|
+
}
|
|
37427
|
+
return issues;
|
|
37428
|
+
}
|
|
37429
|
+
});
|
|
37430
|
+
|
|
37431
|
+
// src/rules/kotlin/string-concat-loop.ts
|
|
37432
|
+
var STRING_CONCAT_REGEX2 = /\b(\w+)\s*=\s*\1\s*\+\s*[^;}]+[;}\n]/g;
|
|
37433
|
+
var kotlinStringConcatLoopRule = createRule({
|
|
37434
|
+
id: "kotlin/string-concat-loop",
|
|
37435
|
+
category: "perf",
|
|
37436
|
+
severity: "low",
|
|
37437
|
+
aiSpecific: true,
|
|
37438
|
+
description: "String concatenation in a loop \u2014 use buildString { ... } or a StringBuilder",
|
|
37439
|
+
create(_context) {
|
|
37440
|
+
return {};
|
|
37441
|
+
},
|
|
37442
|
+
analyze(_context, facts) {
|
|
37443
|
+
const issues = [];
|
|
37444
|
+
const source = facts.v2?._source;
|
|
37445
|
+
if (!source) return issues;
|
|
37446
|
+
if (!/\.kt$/i.test(facts.filePath)) return issues;
|
|
37447
|
+
if (!/\b(?:for|while|repeat|forEach)\b/.test(source)) return issues;
|
|
37448
|
+
let m;
|
|
37449
|
+
STRING_CONCAT_REGEX2.lastIndex = 0;
|
|
37450
|
+
while ((m = STRING_CONCAT_REGEX2.exec(source)) !== null) {
|
|
37451
|
+
const line = source.slice(0, m.index).split("\n").length;
|
|
37452
|
+
const lineText = source.slice(0, m.index).split("\n").pop() ?? "";
|
|
37453
|
+
if (/\.append\s*\(/.test(lineText)) continue;
|
|
37454
|
+
issues.push({
|
|
37455
|
+
ruleId: "kotlin/string-concat-loop",
|
|
37456
|
+
category: "perf",
|
|
37457
|
+
severity: "low",
|
|
37458
|
+
aiSpecific: true,
|
|
37459
|
+
message: `String concatenation in a loop at line ${line} \u2014 use buildString { ... }`,
|
|
37460
|
+
line,
|
|
37461
|
+
column: 1,
|
|
37462
|
+
advice: "Wrap the loop in `buildString { append(...) }` or declare a `StringBuilder` outside the loop. Kotlin cannot optimize `s = s + x` inside a loop \u2014 each iteration allocates a new StringBuilder, making the whole thing O(n\xB2) for n iterations. AI agents concatenate inside loops because of training-data examples. Reference: kotlin/string-concat-loop v0.24."
|
|
36540
37463
|
});
|
|
36541
37464
|
}
|
|
36542
37465
|
return issues;
|
|
@@ -36755,7 +37678,7 @@ var DEFAULT_RULE_CONFIG = {
|
|
|
36755
37678
|
},
|
|
36756
37679
|
genericCenteringMaxInstances: 1
|
|
36757
37680
|
};
|
|
36758
|
-
var
|
|
37681
|
+
var DEFAULT_CONFIG3 = {
|
|
36759
37682
|
include: [
|
|
36760
37683
|
// v0.9.2 — Repository Coherence is language-agnostic. Default include
|
|
36761
37684
|
// covers frontend (TS/JS/Vue/Svelte/Astro) AND backend (Python/Go).
|
|
@@ -37010,8 +37933,8 @@ var STRICTNESS_PRESETS = {
|
|
|
37010
37933
|
}
|
|
37011
37934
|
},
|
|
37012
37935
|
balanced: {
|
|
37013
|
-
thresholds:
|
|
37014
|
-
categoryWeights:
|
|
37936
|
+
thresholds: DEFAULT_CONFIG3.thresholds,
|
|
37937
|
+
categoryWeights: DEFAULT_CONFIG3.categoryWeights
|
|
37015
37938
|
},
|
|
37016
37939
|
permissive: {
|
|
37017
37940
|
thresholds: { meanSlop: 50, p90Slop: 75, individualSlopThreshold: 90 },
|
|
@@ -37955,7 +38878,7 @@ var KEYWORD_OPERATORS = [
|
|
|
37955
38878
|
function stripNoise2(source) {
|
|
37956
38879
|
return source.replace(/\/\*[\s\S]*?\*\//g, "").replace(/\/\/[^\n]*/g, "").replace(/'(?:\\.|[^'\\])*'/g, "''").replace(/"(?:\\.|[^"\\])*"/g, '""').replace(/`(?:\\.|[^`\\])*`/g, "``");
|
|
37957
38880
|
}
|
|
37958
|
-
function
|
|
38881
|
+
function tokenize2(source) {
|
|
37959
38882
|
const cleaned = stripNoise2(source);
|
|
37960
38883
|
const operators = [];
|
|
37961
38884
|
const operands = [];
|
|
@@ -37976,7 +38899,7 @@ function tokenize(source) {
|
|
|
37976
38899
|
return { operators, operands };
|
|
37977
38900
|
}
|
|
37978
38901
|
function computeHalstead(source) {
|
|
37979
|
-
const { operators, operands } =
|
|
38902
|
+
const { operators, operands } = tokenize2(source);
|
|
37980
38903
|
const uniqueOperators = new Set(operators);
|
|
37981
38904
|
const uniqueOperands = new Set(operands);
|
|
37982
38905
|
const n1 = uniqueOperators.size;
|
|
@@ -39237,7 +40160,226 @@ var unsafeHtmlRenderRule = createRule({
|
|
|
39237
40160
|
message: "dangerouslySetInnerHTML fed a non-literal value (variable, template, or expression) \u2014 unsanitized HTML will be rendered.",
|
|
39238
40161
|
line: lineOfSource(source, m.index),
|
|
39239
40162
|
column: 1,
|
|
39240
|
-
advice: "Sanitize the input with DOMPurify (or your framework's sanitizer) before passing it to dangerouslySetInnerHTML, or replace dangerouslySetInnerHTML with a children prop that React escapes automatically."
|
|
40163
|
+
advice: "Sanitize the input with DOMPurify (or your framework's sanitizer) before passing it to dangerouslySetInnerHTML, or replace dangerouslySetInnerHTML with a children prop that React escapes automatically."
|
|
40164
|
+
});
|
|
40165
|
+
}
|
|
40166
|
+
return issues;
|
|
40167
|
+
}
|
|
40168
|
+
});
|
|
40169
|
+
|
|
40170
|
+
// src/rules/swift/fatal-error-thrown.ts
|
|
40171
|
+
var FATAL_REGEX = /\b(?:fatalError|preconditionFailure)\s*\(/g;
|
|
40172
|
+
var swiftFatalErrorThrownRule = createRule({
|
|
40173
|
+
id: "swift/fatal-error-thrown",
|
|
40174
|
+
category: "logic",
|
|
40175
|
+
severity: "high",
|
|
40176
|
+
aiSpecific: true,
|
|
40177
|
+
description: "fatalError / preconditionFailure in production \u2014 crashes unconditionally. Return an error or a typed default.",
|
|
40178
|
+
create(_context) {
|
|
40179
|
+
return {};
|
|
40180
|
+
},
|
|
40181
|
+
analyze(_context, facts) {
|
|
40182
|
+
const issues = [];
|
|
40183
|
+
const source = facts.v2?._source;
|
|
40184
|
+
if (!source) return issues;
|
|
40185
|
+
if (!/\.swift$/i.test(facts.filePath)) return issues;
|
|
40186
|
+
if (/\bimport\s+XCTest\b/.test(source)) return issues;
|
|
40187
|
+
let m;
|
|
40188
|
+
FATAL_REGEX.lastIndex = 0;
|
|
40189
|
+
while ((m = FATAL_REGEX.exec(source)) !== null) {
|
|
40190
|
+
const line = source.slice(0, m.index).split("\n").length;
|
|
40191
|
+
const matched = m[0].replace(/\s*\($/, "");
|
|
40192
|
+
issues.push({
|
|
40193
|
+
ruleId: "swift/fatal-error-thrown",
|
|
40194
|
+
category: "logic",
|
|
40195
|
+
severity: "high",
|
|
40196
|
+
aiSpecific: true,
|
|
40197
|
+
message: `${matched}() at line ${line} \u2014 crashes unconditionally in release builds`,
|
|
40198
|
+
line,
|
|
40199
|
+
column: 1,
|
|
40200
|
+
advice: 'Replace with `return` of a typed default (e.g. `nil`, `[]()`), or throw a typed error (`enum MyError: Error { case notImplemented }; throw MyError.notImplemented`). Apple\'s docs contrast `fatalError` (survives release) with `precondition` (debug+checked only) and `assert` (debug only). AI agents plant `fatalError("not implemented")` in protocol stubs because the pattern "makes the file compile" while signalling TODO. Survives App Store review. Reference: swift/fatal-error-thrown v0.24.'
|
|
40201
|
+
});
|
|
40202
|
+
}
|
|
40203
|
+
return issues;
|
|
40204
|
+
}
|
|
40205
|
+
});
|
|
40206
|
+
|
|
40207
|
+
// src/rules/swift/force-unwrap.ts
|
|
40208
|
+
var AS_FORCE_REGEX = /\bas!\s+/g;
|
|
40209
|
+
var ACCESS_FORCE_REGEX = /(?:\w|\])\!\s*(?:\.|\(|;|,|\s*$)/gm;
|
|
40210
|
+
var TRY_FORCE_REGEX = /\btry!\s+/g;
|
|
40211
|
+
var swiftForceUnwrapRule = createRule({
|
|
40212
|
+
id: "swift/force-unwrap",
|
|
40213
|
+
category: "logic",
|
|
40214
|
+
severity: "medium",
|
|
40215
|
+
aiSpecific: true,
|
|
40216
|
+
description: "Swift force-unwrap (as!, var!.prop, try!) \u2014 silently crashes if the value is nil. Use as? / guard let / try?.",
|
|
40217
|
+
create(_context) {
|
|
40218
|
+
return {};
|
|
40219
|
+
},
|
|
40220
|
+
analyze(_context, facts) {
|
|
40221
|
+
const issues = [];
|
|
40222
|
+
const source = facts.v2?._source;
|
|
40223
|
+
if (!source) return issues;
|
|
40224
|
+
if (!/\.swift$/i.test(facts.filePath)) return issues;
|
|
40225
|
+
if (/\bimport\s+XCTest\b/.test(source)) return issues;
|
|
40226
|
+
const emit = (idx, label) => {
|
|
40227
|
+
const line = source.slice(0, idx).split("\n").length;
|
|
40228
|
+
issues.push({
|
|
40229
|
+
ruleId: "swift/force-unwrap",
|
|
40230
|
+
category: "logic",
|
|
40231
|
+
severity: "medium",
|
|
40232
|
+
aiSpecific: true,
|
|
40233
|
+
message: `force-unwrap (${label}) at line ${line} \u2014 crashes if the value is nil`,
|
|
40234
|
+
line,
|
|
40235
|
+
column: 1,
|
|
40236
|
+
advice: 'Replace with the safe form: `as?` + guard/if let, `try?` + nil-check, or `guard let x = optional else { return }` instead of `x!`. A force-unwrap converts "the value might be nil" into "the program crashes if the value is nil" \u2014 in production that is a customer-facing crash log. AI agents reach for `!` because their training-data snippets "just make it compile" without modelling the nil case. Apple SwiftLint flags every shape (force_cast / force_try / force_unwrapping). Reference: swift/force-unwrap v0.24.'
|
|
40237
|
+
});
|
|
40238
|
+
};
|
|
40239
|
+
let m;
|
|
40240
|
+
AS_FORCE_REGEX.lastIndex = 0;
|
|
40241
|
+
while ((m = AS_FORCE_REGEX.exec(source)) !== null) emit(m.index, "as!");
|
|
40242
|
+
TRY_FORCE_REGEX.lastIndex = 0;
|
|
40243
|
+
while ((m = TRY_FORCE_REGEX.exec(source)) !== null) emit(m.index, "try!");
|
|
40244
|
+
ACCESS_FORCE_REGEX.lastIndex = 0;
|
|
40245
|
+
while ((m = ACCESS_FORCE_REGEX.exec(source)) !== null) emit(m.index, "!.");
|
|
40246
|
+
return issues;
|
|
40247
|
+
}
|
|
40248
|
+
});
|
|
40249
|
+
|
|
40250
|
+
// src/rules/swift/implicitly-unwrapped-optional.ts
|
|
40251
|
+
var IUO_DECL_REGEX = /\b(?:var|let)\s+\w+\s*:\s*[A-Za-z_][\w<>?,\.\s]*!\s*[=;\n]/g;
|
|
40252
|
+
var swiftImplicitlyUnwrappedOptionalRule = createRule({
|
|
40253
|
+
id: "swift/implicitly-unwrapped-optional",
|
|
40254
|
+
category: "typo",
|
|
40255
|
+
severity: "low",
|
|
40256
|
+
aiSpecific: true,
|
|
40257
|
+
description: "Implicitly unwrapped optional (var x: Type!) \u2014 declare as Type? and unwrap with guard let.",
|
|
40258
|
+
create(_context) {
|
|
40259
|
+
return {};
|
|
40260
|
+
},
|
|
40261
|
+
analyze(_context, facts) {
|
|
40262
|
+
const issues = [];
|
|
40263
|
+
const source = facts.v2?._source;
|
|
40264
|
+
if (!source) return issues;
|
|
40265
|
+
if (!/\.swift$/i.test(facts.filePath)) return issues;
|
|
40266
|
+
let m;
|
|
40267
|
+
IUO_DECL_REGEX.lastIndex = 0;
|
|
40268
|
+
while ((m = IUO_DECL_REGEX.exec(source)) !== null) {
|
|
40269
|
+
const captured = m[0];
|
|
40270
|
+
const bangAt = captured.indexOf("!", captured.indexOf(":"));
|
|
40271
|
+
const between = captured.slice(captured.indexOf(":"), bangAt);
|
|
40272
|
+
if (between.includes("?")) continue;
|
|
40273
|
+
const line = source.slice(0, m.index).split("\n").length;
|
|
40274
|
+
issues.push({
|
|
40275
|
+
ruleId: "swift/implicitly-unwrapped-optional",
|
|
40276
|
+
category: "typo",
|
|
40277
|
+
severity: "low",
|
|
40278
|
+
aiSpecific: true,
|
|
40279
|
+
message: `implicitly unwrapped optional at line ${line} \u2014 declare as Type? and unwrap explicitly`,
|
|
40280
|
+
line,
|
|
40281
|
+
column: 1,
|
|
40282
|
+
advice: 'Declare as `var name: Type?` and unwrap with `guard let name else { ... }` (or `if let`). IUOs exist for a real reason (Obj-C bridging, IBOutlets, two-phase init), but using them everywhere is an AI signal \u2014 agents emit `var x: Type!` because the syntax survives the moment when the agent can\'t decide whether the value is nil. The type system silently says "non-optional" while the runtime says "may be nil". Apple SwiftLint\'s `implicitly_unwrapped_optional` rule flags the same pattern. Reference: swift/implicitly-unwrapped-optional v0.24.'
|
|
40283
|
+
});
|
|
40284
|
+
}
|
|
40285
|
+
return issues;
|
|
40286
|
+
}
|
|
40287
|
+
});
|
|
40288
|
+
|
|
40289
|
+
// src/rules/swift/print-debug.ts
|
|
40290
|
+
var PRINT_REGEX = /\bprint\s*\(/g;
|
|
40291
|
+
var DEFAULT_THRESHOLD3 = 1;
|
|
40292
|
+
var swiftPrintDebugRule = createRule({
|
|
40293
|
+
id: "swift/print-debug",
|
|
40294
|
+
category: "typo",
|
|
40295
|
+
severity: "low",
|
|
40296
|
+
aiSpecific: true,
|
|
40297
|
+
description: "print(...) in production Swift \u2014 use Logger (os.log) for level-controlled output",
|
|
40298
|
+
create(_context) {
|
|
40299
|
+
return { threshold: DEFAULT_THRESHOLD3 };
|
|
40300
|
+
},
|
|
40301
|
+
analyze(context, facts) {
|
|
40302
|
+
const issues = [];
|
|
40303
|
+
const source = facts.v2?._source;
|
|
40304
|
+
if (!source) return issues;
|
|
40305
|
+
if (!/\.swift$/i.test(facts.filePath)) return issues;
|
|
40306
|
+
const matches = [];
|
|
40307
|
+
let m;
|
|
40308
|
+
PRINT_REGEX.lastIndex = 0;
|
|
40309
|
+
while ((m = PRINT_REGEX.exec(source)) !== null) {
|
|
40310
|
+
matches.push(m.index);
|
|
40311
|
+
}
|
|
40312
|
+
if (matches.length <= context.threshold) return issues;
|
|
40313
|
+
const cap = Math.min(matches.length, 10);
|
|
40314
|
+
for (let i = 0; i < cap; i++) {
|
|
40315
|
+
const idx = matches[i];
|
|
40316
|
+
const line = source.slice(0, idx).split("\n").length;
|
|
40317
|
+
issues.push({
|
|
40318
|
+
ruleId: "swift/print-debug",
|
|
40319
|
+
category: "typo",
|
|
40320
|
+
severity: "low",
|
|
40321
|
+
aiSpecific: true,
|
|
40322
|
+
message: `print(...) at line ${line} \u2014 use Logger (os.log) for production output`,
|
|
40323
|
+
line,
|
|
40324
|
+
column: 1,
|
|
40325
|
+
advice: 'Replace with `Logger(subsystem: "...", category: "...").info("...")` (Unified Logging System, os.log). `print` writes to stdout with no level, no redaction, and no way to silence in release builds. The `Logger` API integrates with Console.app and respects the device\'s privacy settings. Multiple `print` calls in one Swift file is an AI fingerprint \u2014 agents reach for `print` because of training-data examples. Reference: swift/print-debug v0.24.'
|
|
40326
|
+
});
|
|
40327
|
+
}
|
|
40328
|
+
return issues;
|
|
40329
|
+
}
|
|
40330
|
+
});
|
|
40331
|
+
|
|
40332
|
+
// src/rules/swift/strong-self-capture.ts
|
|
40333
|
+
var SELF_REF_REGEX = /\bself\.(?:\w+)/g;
|
|
40334
|
+
var CAPTURE_LIST_REGEX = /\[\s*(?:weak|unowned)\s+self\b/;
|
|
40335
|
+
var swiftStrongSelfCaptureRule = createRule({
|
|
40336
|
+
id: "swift/strong-self-capture",
|
|
40337
|
+
category: "logic",
|
|
40338
|
+
severity: "medium",
|
|
40339
|
+
aiSpecific: true,
|
|
40340
|
+
description: "Closure captures `self` strongly \u2014 creates a retain cycle. Use `[weak self]` or `[unowned self]`.",
|
|
40341
|
+
create(_context) {
|
|
40342
|
+
return {};
|
|
40343
|
+
},
|
|
40344
|
+
analyze(_context, facts) {
|
|
40345
|
+
const issues = [];
|
|
40346
|
+
const source = facts.v2?._source;
|
|
40347
|
+
if (!source) return issues;
|
|
40348
|
+
if (!/\.swift$/i.test(facts.filePath)) return issues;
|
|
40349
|
+
const METHOD_HEAD_REGEX = /\b(?:func|init\??|deinit|subscript)\b[^;{}\n]*$/m;
|
|
40350
|
+
let m;
|
|
40351
|
+
SELF_REF_REGEX.lastIndex = 0;
|
|
40352
|
+
while ((m = SELF_REF_REGEX.exec(source)) !== null) {
|
|
40353
|
+
const selfIdx = m.index;
|
|
40354
|
+
let depth = 0;
|
|
40355
|
+
let openBrace = -1;
|
|
40356
|
+
for (let j = selfIdx - 1; j >= 0; j--) {
|
|
40357
|
+
const ch = source.charAt(j);
|
|
40358
|
+
if (ch === "}") depth++;
|
|
40359
|
+
else if (ch === "{") {
|
|
40360
|
+
if (depth === 0) {
|
|
40361
|
+
openBrace = j;
|
|
40362
|
+
break;
|
|
40363
|
+
}
|
|
40364
|
+
depth--;
|
|
40365
|
+
}
|
|
40366
|
+
}
|
|
40367
|
+
if (openBrace === -1) continue;
|
|
40368
|
+
const openLineStart = source.lastIndexOf("\n", openBrace) + 1;
|
|
40369
|
+
const lineBeforeBrace = source.slice(openLineStart, openBrace);
|
|
40370
|
+
if (METHOD_HEAD_REGEX.test(lineBeforeBrace)) continue;
|
|
40371
|
+
const openingSlice = source.slice(openBrace, openBrace + 80);
|
|
40372
|
+
if (CAPTURE_LIST_REGEX.test(openingSlice)) continue;
|
|
40373
|
+
const line = source.slice(0, openBrace).split("\n").length;
|
|
40374
|
+
issues.push({
|
|
40375
|
+
ruleId: "swift/strong-self-capture",
|
|
40376
|
+
category: "logic",
|
|
40377
|
+
severity: "medium",
|
|
40378
|
+
aiSpecific: true,
|
|
40379
|
+
message: `closure at line ${line} captures self strongly \u2014 use [weak self] or [unowned self]`,
|
|
40380
|
+
line,
|
|
40381
|
+
column: 1,
|
|
40382
|
+
advice: 'Capture the closure with `[weak self]` (or `[unowned self]` if you can guarantee non-nil): `[weak self] in self?.foo = bar`. Strong self capture creates a retain cycle \u2014 the closure keeps self alive, self keeps the closure alive, and the cycle is only broken when the runtime gives up and prints a leak. Apple\'s Swift docs use UIKit / UIViewController closures as the canonical example. AI agents write `loadData { self.foo = bar }` because it "just compiles"; the leak is invisible without profiling. Reference: swift/strong-self-capture v0.24.'
|
|
39241
40383
|
});
|
|
39242
40384
|
}
|
|
39243
40385
|
return issues;
|
|
@@ -39245,7 +40387,7 @@ var unsafeHtmlRenderRule = createRule({
|
|
|
39245
40387
|
});
|
|
39246
40388
|
|
|
39247
40389
|
// src/rules/test/utils.ts
|
|
39248
|
-
var
|
|
40390
|
+
var import_node_crypto4 = require("crypto");
|
|
39249
40391
|
function isTestFile(filePath) {
|
|
39250
40392
|
const normalized = filePath.replace(/\\/g, "/");
|
|
39251
40393
|
if (/(^|\/)__tests__\//.test(normalized)) return true;
|
|
@@ -39405,7 +40547,7 @@ function extractSetupBlocks(source, minLines = 3) {
|
|
|
39405
40547
|
}).trim();
|
|
39406
40548
|
const lineCount = rawBody.split("\n").length;
|
|
39407
40549
|
if (lineCount < minLines) continue;
|
|
39408
|
-
const bodyHash = (0,
|
|
40550
|
+
const bodyHash = (0, import_node_crypto4.createHash)("sha1").update(normalizedBody).digest("hex");
|
|
39409
40551
|
const { line, column } = lineColumnOf(source, m.index);
|
|
39410
40552
|
hits.push({
|
|
39411
40553
|
kind,
|
|
@@ -41784,6 +42926,11 @@ var builtinRules = [
|
|
|
41784
42926
|
multipleComponentsPerFileRule,
|
|
41785
42927
|
shadcnPropMismatchRule,
|
|
41786
42928
|
importPathMismatchRule,
|
|
42929
|
+
cppCStyleCastRule,
|
|
42930
|
+
cppMagicNumbersRule,
|
|
42931
|
+
cppPrintfDebugRule,
|
|
42932
|
+
cppRawNewDeleteRule,
|
|
42933
|
+
cppUsingNamespaceStdRule,
|
|
41787
42934
|
duplicateIndexRule,
|
|
41788
42935
|
enumSprawlRule,
|
|
41789
42936
|
missingFkIndexRule,
|
|
@@ -41799,6 +42946,8 @@ var builtinRules = [
|
|
|
41799
42946
|
staleFunctionReferenceRule,
|
|
41800
42947
|
stalePackageReferenceRule,
|
|
41801
42948
|
dupIdenticalBlockRule,
|
|
42949
|
+
nearDuplicateRule,
|
|
42950
|
+
structuralCloneRule,
|
|
41802
42951
|
goErrorWrapWithoutContextRule,
|
|
41803
42952
|
goNilSliceVsEmptyRule,
|
|
41804
42953
|
goStructTagInconsistencyRule,
|
|
@@ -41808,6 +42957,11 @@ var builtinRules = [
|
|
|
41808
42957
|
javaRawTypeOveruseRule,
|
|
41809
42958
|
javaStringConcatLoopRule,
|
|
41810
42959
|
javaSystemOutPrintlnRule,
|
|
42960
|
+
kotlinCoroutineGlobalScopeRule,
|
|
42961
|
+
kotlinDataClassDefaultsOveruseRule,
|
|
42962
|
+
kotlinObjectSingletonMisuseRule,
|
|
42963
|
+
kotlinPrintlnDebugRule,
|
|
42964
|
+
kotlinStringConcatLoopRule,
|
|
41811
42965
|
gapMonopolyRule,
|
|
41812
42966
|
mathElementUniformityRule,
|
|
41813
42967
|
mathGridUniformityRule,
|
|
@@ -41846,6 +43000,11 @@ var builtinRules = [
|
|
|
41846
43000
|
sqlConstructionRule,
|
|
41847
43001
|
targetBlankNoNoopenerRule,
|
|
41848
43002
|
unsafeHtmlRenderRule,
|
|
43003
|
+
swiftFatalErrorThrownRule,
|
|
43004
|
+
swiftForceUnwrapRule,
|
|
43005
|
+
swiftImplicitlyUnwrappedOptionalRule,
|
|
43006
|
+
swiftPrintDebugRule,
|
|
43007
|
+
swiftStrongSelfCaptureRule,
|
|
41849
43008
|
duplicateSetupRule,
|
|
41850
43009
|
fakePlaceholderRule,
|
|
41851
43010
|
missingEdgeCaseRule,
|
|
@@ -42564,9 +43723,9 @@ var signal_strength_default = {
|
|
|
42564
43723
|
ratio: 1,
|
|
42565
43724
|
precision: 0,
|
|
42566
43725
|
lastCalibratedAt: "2026-07-01T00:00:00Z",
|
|
42567
|
-
verdict: "
|
|
43726
|
+
verdict: "OK",
|
|
42568
43727
|
defaultOff: false,
|
|
42569
|
-
_calibrationNote: "v0.19: new rule
|
|
43728
|
+
_calibrationNote: "v0.19: new rule. v8.5 calibration does not run dup/* rules (the calibration script analyzes each file in isolation, but dup/* rules require cross-file state \u2014 the module-scope dedup cache is per-process, not per-file, so per-file analysis never produces cross-file matches and the rule's recall reads as 0). Scheduled for v0.22 calibration on the v9 corpus with a per-project dedup cache. v0.21.1 self-scan: 207 fires in src/ after WINDOW_SIZE 10\u219220 (was 575) \u2014 69% reduction. The actual precision/recall of these 207 fires is unverified ground truth. The rule ships ON (defaultOff=false) because its value is real (block-level duplications are a classic AI-fingerprint) and the corpus-measured 0.0 is a methodology artifact, not a real measurement. Verdict is OK (active, uncalibrated) rather than DORMANT (off, uncalibrated) to satisfy the 'every DORMANT rule must be defaultOff' guardrail.",
|
|
42570
43729
|
aiSpecific: false,
|
|
42571
43730
|
_v7Verdict: "DORMANT",
|
|
42572
43731
|
_v7Lift: 1,
|
|
@@ -42574,8 +43733,39 @@ var signal_strength_default = {
|
|
|
42574
43733
|
_v7FpRate: 0,
|
|
42575
43734
|
_v7Precision: 0,
|
|
42576
43735
|
_v8Verdict: "DORMANT",
|
|
42577
|
-
_v8Lift: 1
|
|
42578
|
-
|
|
43736
|
+
_v8Lift: 1
|
|
43737
|
+
},
|
|
43738
|
+
"dup/near-duplicate": {
|
|
43739
|
+
recall: 0,
|
|
43740
|
+
fpRate: 0,
|
|
43741
|
+
ratio: 1,
|
|
43742
|
+
precision: 0,
|
|
43743
|
+
lastCalibratedAt: "2026-07-02T00:00:00Z",
|
|
43744
|
+
verdict: "DORMANT",
|
|
43745
|
+
defaultOff: true,
|
|
43746
|
+
_calibrationNote: "v0.23.0: new rule, not yet calibrated. Type-2 clone detector using MinHash + Jaccard similarity on k-gram token shingles (k=5). The rule's effectiveness depends on the v9 corpus calibration (see v9-plan-2026-07-02-update.md). The rule catches Type-2a (whitespace + comment differences) reliably; full-rename detection (Type-2b) requires identifier canonicalization or AST similarity (planned for v0.27.0 dup/structural-clone). Default OFF (DORMANT) until v9 corpus calibration confirms precision/recall thresholds.",
|
|
43747
|
+
aiSpecific: true,
|
|
43748
|
+
_v7Verdict: "DORMANT",
|
|
43749
|
+
_v7Lift: 1,
|
|
43750
|
+
_v7Recall: 0,
|
|
43751
|
+
_v7FpRate: 0,
|
|
43752
|
+
_v7Precision: 0
|
|
43753
|
+
},
|
|
43754
|
+
"dup/structural-clone": {
|
|
43755
|
+
recall: 0,
|
|
43756
|
+
fpRate: 0,
|
|
43757
|
+
ratio: 1,
|
|
43758
|
+
precision: 0,
|
|
43759
|
+
lastCalibratedAt: "2026-07-02T00:00:00Z",
|
|
43760
|
+
verdict: "DORMANT",
|
|
43761
|
+
defaultOff: true,
|
|
43762
|
+
_calibrationNote: "v0.24.0: new rule, not yet calibrated. Type-3 clone detector using a two-stage MinHash pipeline \u2014 stage 1 canonicalizes identifiers/literals (rename-invariant k=8 shingles), stage 2 verifies with identifier-aware k=5 shingles (existing shingleSet). Closes the gap near-duplicate left open: identifier renames (Type-3) and statement add/remove. Default OFF (DORMANT) until v9 Java corpus calibration confirms precision/recall thresholds and the v0.24.1 patch raises minHits from 1 to 3.",
|
|
43763
|
+
aiSpecific: true,
|
|
43764
|
+
_v7Verdict: "DORMANT",
|
|
43765
|
+
_v7Lift: 1,
|
|
43766
|
+
_v7Recall: 0,
|
|
43767
|
+
_v7FpRate: 0,
|
|
43768
|
+
_v7Precision: 0
|
|
42579
43769
|
},
|
|
42580
43770
|
"go/error-wrap-without-context": {
|
|
42581
43771
|
recall: 0,
|
|
@@ -43981,6 +45171,276 @@ var signal_strength_default = {
|
|
|
43981
45171
|
_v8Verdict: "DORMANT",
|
|
43982
45172
|
_v8Lift: 1,
|
|
43983
45173
|
defaultOff: true
|
|
45174
|
+
},
|
|
45175
|
+
"kotlin/data-class-defaults-overuse": {
|
|
45176
|
+
recall: 0,
|
|
45177
|
+
fpRate: 0,
|
|
45178
|
+
ratio: 1,
|
|
45179
|
+
precision: 0,
|
|
45180
|
+
lastCalibratedAt: "2026-07-02T00:00:00Z",
|
|
45181
|
+
verdict: "DORMANT",
|
|
45182
|
+
_calibrationNote: "v0.24: new rule (data class with 3+ literal defaults). DORMANT until v9 Kotlin corpus calibration.",
|
|
45183
|
+
aiSpecific: true,
|
|
45184
|
+
_v7Verdict: "DORMANT",
|
|
45185
|
+
_v7Lift: 1,
|
|
45186
|
+
_v7Recall: 0,
|
|
45187
|
+
_v7FpRate: 0,
|
|
45188
|
+
_v7Precision: 0,
|
|
45189
|
+
_v8Verdict: "DORMANT",
|
|
45190
|
+
_v8Lift: 1,
|
|
45191
|
+
defaultOff: true
|
|
45192
|
+
},
|
|
45193
|
+
"kotlin/coroutine-global-scope": {
|
|
45194
|
+
recall: 0,
|
|
45195
|
+
fpRate: 0,
|
|
45196
|
+
ratio: 1,
|
|
45197
|
+
precision: 0,
|
|
45198
|
+
lastCalibratedAt: "2026-07-02T00:00:00Z",
|
|
45199
|
+
verdict: "DORMANT",
|
|
45200
|
+
_calibrationNote: "v0.24: new rule (GlobalScope.launch/async/runBlocking \u2014 bypasses structured concurrency). DORMANT until v9 Kotlin corpus calibration.",
|
|
45201
|
+
aiSpecific: true,
|
|
45202
|
+
_v7Verdict: "DORMANT",
|
|
45203
|
+
_v7Lift: 1,
|
|
45204
|
+
_v7Recall: 0,
|
|
45205
|
+
_v7FpRate: 0,
|
|
45206
|
+
_v7Precision: 0,
|
|
45207
|
+
_v8Verdict: "DORMANT",
|
|
45208
|
+
_v8Lift: 1,
|
|
45209
|
+
defaultOff: true
|
|
45210
|
+
},
|
|
45211
|
+
"kotlin/println-debug": {
|
|
45212
|
+
recall: 0,
|
|
45213
|
+
fpRate: 0,
|
|
45214
|
+
ratio: 1,
|
|
45215
|
+
precision: 0,
|
|
45216
|
+
lastCalibratedAt: "2026-07-02T00:00:00Z",
|
|
45217
|
+
verdict: "DORMANT",
|
|
45218
|
+
_calibrationNote: "v0.24: new rule (multi-println in Kotlin source \u2014 use Timber / android.util.Log). DORMANT until v9 Kotlin corpus calibration.",
|
|
45219
|
+
aiSpecific: true,
|
|
45220
|
+
_v7Verdict: "DORMANT",
|
|
45221
|
+
_v7Lift: 1,
|
|
45222
|
+
_v7Recall: 0,
|
|
45223
|
+
_v7FpRate: 0,
|
|
45224
|
+
_v7Precision: 0,
|
|
45225
|
+
_v8Verdict: "DORMANT",
|
|
45226
|
+
_v8Lift: 1,
|
|
45227
|
+
defaultOff: true
|
|
45228
|
+
},
|
|
45229
|
+
"kotlin/object-singleton-misuse": {
|
|
45230
|
+
recall: 0,
|
|
45231
|
+
fpRate: 0,
|
|
45232
|
+
ratio: 1,
|
|
45233
|
+
precision: 0,
|
|
45234
|
+
lastCalibratedAt: "2026-07-02T00:00:00Z",
|
|
45235
|
+
verdict: "DORMANT",
|
|
45236
|
+
_calibrationNote: "v0.24: new rule (Kotlin `object` singleton holding `var` \u2014 hidden shared state). DORMANT until v9 Kotlin corpus calibration.",
|
|
45237
|
+
aiSpecific: true,
|
|
45238
|
+
_v7Verdict: "DORMANT",
|
|
45239
|
+
_v7Lift: 1,
|
|
45240
|
+
_v7Recall: 0,
|
|
45241
|
+
_v7FpRate: 0,
|
|
45242
|
+
_v7Precision: 0,
|
|
45243
|
+
_v8Verdict: "DORMANT",
|
|
45244
|
+
_v8Lift: 1,
|
|
45245
|
+
defaultOff: true
|
|
45246
|
+
},
|
|
45247
|
+
"kotlin/string-concat-loop": {
|
|
45248
|
+
recall: 0,
|
|
45249
|
+
fpRate: 0,
|
|
45250
|
+
ratio: 1,
|
|
45251
|
+
precision: 0,
|
|
45252
|
+
lastCalibratedAt: "2026-07-02T00:00:00Z",
|
|
45253
|
+
verdict: "DORMANT",
|
|
45254
|
+
_calibrationNote: "v0.24: new rule (string concat inside a Kotlin loop \u2014 use buildString { ... }). DORMANT until v9 Kotlin corpus calibration.",
|
|
45255
|
+
aiSpecific: true,
|
|
45256
|
+
_v7Verdict: "DORMANT",
|
|
45257
|
+
_v7Lift: 1,
|
|
45258
|
+
_v7Recall: 0,
|
|
45259
|
+
_v7FpRate: 0,
|
|
45260
|
+
_v7Precision: 0,
|
|
45261
|
+
_v8Verdict: "DORMANT",
|
|
45262
|
+
_v8Lift: 1,
|
|
45263
|
+
defaultOff: true
|
|
45264
|
+
},
|
|
45265
|
+
"swift/force-unwrap": {
|
|
45266
|
+
recall: 0,
|
|
45267
|
+
fpRate: 0,
|
|
45268
|
+
ratio: 1,
|
|
45269
|
+
precision: 0,
|
|
45270
|
+
lastCalibratedAt: "2026-07-02T00:00:00Z",
|
|
45271
|
+
verdict: "DORMANT",
|
|
45272
|
+
_calibrationNote: "v0.24: new rule (Swift force-unwrap \u2014 `as!`, `try!`, `var!.prop` in production). DORMANT until v9 Swift corpus calibration.",
|
|
45273
|
+
aiSpecific: true,
|
|
45274
|
+
_v7Verdict: "DORMANT",
|
|
45275
|
+
_v7Lift: 1,
|
|
45276
|
+
_v7Recall: 0,
|
|
45277
|
+
_v7FpRate: 0,
|
|
45278
|
+
_v7Precision: 0,
|
|
45279
|
+
_v8Verdict: "DORMANT",
|
|
45280
|
+
_v8Lift: 1,
|
|
45281
|
+
defaultOff: true
|
|
45282
|
+
},
|
|
45283
|
+
"swift/print-debug": {
|
|
45284
|
+
recall: 0,
|
|
45285
|
+
fpRate: 0,
|
|
45286
|
+
ratio: 1,
|
|
45287
|
+
precision: 0,
|
|
45288
|
+
lastCalibratedAt: "2026-07-02T00:00:00Z",
|
|
45289
|
+
verdict: "DORMANT",
|
|
45290
|
+
_calibrationNote: "v0.24: new rule (multi-print in Swift source \u2014 use Logger / os.log). DORMANT until v9 Swift corpus calibration.",
|
|
45291
|
+
aiSpecific: true,
|
|
45292
|
+
_v7Verdict: "DORMANT",
|
|
45293
|
+
_v7Lift: 1,
|
|
45294
|
+
_v7Recall: 0,
|
|
45295
|
+
_v7FpRate: 0,
|
|
45296
|
+
_v7Precision: 0,
|
|
45297
|
+
_v8Verdict: "DORMANT",
|
|
45298
|
+
_v8Lift: 1,
|
|
45299
|
+
defaultOff: true
|
|
45300
|
+
},
|
|
45301
|
+
"swift/fatal-error-thrown": {
|
|
45302
|
+
recall: 0,
|
|
45303
|
+
fpRate: 0,
|
|
45304
|
+
ratio: 1,
|
|
45305
|
+
precision: 0,
|
|
45306
|
+
lastCalibratedAt: "2026-07-02T00:00:00Z",
|
|
45307
|
+
verdict: "DORMANT",
|
|
45308
|
+
_calibrationNote: "v0.24: new rule (`fatalError` / `preconditionFailure` in production Swift \u2014 replaces with typed default). DORMANT until v9 Swift corpus calibration.",
|
|
45309
|
+
aiSpecific: true,
|
|
45310
|
+
_v7Verdict: "DORMANT",
|
|
45311
|
+
_v7Lift: 1,
|
|
45312
|
+
_v7Recall: 0,
|
|
45313
|
+
_v7FpRate: 0,
|
|
45314
|
+
_v7Precision: 0,
|
|
45315
|
+
_v8Verdict: "DORMANT",
|
|
45316
|
+
_v8Lift: 1,
|
|
45317
|
+
defaultOff: true
|
|
45318
|
+
},
|
|
45319
|
+
"swift/implicitly-unwrapped-optional": {
|
|
45320
|
+
recall: 0,
|
|
45321
|
+
fpRate: 0,
|
|
45322
|
+
ratio: 1,
|
|
45323
|
+
precision: 0,
|
|
45324
|
+
lastCalibratedAt: "2026-07-02T00:00:00Z",
|
|
45325
|
+
verdict: "DORMANT",
|
|
45326
|
+
_calibrationNote: "v0.24: new rule (Swift implicitly unwrapped optional \u2014 declare as Type? and unwrap with guard let). DORMANT until v9 Swift corpus calibration.",
|
|
45327
|
+
aiSpecific: true,
|
|
45328
|
+
_v7Verdict: "DORMANT",
|
|
45329
|
+
_v7Lift: 1,
|
|
45330
|
+
_v7Recall: 0,
|
|
45331
|
+
_v7FpRate: 0,
|
|
45332
|
+
_v7Precision: 0,
|
|
45333
|
+
_v8Verdict: "DORMANT",
|
|
45334
|
+
_v8Lift: 1,
|
|
45335
|
+
defaultOff: true
|
|
45336
|
+
},
|
|
45337
|
+
"swift/strong-self-capture": {
|
|
45338
|
+
recall: 0,
|
|
45339
|
+
fpRate: 0,
|
|
45340
|
+
ratio: 1,
|
|
45341
|
+
precision: 0,
|
|
45342
|
+
lastCalibratedAt: "2026-07-02T00:00:00Z",
|
|
45343
|
+
verdict: "DORMANT",
|
|
45344
|
+
_calibrationNote: "v0.24: new rule (Swift closure captures `self` strongly \u2014 retain cycle. Use [weak self] / [unowned self]). DORMANT until v9 Swift corpus calibration.",
|
|
45345
|
+
aiSpecific: true,
|
|
45346
|
+
_v7Verdict: "DORMANT",
|
|
45347
|
+
_v7Lift: 1,
|
|
45348
|
+
_v7Recall: 0,
|
|
45349
|
+
_v7FpRate: 0,
|
|
45350
|
+
_v7Precision: 0,
|
|
45351
|
+
_v8Verdict: "DORMANT",
|
|
45352
|
+
_v8Lift: 1,
|
|
45353
|
+
defaultOff: true
|
|
45354
|
+
},
|
|
45355
|
+
"cpp/using-namespace-std": {
|
|
45356
|
+
recall: 0,
|
|
45357
|
+
fpRate: 0,
|
|
45358
|
+
ratio: 1,
|
|
45359
|
+
precision: 0,
|
|
45360
|
+
lastCalibratedAt: "2026-07-02T00:00:00Z",
|
|
45361
|
+
verdict: "DORMANT",
|
|
45362
|
+
_calibrationNote: "v0.24: new rule (`using namespace std;` in C++ header \u2014 pollutes every consumer). DORMANT until v9 C++ corpus calibration.",
|
|
45363
|
+
aiSpecific: true,
|
|
45364
|
+
_v7Verdict: "DORMANT",
|
|
45365
|
+
_v7Lift: 1,
|
|
45366
|
+
_v7Recall: 0,
|
|
45367
|
+
_v7FpRate: 0,
|
|
45368
|
+
_v7Precision: 0,
|
|
45369
|
+
_v8Verdict: "DORMANT",
|
|
45370
|
+
_v8Lift: 1,
|
|
45371
|
+
defaultOff: true
|
|
45372
|
+
},
|
|
45373
|
+
"cpp/raw-new-delete": {
|
|
45374
|
+
recall: 0,
|
|
45375
|
+
fpRate: 0,
|
|
45376
|
+
ratio: 1,
|
|
45377
|
+
precision: 0,
|
|
45378
|
+
lastCalibratedAt: "2026-07-02T00:00:00Z",
|
|
45379
|
+
verdict: "DORMANT",
|
|
45380
|
+
_calibrationNote: "v0.24: new rule (manual `new` / `delete` pairing in C++ \u2014 use std::make_unique / std::unique_ptr). DORMANT until v9 C++ corpus calibration.",
|
|
45381
|
+
aiSpecific: true,
|
|
45382
|
+
_v7Verdict: "DORMANT",
|
|
45383
|
+
_v7Lift: 1,
|
|
45384
|
+
_v7Recall: 0,
|
|
45385
|
+
_v7FpRate: 0,
|
|
45386
|
+
_v7Precision: 0,
|
|
45387
|
+
_v8Verdict: "DORMANT",
|
|
45388
|
+
_v8Lift: 1,
|
|
45389
|
+
defaultOff: true
|
|
45390
|
+
},
|
|
45391
|
+
"cpp/c-style-cast": {
|
|
45392
|
+
recall: 0,
|
|
45393
|
+
fpRate: 0,
|
|
45394
|
+
ratio: 1,
|
|
45395
|
+
precision: 0,
|
|
45396
|
+
lastCalibratedAt: "2026-07-02T00:00:00Z",
|
|
45397
|
+
verdict: "DORMANT",
|
|
45398
|
+
_calibrationNote: "v0.24: new rule (C-style cast `(int)x` in C++ \u2014 use static_cast / reinterpret_cast / const_cast). DORMANT until v9 C++ corpus calibration.",
|
|
45399
|
+
aiSpecific: true,
|
|
45400
|
+
_v7Verdict: "DORMANT",
|
|
45401
|
+
_v7Lift: 1,
|
|
45402
|
+
_v7Recall: 0,
|
|
45403
|
+
_v7FpRate: 0,
|
|
45404
|
+
_v7Precision: 0,
|
|
45405
|
+
_v8Verdict: "DORMANT",
|
|
45406
|
+
_v8Lift: 1,
|
|
45407
|
+
defaultOff: true
|
|
45408
|
+
},
|
|
45409
|
+
"cpp/printf-debug": {
|
|
45410
|
+
recall: 0,
|
|
45411
|
+
fpRate: 0,
|
|
45412
|
+
ratio: 1,
|
|
45413
|
+
precision: 0,
|
|
45414
|
+
lastCalibratedAt: "2026-07-02T00:00:00Z",
|
|
45415
|
+
verdict: "DORMANT",
|
|
45416
|
+
_calibrationNote: "v0.24: new rule (printf family / std::cout debug printing in C++ \u2014 use spdlog / glog / AbslLog). DORMANT until v9 C++ corpus calibration.",
|
|
45417
|
+
aiSpecific: true,
|
|
45418
|
+
_v7Verdict: "DORMANT",
|
|
45419
|
+
_v7Lift: 1,
|
|
45420
|
+
_v7Recall: 0,
|
|
45421
|
+
_v7FpRate: 0,
|
|
45422
|
+
_v7Precision: 0,
|
|
45423
|
+
_v8Verdict: "DORMANT",
|
|
45424
|
+
_v8Lift: 1,
|
|
45425
|
+
defaultOff: true
|
|
45426
|
+
},
|
|
45427
|
+
"cpp/magic-numbers": {
|
|
45428
|
+
recall: 0,
|
|
45429
|
+
fpRate: 0,
|
|
45430
|
+
ratio: 1,
|
|
45431
|
+
precision: 0,
|
|
45432
|
+
lastCalibratedAt: "2026-07-02T00:00:00Z",
|
|
45433
|
+
verdict: "DORMANT",
|
|
45434
|
+
_calibrationNote: "v0.24: new rule (magic-number literal in C++ comparison / return \u2014 name it `constexpr int MAX = ...`). DORMANT until v9 C++ corpus calibration.",
|
|
45435
|
+
aiSpecific: true,
|
|
45436
|
+
_v7Verdict: "DORMANT",
|
|
45437
|
+
_v7Lift: 1,
|
|
45438
|
+
_v7Recall: 0,
|
|
45439
|
+
_v7FpRate: 0,
|
|
45440
|
+
_v7Precision: 0,
|
|
45441
|
+
_v8Verdict: "DORMANT",
|
|
45442
|
+
_v8Lift: 1,
|
|
45443
|
+
defaultOff: true
|
|
43984
45444
|
}
|
|
43985
45445
|
};
|
|
43986
45446
|
|