slopbrick 0.21.2 → 0.25.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.
@@ -7,7 +7,8 @@ var __export = (target, all) => {
7
7
  // src/engine/worker.ts
8
8
  import { isMainThread, parentPort, workerData } from "worker_threads";
9
9
  import { extname as extname4 } from "path";
10
- import { join as join11 } from "path";
10
+ import { join as join11, relative as relative2, sep } from "path";
11
+ import { minimatch } from "minimatch";
11
12
 
12
13
  // ../engine/dist/index.js
13
14
  import { readFile, writeFile, mkdir, access } from "fs/promises";
@@ -4335,6 +4336,7 @@ function parseSource(source, filePath) {
4335
4336
  case "py":
4336
4337
  case "go":
4337
4338
  case "rs":
4339
+ case "java":
4338
4340
  return parseBlankModule(source);
4339
4341
  default:
4340
4342
  return parseWithSwc(source, filePath);
@@ -34376,6 +34378,232 @@ var importPathMismatchRule = createRule({
34376
34378
  }
34377
34379
  });
34378
34380
 
34381
+ // src/rules/cpp/c-style-cast.ts
34382
+ 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;
34383
+ var NAMED_CAST_PREFIX_REGEX = /\b(?:static|reinterpret|const|dynamic)_cast\s*<[^>]*>\s*\($/;
34384
+ var cppCStyleCastRule = createRule({
34385
+ id: "cpp/c-style-cast",
34386
+ category: "typo",
34387
+ severity: "low",
34388
+ aiSpecific: true,
34389
+ description: "C-style cast `(int)x` \u2014 use static_cast / reinterpret_cast / const_cast so the kind is greppable.",
34390
+ create(_context) {
34391
+ return {};
34392
+ },
34393
+ analyze(_context, facts) {
34394
+ const issues = [];
34395
+ const source = facts.v2?._source;
34396
+ if (!source) return issues;
34397
+ if (!/\.(cpp|cc|cxx|h|hpp|hh|hxx|H)$/i.test(facts.filePath)) return issues;
34398
+ let m;
34399
+ C_STYLE_CAST_REGEX.lastIndex = 0;
34400
+ while ((m = C_STYLE_CAST_REGEX.exec(source)) !== null) {
34401
+ const innerMatch = /\(\s*([^)]+?)\s*\)/.exec(m[0]) ?? [];
34402
+ const inner = (innerMatch[1] ?? "").trim();
34403
+ const looksLikeCast = /\b(?:int|long|short|char|float|double|bool|unsigned|signed|size_t)\b/.test(inner) || /[*&]/.test(inner);
34404
+ if (!looksLikeCast) continue;
34405
+ const before = source.slice(Math.max(0, m.index - 40), m.index);
34406
+ if (NAMED_CAST_PREFIX_REGEX.test(before)) continue;
34407
+ const line = source.slice(0, m.index).split("\n").length;
34408
+ issues.push({
34409
+ ruleId: "cpp/c-style-cast",
34410
+ category: "typo",
34411
+ severity: "low",
34412
+ aiSpecific: true,
34413
+ message: `C-style cast at line ${line} \u2014 use static_cast / reinterpret_cast / const_cast`,
34414
+ line,
34415
+ column: 1,
34416
+ 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."
34417
+ });
34418
+ }
34419
+ return issues;
34420
+ }
34421
+ });
34422
+
34423
+ // src/rules/cpp/magic-numbers.ts
34424
+ var MAGIC_NUMBER_REGEX = /\b(\d+(?:\.\d+)?)\b/g;
34425
+ var COMPARE_OR_RETURN_REGEX = /\b(?:if|while|return|for)\s*[\(\s]?[^;]*[<>=!][^;]*/;
34426
+ var cppMagicNumbersRule = createRule({
34427
+ id: "cpp/magic-numbers",
34428
+ category: "typo",
34429
+ severity: "low",
34430
+ aiSpecific: true,
34431
+ description: "Magic-number literal in a comparison / return \u2014 name it: `constexpr int MAX = 1024;`.",
34432
+ create(_context) {
34433
+ return {};
34434
+ },
34435
+ analyze(_context, facts) {
34436
+ const issues = [];
34437
+ const source = facts.v2?._source;
34438
+ if (!source) return issues;
34439
+ if (!/\.(cpp|cc|cxx|h|hpp|hh|hxx|H)$/i.test(facts.filePath)) return issues;
34440
+ const lines = source.split("\n");
34441
+ const allowSet = /* @__PURE__ */ new Set([
34442
+ "1024",
34443
+ "65535",
34444
+ "65536",
34445
+ "86400",
34446
+ "3600",
34447
+ "1000",
34448
+ "100.0",
34449
+ "60",
34450
+ "24",
34451
+ "7",
34452
+ "365",
34453
+ "256",
34454
+ "255",
34455
+ "0",
34456
+ "1",
34457
+ "2",
34458
+ "3",
34459
+ "4",
34460
+ "5"
34461
+ ]);
34462
+ for (let i = 0; i < lines.length; i++) {
34463
+ const line = lines[i] ?? "";
34464
+ if (!COMPARE_OR_RETURN_REGEX.test(line)) continue;
34465
+ let m;
34466
+ MAGIC_NUMBER_REGEX.lastIndex = 0;
34467
+ while ((m = MAGIC_NUMBER_REGEX.exec(line)) !== null) {
34468
+ const literal = m[0] ?? "";
34469
+ if (allowSet.has(literal)) continue;
34470
+ if (/\b(?:constexpr|const)\s+\w+\s*=\s*$/.test(line.slice(0, m.index).trimEnd())) continue;
34471
+ const prevLine = i > 0 ? lines[i - 1] ?? "" : "";
34472
+ if (/\b(?:constexpr|const)\s+\w+\s*=\s*$/.test(prevLine.trim())) continue;
34473
+ issues.push({
34474
+ ruleId: "cpp/magic-numbers",
34475
+ category: "typo",
34476
+ severity: "low",
34477
+ aiSpecific: true,
34478
+ message: `magic number ${literal} at line ${i + 1} \u2014 name it: constexpr int MAX = ${literal};`,
34479
+ line: i + 1,
34480
+ column: 1,
34481
+ 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.'
34482
+ });
34483
+ }
34484
+ }
34485
+ return issues;
34486
+ }
34487
+ });
34488
+
34489
+ // src/rules/cpp/printf-debug.ts
34490
+ var PRINTF_FAMILY_REGEX = /\b(?:printf|fprintf|sprintf|snprintf)\s*\(/g;
34491
+ var COUT_LITERAL_REGEX = /std\s*::\s*(?:cout|cerr|clog)\s*<<\s*"[^"]*"/g;
34492
+ var STD_COUT_BARE_REGEX = /std\s*::\s*(?:cout|cerr|clog)\s*<<\s*'[^']*'/g;
34493
+ var THRESHOLD_DEFAULT = 1;
34494
+ var cppPrintfDebugRule = createRule({
34495
+ id: "cpp/printf-debug",
34496
+ category: "typo",
34497
+ severity: "low",
34498
+ aiSpecific: true,
34499
+ description: "printf family or std::cout debug printing \u2014 use spdlog / glog / AbslLog for level-controlled output.",
34500
+ create(_context) {
34501
+ return { threshold: THRESHOLD_DEFAULT };
34502
+ },
34503
+ analyze(context, facts) {
34504
+ const issues = [];
34505
+ const source = facts.v2?._source;
34506
+ if (!source) return issues;
34507
+ if (!/\.(cpp|cc|cxx|h|hpp|hh|hxx|H)$/i.test(facts.filePath)) return issues;
34508
+ const printfCount = (source.match(PRINTF_FAMILY_REGEX) ?? []).length;
34509
+ let viaPrintf = false;
34510
+ if (printfCount > context.threshold) {
34511
+ const line = source.indexOf("printf");
34512
+ if (line !== -1) viaPrintf = true;
34513
+ }
34514
+ const coutHit = COUT_LITERAL_REGEX.test(source) || STD_COUT_BARE_REGEX.test(source);
34515
+ if (!viaPrintf && !coutHit) return issues;
34516
+ issues.push({
34517
+ ruleId: "cpp/printf-debug",
34518
+ category: "typo",
34519
+ severity: "low",
34520
+ aiSpecific: true,
34521
+ message: viaPrintf ? `${printfCount} printf-family calls \u2014 use spdlog / glog / AbslLog` : "std::cout/cerr/clog with a string literal \u2014 use spdlog / glog / AbslLog",
34522
+ line: 1,
34523
+ column: 1,
34524
+ 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."
34525
+ });
34526
+ return issues;
34527
+ }
34528
+ });
34529
+
34530
+ // src/rules/cpp/raw-new-delete.ts
34531
+ var NEW_TYPE_REGEX = /\bnew\s+[A-Za-z_]\w*\s*\(/g;
34532
+ var DELETE_REGEX = /\bdelete\s+/g;
34533
+ var MIN_PAIRS_DEFAULT = 1;
34534
+ var cppRawNewDeleteRule = createRule({
34535
+ id: "cpp/raw-new-delete",
34536
+ category: "typo",
34537
+ severity: "low",
34538
+ aiSpecific: true,
34539
+ description: "Manual `new` / `delete` pairing \u2014 use std::make_unique / std::unique_ptr instead.",
34540
+ create(_context) {
34541
+ return { minPairs: MIN_PAIRS_DEFAULT };
34542
+ },
34543
+ analyze(context, facts) {
34544
+ const issues = [];
34545
+ const source = facts.v2?._source;
34546
+ if (!source) return issues;
34547
+ if (!/\.(cpp|cc|cxx|h|hpp|hh|hxx|H)$/i.test(facts.filePath)) return issues;
34548
+ let newCount = 0;
34549
+ let m;
34550
+ NEW_TYPE_REGEX.lastIndex = 0;
34551
+ while ((m = NEW_TYPE_REGEX.exec(source)) !== null) newCount++;
34552
+ let deleteCount = 0;
34553
+ DELETE_REGEX.lastIndex = 0;
34554
+ while ((m = DELETE_REGEX.exec(source)) !== null) deleteCount++;
34555
+ if (newCount <= context.minPairs) return issues;
34556
+ if (deleteCount <= context.minPairs) return issues;
34557
+ issues.push({
34558
+ ruleId: "cpp/raw-new-delete",
34559
+ category: "typo",
34560
+ severity: "low",
34561
+ aiSpecific: true,
34562
+ message: `manual new/delete pairing (${newCount} new, ${deleteCount} delete) \u2014 wrap in std::unique_ptr`,
34563
+ line: 1,
34564
+ column: 1,
34565
+ 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."
34566
+ });
34567
+ return issues;
34568
+ }
34569
+ });
34570
+
34571
+ // src/rules/cpp/using-namespace-std.ts
34572
+ var USING_NAMESPACE_STD_REGEX = /\busing\s+namespace\s+std\s*;/g;
34573
+ var cppUsingNamespaceStdRule = createRule({
34574
+ id: "cpp/using-namespace-std",
34575
+ category: "logic",
34576
+ severity: "medium",
34577
+ aiSpecific: true,
34578
+ description: "`using namespace std;` in a header \u2014 pollutes every consumer. Use `using std::foo;` or qualify names.",
34579
+ create(_context) {
34580
+ return {};
34581
+ },
34582
+ analyze(_context, facts) {
34583
+ const issues = [];
34584
+ const source = facts.v2?._source;
34585
+ if (!source) return issues;
34586
+ if (!/\.(cpp|cc|cxx|h|hpp|hh|hxx|H)$/i.test(facts.filePath)) return issues;
34587
+ if (!/\.(h|hpp|hh|hxx|H)$/i.test(facts.filePath)) return issues;
34588
+ let m;
34589
+ USING_NAMESPACE_STD_REGEX.lastIndex = 0;
34590
+ while ((m = USING_NAMESPACE_STD_REGEX.exec(source)) !== null) {
34591
+ const line = source.slice(0, m.index).split("\n").length;
34592
+ issues.push({
34593
+ ruleId: "cpp/using-namespace-std",
34594
+ category: "logic",
34595
+ severity: "medium",
34596
+ aiSpecific: true,
34597
+ message: `using namespace std; at line ${line} \u2014 pollutes every consumer of this header`,
34598
+ line,
34599
+ column: 1,
34600
+ 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."
34601
+ });
34602
+ }
34603
+ return issues;
34604
+ }
34605
+ });
34606
+
34379
34607
  // src/rules/db/duplicate-index.ts
34380
34608
  import { parseSync as parseSql, loadModule as loadSqlModule } from "pgsql-parser";
34381
34609
  var moduleReady = loadSqlModule();
@@ -36108,6 +36336,480 @@ var dupIdenticalBlockRule = createRule({
36108
36336
  }
36109
36337
  });
36110
36338
 
36339
+ // src/engine/dedup/tokenize.ts
36340
+ import { createHash as createHash3 } from "crypto";
36341
+ var DEFAULT_CONFIG = { k: 5 };
36342
+ function stripComments(source) {
36343
+ let out = "";
36344
+ let i = 0;
36345
+ while (i < source.length) {
36346
+ const ch = source[i];
36347
+ const next = source[i + 1];
36348
+ if (ch === "/" && next === "/") {
36349
+ while (i < source.length && source[i] !== "\n") i++;
36350
+ continue;
36351
+ }
36352
+ if (ch === "/" && next === "*") {
36353
+ i += 2;
36354
+ while (i < source.length && !(source[i] === "*" && source[i + 1] === "/")) i++;
36355
+ i += 2;
36356
+ continue;
36357
+ }
36358
+ out += ch;
36359
+ i++;
36360
+ }
36361
+ return out;
36362
+ }
36363
+ function tokenize(source) {
36364
+ return source.toLowerCase().split(/[^a-z0-9_]+/u).filter((t) => t.length > 0);
36365
+ }
36366
+ function shingleHash(shingle) {
36367
+ const h = createHash3("sha1").update(shingle).digest();
36368
+ return (h[0] ?? 0) << 24 | (h[1] ?? 0) << 16 | (h[2] ?? 0) << 8 | (h[3] ?? 0);
36369
+ }
36370
+ function shingleSet(source, config = {}) {
36371
+ const { k } = { ...DEFAULT_CONFIG, ...config };
36372
+ const tokens = tokenize(stripComments(source));
36373
+ if (tokens.length === 0) return /* @__PURE__ */ new Set();
36374
+ if (tokens.length < k) {
36375
+ return /* @__PURE__ */ new Set([shingleHash(tokens.join(" "))]);
36376
+ }
36377
+ const out = /* @__PURE__ */ new Set();
36378
+ for (let i = 0; i + k <= tokens.length; i++) {
36379
+ out.add(shingleHash(tokens.slice(i, i + k).join(" ")));
36380
+ }
36381
+ return out;
36382
+ }
36383
+
36384
+ // src/engine/dedup/minhash.ts
36385
+ import { createHash as createHash4 } from "crypto";
36386
+ var PRIME = (1n << 61n) - 1n;
36387
+ function mix64(x) {
36388
+ x ^= x >> 33n;
36389
+ x = x * 0xff51afd7ed558ccdn & 0xffffffffffffffffn;
36390
+ x ^= x >> 33n;
36391
+ x = x * 0xc4ceb9fe1a85ec53n & 0xffffffffffffffffn;
36392
+ x ^= x >> 33n;
36393
+ return x;
36394
+ }
36395
+ function bmod(a, m) {
36396
+ const r = a % m;
36397
+ return r < 0n ? r + m : r;
36398
+ }
36399
+ function hashParams(i) {
36400
+ const a = mix64(BigInt(i) * 0x9e3779b97f4a7c15n) & 0xffffffffffffffffn | 1n;
36401
+ const b = mix64(BigInt(i) * 0xbf58476d1ce4e5b9n) & 0xffffffffffffffffn;
36402
+ return [a, b];
36403
+ }
36404
+ function hashAt(i, x) {
36405
+ const [a, b] = hashParams(i);
36406
+ const xb = BigInt(x >>> 0);
36407
+ const combined = a * xb + b;
36408
+ const h = Number(bmod(combined, PRIME) & 0xffffffffn);
36409
+ return h >>> 0;
36410
+ }
36411
+ var DEFAULT_CONFIG2 = {
36412
+ numHashes: 128
36413
+ };
36414
+ function minHash(tokens, config = {}) {
36415
+ const { numHashes } = { ...DEFAULT_CONFIG2, ...config };
36416
+ const sig = new Uint32Array(numHashes);
36417
+ sig.fill(4294967295);
36418
+ const tokenIter = tokens instanceof Set ? tokens : Array.from(tokens);
36419
+ for (const t of tokenIter) {
36420
+ for (let i = 0; i < numHashes; i++) {
36421
+ const h = hashAt(i, t);
36422
+ if (h < (sig[i] ?? 4294967295)) sig[i] = h;
36423
+ }
36424
+ }
36425
+ return sig;
36426
+ }
36427
+ function minHashSimilarity(a, b) {
36428
+ if (a.length !== b.length) {
36429
+ throw new Error(`minHashSimilarity: length mismatch ${a.length} vs ${b.length}`);
36430
+ }
36431
+ if (a.length === 0) return 1;
36432
+ let matches = 0;
36433
+ for (let i = 0; i < a.length; i++) {
36434
+ if (a[i] === b[i]) matches++;
36435
+ }
36436
+ return matches / a.length;
36437
+ }
36438
+
36439
+ // src/rules/dup/near-duplicate.ts
36440
+ var DEFAULT_CONTEXT = {
36441
+ threshold: 0.7,
36442
+ k: 5
36443
+ };
36444
+ var signatureCache = /* @__PURE__ */ new Map();
36445
+ var nearDuplicateRule = createRule({
36446
+ id: "dup/near-duplicate",
36447
+ category: "logic",
36448
+ severity: "medium",
36449
+ aiSpecific: true,
36450
+ description: "Near-duplicate file (Type-2 clone) \u2014 token-set Jaccard similarity > 0.7 after MinHash. Catches AI whitespace/comment refactors.",
36451
+ create(_context) {
36452
+ return { ...DEFAULT_CONTEXT };
36453
+ },
36454
+ analyze(context, facts) {
36455
+ const ctx = { ...DEFAULT_CONTEXT, ...context };
36456
+ const issues = [];
36457
+ const source = facts.v2?._source;
36458
+ if (!source) return issues;
36459
+ const filePath = facts.filePath;
36460
+ if (!filePath) return issues;
36461
+ const shingles = shingleSet(source, { k: ctx.k });
36462
+ if (shingles.size === 0) return issues;
36463
+ const sig = minHash(shingles);
36464
+ const matched = [];
36465
+ for (const [prevPath, prevSig] of signatureCache.entries()) {
36466
+ const sim = minHashSimilarity(sig, prevSig);
36467
+ if (sim >= ctx.threshold) {
36468
+ matched.push({ path: prevPath, similarity: sim });
36469
+ }
36470
+ }
36471
+ if (matched.length > 0) {
36472
+ matched.sort((a, b) => b.similarity - a.similarity);
36473
+ const best = matched[0];
36474
+ issues.push({
36475
+ ruleId: "dup/near-duplicate",
36476
+ category: "logic",
36477
+ severity: "medium",
36478
+ aiSpecific: true,
36479
+ message: `Near-duplicate of ${best.path} (Jaccard ${(best.similarity * 100).toFixed(1)}%, threshold ${(ctx.threshold * 100).toFixed(0)}%)`,
36480
+ line: 1,
36481
+ column: 1,
36482
+ 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."
36483
+ });
36484
+ }
36485
+ signatureCache.set(filePath, sig);
36486
+ return issues;
36487
+ }
36488
+ });
36489
+
36490
+ // src/engine/dedup/lsh.ts
36491
+ import { createHash as createHash5 } from "crypto";
36492
+
36493
+ // src/engine/dedup/structural-clone.ts
36494
+ function stripComments2(source) {
36495
+ let out = "";
36496
+ let i = 0;
36497
+ while (i < source.length) {
36498
+ const ch = source[i];
36499
+ const next = source[i + 1];
36500
+ if (ch === "/" && next === "/") {
36501
+ while (i < source.length && source[i] !== "\n") i++;
36502
+ continue;
36503
+ }
36504
+ if (ch === "/" && next === "*") {
36505
+ i += 2;
36506
+ while (i < source.length && !(source[i] === "*" && source[i + 1] === "/")) i++;
36507
+ i += 2;
36508
+ continue;
36509
+ }
36510
+ out += ch;
36511
+ i++;
36512
+ }
36513
+ return out;
36514
+ }
36515
+ var TOKEN_REGEX = /([A-Za-z_$][A-Za-z0-9_$]*)|(0[xX][0-9A-Fa-f]+|\d+(?:\.\d+)?(?:[eE][+-]?\d+)?[fFdDlL]?)|([(){}\[\];,.<>=+\-*/%!&|^?:])|"((?:[^"\\\n]|\\.)*)"|'((?:[^'\\\n]|\\.)*)'|`((?:[^`\\]|\\.)*)`/g;
36516
+ var BOOL_TOKENS = /* @__PURE__ */ new Set(["true", "false", "null", "none", "nil"]);
36517
+ var KEYWORDS = /* @__PURE__ */ new Set([
36518
+ // Control flow
36519
+ "if",
36520
+ "else",
36521
+ "for",
36522
+ "while",
36523
+ "do",
36524
+ "switch",
36525
+ "case",
36526
+ "default",
36527
+ "break",
36528
+ "continue",
36529
+ "return",
36530
+ "goto",
36531
+ // Declarations
36532
+ "function",
36533
+ "class",
36534
+ "interface",
36535
+ "struct",
36536
+ "enum",
36537
+ "trait",
36538
+ "def",
36539
+ "fn",
36540
+ "fun",
36541
+ "func",
36542
+ "var",
36543
+ "let",
36544
+ "const",
36545
+ "val",
36546
+ "mod",
36547
+ "use",
36548
+ "pub",
36549
+ "impl",
36550
+ "package",
36551
+ "module",
36552
+ "lambda",
36553
+ // Modifiers / visibility
36554
+ "public",
36555
+ "private",
36556
+ "protected",
36557
+ "static",
36558
+ "abstract",
36559
+ "final",
36560
+ "sealed",
36561
+ "override",
36562
+ "virtual",
36563
+ "readonly",
36564
+ "async",
36565
+ "await",
36566
+ "synchronized",
36567
+ "volatile",
36568
+ "transient",
36569
+ "native",
36570
+ "strictfp",
36571
+ "inline",
36572
+ "external",
36573
+ "export",
36574
+ "import",
36575
+ // Type system
36576
+ "type",
36577
+ "interface",
36578
+ "record",
36579
+ "object",
36580
+ "enum",
36581
+ "data",
36582
+ // Pattern / dispatch
36583
+ "match",
36584
+ "select",
36585
+ "when",
36586
+ "where",
36587
+ // Error handling
36588
+ "try",
36589
+ "catch",
36590
+ "finally",
36591
+ "throw",
36592
+ "throws",
36593
+ "raise",
36594
+ "rescue",
36595
+ "ensure",
36596
+ "except",
36597
+ // Logical connectives and tests
36598
+ "and",
36599
+ "or",
36600
+ "not",
36601
+ "in",
36602
+ "is",
36603
+ "as",
36604
+ "instanceof",
36605
+ "typeof",
36606
+ "delete",
36607
+ "void",
36608
+ "new",
36609
+ "this",
36610
+ "super",
36611
+ "self",
36612
+ "yield",
36613
+ // Misc
36614
+ "with",
36615
+ "without",
36616
+ "pass",
36617
+ "assert",
36618
+ "mut",
36619
+ "move",
36620
+ "ref",
36621
+ "out",
36622
+ "params",
36623
+ "operator",
36624
+ "sizeof",
36625
+ "typedef",
36626
+ "union",
36627
+ "register",
36628
+ "extern",
36629
+ "volatile",
36630
+ "goto",
36631
+ // Python-specific
36632
+ "elif",
36633
+ "global",
36634
+ "nonlocal",
36635
+ "del",
36636
+ "with",
36637
+ // Ruby-specific
36638
+ "unless",
36639
+ "until",
36640
+ "begin",
36641
+ "next",
36642
+ "then",
36643
+ "end",
36644
+ "alias",
36645
+ "defined",
36646
+ "super",
36647
+ "yield",
36648
+ "self",
36649
+ // Kotlin-specific
36650
+ "suspend",
36651
+ "lateinit",
36652
+ "companion",
36653
+ "internal",
36654
+ "open",
36655
+ // Rust-specific
36656
+ "unsafe",
36657
+ "dyn",
36658
+ "box",
36659
+ "crate",
36660
+ "where",
36661
+ // Swift-specific
36662
+ "guard",
36663
+ "defer",
36664
+ "repeat",
36665
+ "init",
36666
+ "deinit",
36667
+ "extension",
36668
+ "protocol",
36669
+ "throws",
36670
+ "rethrows",
36671
+ "weak",
36672
+ "unowned",
36673
+ "lazy"
36674
+ ]);
36675
+ function canonicalTokens(source) {
36676
+ const stripped = stripComments2(source);
36677
+ const out = [];
36678
+ TOKEN_REGEX.lastIndex = 0;
36679
+ let m;
36680
+ while ((m = TOKEN_REGEX.exec(stripped)) !== null) {
36681
+ const [, ident, num, punct, dq, sq, bq] = m;
36682
+ if (ident !== void 0) {
36683
+ const lower = ident.toLowerCase();
36684
+ if (BOOL_TOKENS.has(lower)) {
36685
+ out.push("bool");
36686
+ } else if (KEYWORDS.has(lower)) {
36687
+ out.push(lower);
36688
+ } else {
36689
+ out.push("id");
36690
+ }
36691
+ continue;
36692
+ }
36693
+ if (num !== void 0) {
36694
+ out.push("num");
36695
+ continue;
36696
+ }
36697
+ if (punct !== void 0) {
36698
+ out.push(punct);
36699
+ continue;
36700
+ }
36701
+ if (dq !== void 0 || sq !== void 0 || bq !== void 0) {
36702
+ out.push("str");
36703
+ continue;
36704
+ }
36705
+ }
36706
+ return out;
36707
+ }
36708
+ function shingleHash2(shingle) {
36709
+ let h = 2166136261;
36710
+ for (let i = 0; i < shingle.length; i++) {
36711
+ h ^= shingle.charCodeAt(i);
36712
+ h = Math.imul(h, 16777619) >>> 0;
36713
+ }
36714
+ return h >>> 0;
36715
+ }
36716
+ var DEFAULT_STRUCTURAL_CONFIG = {
36717
+ k: 8,
36718
+ minTokens: 60
36719
+ };
36720
+ function structuralShingles(source, config = {}) {
36721
+ const { k, minTokens } = { ...DEFAULT_STRUCTURAL_CONFIG, ...config };
36722
+ const tokens = canonicalTokens(source);
36723
+ if (tokens.length < minTokens) return /* @__PURE__ */ new Set();
36724
+ if (tokens.length < k) {
36725
+ return /* @__PURE__ */ new Set([shingleHash2(tokens.join(" "))]);
36726
+ }
36727
+ const out = /* @__PURE__ */ new Set();
36728
+ for (let i = 0; i + k <= tokens.length; i++) {
36729
+ out.add(shingleHash2(tokens.slice(i, i + k).join(" ")));
36730
+ }
36731
+ return out;
36732
+ }
36733
+ function structuralSignature(source, config = {}) {
36734
+ return minHash(structuralShingles(source, config));
36735
+ }
36736
+
36737
+ // src/rules/dup/structural-clone.ts
36738
+ var DEFAULT_CONTEXT2 = {
36739
+ structuralThreshold: 0.55,
36740
+ verifyThreshold: 0.45,
36741
+ kStruct: 8,
36742
+ kIdent: 5,
36743
+ minTokens: 60,
36744
+ minHits: 1
36745
+ };
36746
+ var structuralCache = /* @__PURE__ */ new Map();
36747
+ var identifierCache = /* @__PURE__ */ new Map();
36748
+ var structuralCloneRule = createRule({
36749
+ id: "dup/structural-clone",
36750
+ category: "logic",
36751
+ severity: "medium",
36752
+ aiSpecific: true,
36753
+ defaultOff: true,
36754
+ description: "Structural clone (Type-3) \u2014 same shape after identifier canonicalization with possible added/removed statements. Two-stage MinHash: canonical + identifier.",
36755
+ create(_context) {
36756
+ return { ...DEFAULT_CONTEXT2 };
36757
+ },
36758
+ analyze(context, facts) {
36759
+ const ctx = { ...DEFAULT_CONTEXT2, ...context };
36760
+ const issues = [];
36761
+ const source = facts.v2?._source;
36762
+ if (!source) return issues;
36763
+ const filePath = facts.filePath;
36764
+ if (!filePath) return issues;
36765
+ const sigStruct = structuralSignature(source, {
36766
+ k: ctx.kStruct,
36767
+ minTokens: ctx.minTokens
36768
+ });
36769
+ if (sigStruct.every((v) => v === 4294967295)) return issues;
36770
+ const identShingles = shingleSet(source, { k: ctx.kIdent });
36771
+ if (identShingles.size === 0) return issues;
36772
+ const sigIdent = minHash(identShingles);
36773
+ const matched = [];
36774
+ for (const [prevPath, prevStruct] of structuralCache.entries()) {
36775
+ if (prevPath === filePath) continue;
36776
+ const simStruct = minHashSimilarity(sigStruct, prevStruct);
36777
+ if (simStruct < ctx.structuralThreshold) continue;
36778
+ const prevIdent = identifierCache.get(prevPath);
36779
+ if (!prevIdent) continue;
36780
+ const simIdent = minHashSimilarity(sigIdent, prevIdent);
36781
+ if (simIdent <= 0) continue;
36782
+ const score = 2 * simStruct * simIdent / (simStruct + simIdent + 1e-9);
36783
+ if (score >= ctx.verifyThreshold) {
36784
+ matched.push({ path: prevPath, score, simStruct, simIdent });
36785
+ }
36786
+ }
36787
+ if (matched.length >= ctx.minHits) {
36788
+ matched.sort((a, b) => b.score - a.score);
36789
+ const best = matched[0];
36790
+ issues.push({
36791
+ ruleId: "dup/structural-clone",
36792
+ category: "logic",
36793
+ severity: "medium",
36794
+ aiSpecific: true,
36795
+ 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)}%)`,
36796
+ line: 1,
36797
+ column: 1,
36798
+ 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.)",
36799
+ extras: {
36800
+ structuralDuplicateOf: {
36801
+ file: best.path,
36802
+ score: best.score
36803
+ }
36804
+ }
36805
+ });
36806
+ }
36807
+ structuralCache.set(filePath, sigStruct);
36808
+ identifierCache.set(filePath, sigIdent);
36809
+ return issues;
36810
+ }
36811
+ });
36812
+
36111
36813
  // src/rules/go/error-wrap-without-context.ts
36112
36814
  var ERR_WRAP_REGEX = /fmt\.Errorf\(\s*"((?:[^"\\]|\\.)*)"\s*,\s*([^)]+)\)/g;
36113
36815
  var GENERIC_PREFIX_REGEX = /^\s*(?:error|err|failed|wrap(?:ping)?|invalid)\s*(?::\s*)?%w\b/i;
@@ -36514,6 +37216,229 @@ var javaSystemOutPrintlnRule = createRule({
36514
37216
  }
36515
37217
  });
36516
37218
 
37219
+ // src/rules/kotlin/coroutine-global-scope.ts
37220
+ var GLOBAL_SCOPE_REGEX = /GlobalScope\s*\.\s*(?:launch|async|runBlocking)\s*[({]/g;
37221
+ var kotlinCoroutineGlobalScopeRule = createRule({
37222
+ id: "kotlin/coroutine-global-scope",
37223
+ category: "logic",
37224
+ severity: "medium",
37225
+ aiSpecific: true,
37226
+ description: "GlobalScope.launch/async/runBlocking \u2014 bypasses structured concurrency. Use viewModelScope / lifecycleScope / coroutineScope {}.",
37227
+ create(_context) {
37228
+ return {};
37229
+ },
37230
+ analyze(_context, facts) {
37231
+ const issues = [];
37232
+ const source = facts.v2?._source;
37233
+ if (!source) return issues;
37234
+ if (!/\.kt$/i.test(facts.filePath)) return issues;
37235
+ let m;
37236
+ GLOBAL_SCOPE_REGEX.lastIndex = 0;
37237
+ while ((m = GLOBAL_SCOPE_REGEX.exec(source)) !== null) {
37238
+ const line = source.slice(0, m.index).split("\n").length;
37239
+ issues.push({
37240
+ ruleId: "kotlin/coroutine-global-scope",
37241
+ category: "logic",
37242
+ severity: "medium",
37243
+ aiSpecific: true,
37244
+ message: `GlobalScope.${m[0].split(".")[1]?.split("(")[0]}() at line ${line} \u2014 bypasses structured concurrency`,
37245
+ line,
37246
+ column: 1,
37247
+ 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.'
37248
+ });
37249
+ }
37250
+ return issues;
37251
+ }
37252
+ });
37253
+
37254
+ // src/rules/kotlin/data-class-defaults-overuse.ts
37255
+ var DATA_CLASS_HEAD_REGEX = /\bdata\s+class\s+\w+\s*\(/g;
37256
+ var DEFAULT_PARAM_REGEX = /=\s*(?:null|true|false|"[^"]*"|'[^']*'|[+-]?\d+(?:\.\d+)?\w*|emptyList\(\)|emptyMap\(\)|emptySet\(\)|listOf\(\)|mapOf\(\)|setOf\(\))/g;
37257
+ var DEFAULT_MIN_DEFAULTS = 3;
37258
+ var kotlinDataClassDefaultsOveruseRule = createRule({
37259
+ id: "kotlin/data-class-defaults-overuse",
37260
+ category: "typo",
37261
+ severity: "low",
37262
+ aiSpecific: true,
37263
+ description: "data class with 3+ literal defaults \u2014 AI defaults every field rather than only the genuinely optional ones",
37264
+ create(_context) {
37265
+ return { minDefaults: DEFAULT_MIN_DEFAULTS };
37266
+ },
37267
+ analyze(context, facts) {
37268
+ const issues = [];
37269
+ const source = facts.v2?._source;
37270
+ if (!source) return issues;
37271
+ if (!/\.kt$/i.test(facts.filePath)) return issues;
37272
+ let m;
37273
+ DATA_CLASS_HEAD_REGEX.lastIndex = 0;
37274
+ while ((m = DATA_CLASS_HEAD_REGEX.exec(source)) !== null) {
37275
+ const headStart = m.index;
37276
+ const openParen = source.indexOf("(", headStart);
37277
+ if (openParen === -1) continue;
37278
+ let depth = 1;
37279
+ let i = openParen + 1;
37280
+ while (i < source.length && depth > 0) {
37281
+ const ch = source.charAt(i);
37282
+ if (ch === "(") depth++;
37283
+ else if (ch === ")") depth--;
37284
+ i++;
37285
+ }
37286
+ if (depth !== 0) continue;
37287
+ const paramBlock = source.slice(openParen + 1, i - 1);
37288
+ DEFAULT_PARAM_REGEX.lastIndex = 0;
37289
+ let defaults = 0;
37290
+ let dm;
37291
+ while ((dm = DEFAULT_PARAM_REGEX.exec(paramBlock)) !== null) {
37292
+ defaults++;
37293
+ }
37294
+ if (defaults < context.minDefaults) continue;
37295
+ const line = source.slice(0, headStart).split("\n").length;
37296
+ issues.push({
37297
+ ruleId: "kotlin/data-class-defaults-overuse",
37298
+ category: "typo",
37299
+ severity: "low",
37300
+ aiSpecific: true,
37301
+ message: `data class with ${defaults} literal defaults at line ${line} \u2014 only optional fields should have defaults`,
37302
+ line,
37303
+ column: 1,
37304
+ 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."
37305
+ });
37306
+ }
37307
+ return issues;
37308
+ }
37309
+ });
37310
+
37311
+ // src/rules/kotlin/object-singleton-misuse.ts
37312
+ var OBJECT_DECL_REGEX = /\bobject\s+(?!\w*Companion\b)(\w+)\s*\{/g;
37313
+ var kotlinObjectSingletonMisuseRule = createRule({
37314
+ id: "kotlin/object-singleton-misuse",
37315
+ category: "logic",
37316
+ severity: "medium",
37317
+ aiSpecific: true,
37318
+ description: "Kotlin object singleton holding mutable `var` state \u2014 hidden shared state. Use DI or a repository.",
37319
+ create(_context) {
37320
+ return {};
37321
+ },
37322
+ analyze(_context, facts) {
37323
+ const issues = [];
37324
+ const source = facts.v2?._source;
37325
+ if (!source) return issues;
37326
+ if (!/\.kt$/i.test(facts.filePath)) return issues;
37327
+ let m;
37328
+ OBJECT_DECL_REGEX.lastIndex = 0;
37329
+ while ((m = OBJECT_DECL_REGEX.exec(source)) !== null) {
37330
+ const declStart = m.index;
37331
+ const openBrace = source.indexOf("{", declStart);
37332
+ if (openBrace === -1) continue;
37333
+ let depth = 1;
37334
+ let i = openBrace + 1;
37335
+ while (i < source.length && depth > 0) {
37336
+ const ch = source.charAt(i);
37337
+ if (ch === "{") depth++;
37338
+ else if (ch === "}") depth--;
37339
+ i++;
37340
+ }
37341
+ if (depth !== 0) continue;
37342
+ const body = source.slice(openBrace + 1, i - 1);
37343
+ if (!/\bvar\s+\w+\s*[:=]/m.test(body)) continue;
37344
+ const line = source.slice(0, declStart).split("\n").length;
37345
+ const name = m[1] ?? "<unknown>";
37346
+ issues.push({
37347
+ ruleId: "kotlin/object-singleton-misuse",
37348
+ category: "logic",
37349
+ severity: "medium",
37350
+ aiSpecific: true,
37351
+ message: `object ${name} at line ${line} holds mutable state \u2014 singleton + var = hidden shared state`,
37352
+ line,
37353
+ column: 1,
37354
+ 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."
37355
+ });
37356
+ }
37357
+ return issues;
37358
+ }
37359
+ });
37360
+
37361
+ // src/rules/kotlin/println-debug.ts
37362
+ var PRINTLN_REGEX2 = /^\s*println\s*\(/gm;
37363
+ var DEFAULT_THRESHOLD2 = 1;
37364
+ var kotlinPrintlnDebugRule = createRule({
37365
+ id: "kotlin/println-debug",
37366
+ category: "typo",
37367
+ severity: "low",
37368
+ aiSpecific: true,
37369
+ description: "println(...) in production code \u2014 use Timber, android.util.Log, or an SLF4J facade",
37370
+ create(_context) {
37371
+ return { threshold: DEFAULT_THRESHOLD2 };
37372
+ },
37373
+ analyze(context, facts) {
37374
+ const issues = [];
37375
+ const source = facts.v2?._source;
37376
+ if (!source) return issues;
37377
+ if (!/\.kt$/i.test(facts.filePath)) return issues;
37378
+ const matches = [];
37379
+ let m;
37380
+ PRINTLN_REGEX2.lastIndex = 0;
37381
+ while ((m = PRINTLN_REGEX2.exec(source)) !== null) {
37382
+ matches.push(m.index);
37383
+ }
37384
+ if (matches.length <= context.threshold) return issues;
37385
+ const cap = Math.min(matches.length, 10);
37386
+ for (let i = 0; i < cap; i++) {
37387
+ const idx = matches[i];
37388
+ const line = source.slice(0, idx).split("\n").length;
37389
+ issues.push({
37390
+ ruleId: "kotlin/println-debug",
37391
+ category: "typo",
37392
+ severity: "low",
37393
+ aiSpecific: true,
37394
+ message: `println(...) at line ${line} \u2014 use Timber or android.util.Log for production output`,
37395
+ line,
37396
+ column: 1,
37397
+ 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."
37398
+ });
37399
+ }
37400
+ return issues;
37401
+ }
37402
+ });
37403
+
37404
+ // src/rules/kotlin/string-concat-loop.ts
37405
+ var STRING_CONCAT_REGEX2 = /\b(\w+)\s*=\s*\1\s*\+\s*[^;}]+[;}\n]/g;
37406
+ var kotlinStringConcatLoopRule = createRule({
37407
+ id: "kotlin/string-concat-loop",
37408
+ category: "perf",
37409
+ severity: "low",
37410
+ aiSpecific: true,
37411
+ description: "String concatenation in a loop \u2014 use buildString { ... } or a StringBuilder",
37412
+ create(_context) {
37413
+ return {};
37414
+ },
37415
+ analyze(_context, facts) {
37416
+ const issues = [];
37417
+ const source = facts.v2?._source;
37418
+ if (!source) return issues;
37419
+ if (!/\.kt$/i.test(facts.filePath)) return issues;
37420
+ if (!/\b(?:for|while|repeat|forEach)\b/.test(source)) return issues;
37421
+ let m;
37422
+ STRING_CONCAT_REGEX2.lastIndex = 0;
37423
+ while ((m = STRING_CONCAT_REGEX2.exec(source)) !== null) {
37424
+ const line = source.slice(0, m.index).split("\n").length;
37425
+ const lineText = source.slice(0, m.index).split("\n").pop() ?? "";
37426
+ if (/\.append\s*\(/.test(lineText)) continue;
37427
+ issues.push({
37428
+ ruleId: "kotlin/string-concat-loop",
37429
+ category: "perf",
37430
+ severity: "low",
37431
+ aiSpecific: true,
37432
+ message: `String concatenation in a loop at line ${line} \u2014 use buildString { ... }`,
37433
+ line,
37434
+ column: 1,
37435
+ 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."
37436
+ });
37437
+ }
37438
+ return issues;
37439
+ }
37440
+ });
37441
+
36517
37442
  // src/rules/layout/gap-monopoly.ts
36518
37443
  var GAP_RE = /\bgap(?:-x|-y)?-(\d+)\b/g;
36519
37444
  var gapMonopolyRule = createRule({
@@ -36726,7 +37651,7 @@ var DEFAULT_RULE_CONFIG = {
36726
37651
  },
36727
37652
  genericCenteringMaxInstances: 1
36728
37653
  };
36729
- var DEFAULT_CONFIG = {
37654
+ var DEFAULT_CONFIG3 = {
36730
37655
  include: [
36731
37656
  // v0.9.2 — Repository Coherence is language-agnostic. Default include
36732
37657
  // covers frontend (TS/JS/Vue/Svelte/Astro) AND backend (Python/Go).
@@ -36868,6 +37793,38 @@ var DEFAULT_CONFIG = {
36868
37793
  */
36869
37794
  testIntelligence: {
36870
37795
  missingEdgeCase: false
37796
+ },
37797
+ /**
37798
+ * v0.25.0: self-scan exclude paths. Defaults cover the three paths
37799
+ * that are always false positives when scanning the slopbrick repo
37800
+ * itself:
37801
+ *
37802
+ * - `src/rules/**` — rule definitions contain example patterns
37803
+ * the rules themselves detect (self-fire). E.g. a
37804
+ * `security/sql-construction` rule's source file has a SQL
37805
+ * concat string literal that fires its own regex.
37806
+ * - `tests/fixtures/**` — test fixtures contain intentional bad
37807
+ * code that the rules must fire on to be useful (each fixture
37808
+ * is a positive test case). Scanning them in a self-scan
37809
+ * produces ~70 false-positive "issues" that are really just
37810
+ * test data.
37811
+ * - `tests/rules/**` — rule test files contain expected-issue
37812
+ * assertions, also meta-code.
37813
+ *
37814
+ * Three patterns, ~70 issues removed per self-scan. Combined with
37815
+ * the v0.25.0 graded security cap, this restores the v9 plan's
37816
+ * "security ≥ 80" criterion (unachievable in v0.24.0 due to 90
37817
+ * self-scan FPs collapsing the score to 0).
37818
+ *
37819
+ * Set `selfScan: { excludePaths: [] }` in `slopbrick.config.mjs`
37820
+ * to opt out and scan every file (legacy behavior).
37821
+ */
37822
+ selfScan: {
37823
+ excludePaths: [
37824
+ "src/rules/**",
37825
+ "tests/fixtures/**",
37826
+ "tests/rules/**"
37827
+ ]
36871
37828
  }
36872
37829
  };
36873
37830
 
@@ -36981,8 +37938,8 @@ var STRICTNESS_PRESETS = {
36981
37938
  }
36982
37939
  },
36983
37940
  balanced: {
36984
- thresholds: DEFAULT_CONFIG.thresholds,
36985
- categoryWeights: DEFAULT_CONFIG.categoryWeights
37941
+ thresholds: DEFAULT_CONFIG3.thresholds,
37942
+ categoryWeights: DEFAULT_CONFIG3.categoryWeights
36986
37943
  },
36987
37944
  permissive: {
36988
37945
  thresholds: { meanSlop: 50, p90Slop: 75, individualSlopThreshold: 90 },
@@ -37926,7 +38883,7 @@ var KEYWORD_OPERATORS = [
37926
38883
  function stripNoise2(source) {
37927
38884
  return source.replace(/\/\*[\s\S]*?\*\//g, "").replace(/\/\/[^\n]*/g, "").replace(/'(?:\\.|[^'\\])*'/g, "''").replace(/"(?:\\.|[^"\\])*"/g, '""').replace(/`(?:\\.|[^`\\])*`/g, "``");
37928
38885
  }
37929
- function tokenize(source) {
38886
+ function tokenize2(source) {
37930
38887
  const cleaned = stripNoise2(source);
37931
38888
  const operators = [];
37932
38889
  const operands = [];
@@ -37947,7 +38904,7 @@ function tokenize(source) {
37947
38904
  return { operators, operands };
37948
38905
  }
37949
38906
  function computeHalstead(source) {
37950
- const { operators, operands } = tokenize(source);
38907
+ const { operators, operands } = tokenize2(source);
37951
38908
  const uniqueOperators = new Set(operators);
37952
38909
  const uniqueOperands = new Set(operands);
37953
38910
  const n1 = uniqueOperators.size;
@@ -39215,8 +40172,227 @@ var unsafeHtmlRenderRule = createRule({
39215
40172
  }
39216
40173
  });
39217
40174
 
40175
+ // src/rules/swift/fatal-error-thrown.ts
40176
+ var FATAL_REGEX = /\b(?:fatalError|preconditionFailure)\s*\(/g;
40177
+ var swiftFatalErrorThrownRule = createRule({
40178
+ id: "swift/fatal-error-thrown",
40179
+ category: "logic",
40180
+ severity: "high",
40181
+ aiSpecific: true,
40182
+ description: "fatalError / preconditionFailure in production \u2014 crashes unconditionally. Return an error or a typed default.",
40183
+ create(_context) {
40184
+ return {};
40185
+ },
40186
+ analyze(_context, facts) {
40187
+ const issues = [];
40188
+ const source = facts.v2?._source;
40189
+ if (!source) return issues;
40190
+ if (!/\.swift$/i.test(facts.filePath)) return issues;
40191
+ if (/\bimport\s+XCTest\b/.test(source)) return issues;
40192
+ let m;
40193
+ FATAL_REGEX.lastIndex = 0;
40194
+ while ((m = FATAL_REGEX.exec(source)) !== null) {
40195
+ const line = source.slice(0, m.index).split("\n").length;
40196
+ const matched = m[0].replace(/\s*\($/, "");
40197
+ issues.push({
40198
+ ruleId: "swift/fatal-error-thrown",
40199
+ category: "logic",
40200
+ severity: "high",
40201
+ aiSpecific: true,
40202
+ message: `${matched}() at line ${line} \u2014 crashes unconditionally in release builds`,
40203
+ line,
40204
+ column: 1,
40205
+ 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.'
40206
+ });
40207
+ }
40208
+ return issues;
40209
+ }
40210
+ });
40211
+
40212
+ // src/rules/swift/force-unwrap.ts
40213
+ var AS_FORCE_REGEX = /\bas!\s+/g;
40214
+ var ACCESS_FORCE_REGEX = /(?:\w|\])\!\s*(?:\.|\(|;|,|\s*$)/gm;
40215
+ var TRY_FORCE_REGEX = /\btry!\s+/g;
40216
+ var swiftForceUnwrapRule = createRule({
40217
+ id: "swift/force-unwrap",
40218
+ category: "logic",
40219
+ severity: "medium",
40220
+ aiSpecific: true,
40221
+ description: "Swift force-unwrap (as!, var!.prop, try!) \u2014 silently crashes if the value is nil. Use as? / guard let / try?.",
40222
+ create(_context) {
40223
+ return {};
40224
+ },
40225
+ analyze(_context, facts) {
40226
+ const issues = [];
40227
+ const source = facts.v2?._source;
40228
+ if (!source) return issues;
40229
+ if (!/\.swift$/i.test(facts.filePath)) return issues;
40230
+ if (/\bimport\s+XCTest\b/.test(source)) return issues;
40231
+ const emit = (idx, label) => {
40232
+ const line = source.slice(0, idx).split("\n").length;
40233
+ issues.push({
40234
+ ruleId: "swift/force-unwrap",
40235
+ category: "logic",
40236
+ severity: "medium",
40237
+ aiSpecific: true,
40238
+ message: `force-unwrap (${label}) at line ${line} \u2014 crashes if the value is nil`,
40239
+ line,
40240
+ column: 1,
40241
+ 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.'
40242
+ });
40243
+ };
40244
+ let m;
40245
+ AS_FORCE_REGEX.lastIndex = 0;
40246
+ while ((m = AS_FORCE_REGEX.exec(source)) !== null) emit(m.index, "as!");
40247
+ TRY_FORCE_REGEX.lastIndex = 0;
40248
+ while ((m = TRY_FORCE_REGEX.exec(source)) !== null) emit(m.index, "try!");
40249
+ ACCESS_FORCE_REGEX.lastIndex = 0;
40250
+ while ((m = ACCESS_FORCE_REGEX.exec(source)) !== null) emit(m.index, "!.");
40251
+ return issues;
40252
+ }
40253
+ });
40254
+
40255
+ // src/rules/swift/implicitly-unwrapped-optional.ts
40256
+ var IUO_DECL_REGEX = /\b(?:var|let)\s+\w+\s*:\s*[A-Za-z_][\w<>?,\.\s]*!\s*[=;\n]/g;
40257
+ var swiftImplicitlyUnwrappedOptionalRule = createRule({
40258
+ id: "swift/implicitly-unwrapped-optional",
40259
+ category: "typo",
40260
+ severity: "low",
40261
+ aiSpecific: true,
40262
+ description: "Implicitly unwrapped optional (var x: Type!) \u2014 declare as Type? and unwrap with guard let.",
40263
+ create(_context) {
40264
+ return {};
40265
+ },
40266
+ analyze(_context, facts) {
40267
+ const issues = [];
40268
+ const source = facts.v2?._source;
40269
+ if (!source) return issues;
40270
+ if (!/\.swift$/i.test(facts.filePath)) return issues;
40271
+ let m;
40272
+ IUO_DECL_REGEX.lastIndex = 0;
40273
+ while ((m = IUO_DECL_REGEX.exec(source)) !== null) {
40274
+ const captured = m[0];
40275
+ const bangAt = captured.indexOf("!", captured.indexOf(":"));
40276
+ const between = captured.slice(captured.indexOf(":"), bangAt);
40277
+ if (between.includes("?")) continue;
40278
+ const line = source.slice(0, m.index).split("\n").length;
40279
+ issues.push({
40280
+ ruleId: "swift/implicitly-unwrapped-optional",
40281
+ category: "typo",
40282
+ severity: "low",
40283
+ aiSpecific: true,
40284
+ message: `implicitly unwrapped optional at line ${line} \u2014 declare as Type? and unwrap explicitly`,
40285
+ line,
40286
+ column: 1,
40287
+ 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.'
40288
+ });
40289
+ }
40290
+ return issues;
40291
+ }
40292
+ });
40293
+
40294
+ // src/rules/swift/print-debug.ts
40295
+ var PRINT_REGEX = /\bprint\s*\(/g;
40296
+ var DEFAULT_THRESHOLD3 = 1;
40297
+ var swiftPrintDebugRule = createRule({
40298
+ id: "swift/print-debug",
40299
+ category: "typo",
40300
+ severity: "low",
40301
+ aiSpecific: true,
40302
+ description: "print(...) in production Swift \u2014 use Logger (os.log) for level-controlled output",
40303
+ create(_context) {
40304
+ return { threshold: DEFAULT_THRESHOLD3 };
40305
+ },
40306
+ analyze(context, facts) {
40307
+ const issues = [];
40308
+ const source = facts.v2?._source;
40309
+ if (!source) return issues;
40310
+ if (!/\.swift$/i.test(facts.filePath)) return issues;
40311
+ const matches = [];
40312
+ let m;
40313
+ PRINT_REGEX.lastIndex = 0;
40314
+ while ((m = PRINT_REGEX.exec(source)) !== null) {
40315
+ matches.push(m.index);
40316
+ }
40317
+ if (matches.length <= context.threshold) return issues;
40318
+ const cap = Math.min(matches.length, 10);
40319
+ for (let i = 0; i < cap; i++) {
40320
+ const idx = matches[i];
40321
+ const line = source.slice(0, idx).split("\n").length;
40322
+ issues.push({
40323
+ ruleId: "swift/print-debug",
40324
+ category: "typo",
40325
+ severity: "low",
40326
+ aiSpecific: true,
40327
+ message: `print(...) at line ${line} \u2014 use Logger (os.log) for production output`,
40328
+ line,
40329
+ column: 1,
40330
+ 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.'
40331
+ });
40332
+ }
40333
+ return issues;
40334
+ }
40335
+ });
40336
+
40337
+ // src/rules/swift/strong-self-capture.ts
40338
+ var SELF_REF_REGEX = /\bself\.(?:\w+)/g;
40339
+ var CAPTURE_LIST_REGEX = /\[\s*(?:weak|unowned)\s+self\b/;
40340
+ var swiftStrongSelfCaptureRule = createRule({
40341
+ id: "swift/strong-self-capture",
40342
+ category: "logic",
40343
+ severity: "medium",
40344
+ aiSpecific: true,
40345
+ description: "Closure captures `self` strongly \u2014 creates a retain cycle. Use `[weak self]` or `[unowned self]`.",
40346
+ create(_context) {
40347
+ return {};
40348
+ },
40349
+ analyze(_context, facts) {
40350
+ const issues = [];
40351
+ const source = facts.v2?._source;
40352
+ if (!source) return issues;
40353
+ if (!/\.swift$/i.test(facts.filePath)) return issues;
40354
+ const METHOD_HEAD_REGEX = /\b(?:func|init\??|deinit|subscript)\b[^;{}\n]*$/m;
40355
+ let m;
40356
+ SELF_REF_REGEX.lastIndex = 0;
40357
+ while ((m = SELF_REF_REGEX.exec(source)) !== null) {
40358
+ const selfIdx = m.index;
40359
+ let depth = 0;
40360
+ let openBrace = -1;
40361
+ for (let j = selfIdx - 1; j >= 0; j--) {
40362
+ const ch = source.charAt(j);
40363
+ if (ch === "}") depth++;
40364
+ else if (ch === "{") {
40365
+ if (depth === 0) {
40366
+ openBrace = j;
40367
+ break;
40368
+ }
40369
+ depth--;
40370
+ }
40371
+ }
40372
+ if (openBrace === -1) continue;
40373
+ const openLineStart = source.lastIndexOf("\n", openBrace) + 1;
40374
+ const lineBeforeBrace = source.slice(openLineStart, openBrace);
40375
+ if (METHOD_HEAD_REGEX.test(lineBeforeBrace)) continue;
40376
+ const openingSlice = source.slice(openBrace, openBrace + 80);
40377
+ if (CAPTURE_LIST_REGEX.test(openingSlice)) continue;
40378
+ const line = source.slice(0, openBrace).split("\n").length;
40379
+ issues.push({
40380
+ ruleId: "swift/strong-self-capture",
40381
+ category: "logic",
40382
+ severity: "medium",
40383
+ aiSpecific: true,
40384
+ message: `closure at line ${line} captures self strongly \u2014 use [weak self] or [unowned self]`,
40385
+ line,
40386
+ column: 1,
40387
+ 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.'
40388
+ });
40389
+ }
40390
+ return issues;
40391
+ }
40392
+ });
40393
+
39218
40394
  // src/rules/test/utils.ts
39219
- import { createHash as createHash3 } from "crypto";
40395
+ import { createHash as createHash6 } from "crypto";
39220
40396
  function isTestFile(filePath) {
39221
40397
  const normalized = filePath.replace(/\\/g, "/");
39222
40398
  if (/(^|\/)__tests__\//.test(normalized)) return true;
@@ -39376,7 +40552,7 @@ function extractSetupBlocks(source, minLines = 3) {
39376
40552
  }).trim();
39377
40553
  const lineCount = rawBody.split("\n").length;
39378
40554
  if (lineCount < minLines) continue;
39379
- const bodyHash = createHash3("sha1").update(normalizedBody).digest("hex");
40555
+ const bodyHash = createHash6("sha1").update(normalizedBody).digest("hex");
39380
40556
  const { line, column } = lineColumnOf(source, m.index);
39381
40557
  hits.push({
39382
40558
  kind,
@@ -41755,6 +42931,11 @@ var builtinRules = [
41755
42931
  multipleComponentsPerFileRule,
41756
42932
  shadcnPropMismatchRule,
41757
42933
  importPathMismatchRule,
42934
+ cppCStyleCastRule,
42935
+ cppMagicNumbersRule,
42936
+ cppPrintfDebugRule,
42937
+ cppRawNewDeleteRule,
42938
+ cppUsingNamespaceStdRule,
41758
42939
  duplicateIndexRule,
41759
42940
  enumSprawlRule,
41760
42941
  missingFkIndexRule,
@@ -41770,6 +42951,8 @@ var builtinRules = [
41770
42951
  staleFunctionReferenceRule,
41771
42952
  stalePackageReferenceRule,
41772
42953
  dupIdenticalBlockRule,
42954
+ nearDuplicateRule,
42955
+ structuralCloneRule,
41773
42956
  goErrorWrapWithoutContextRule,
41774
42957
  goNilSliceVsEmptyRule,
41775
42958
  goStructTagInconsistencyRule,
@@ -41779,6 +42962,11 @@ var builtinRules = [
41779
42962
  javaRawTypeOveruseRule,
41780
42963
  javaStringConcatLoopRule,
41781
42964
  javaSystemOutPrintlnRule,
42965
+ kotlinCoroutineGlobalScopeRule,
42966
+ kotlinDataClassDefaultsOveruseRule,
42967
+ kotlinObjectSingletonMisuseRule,
42968
+ kotlinPrintlnDebugRule,
42969
+ kotlinStringConcatLoopRule,
41782
42970
  gapMonopolyRule,
41783
42971
  mathElementUniformityRule,
41784
42972
  mathGridUniformityRule,
@@ -41817,6 +43005,11 @@ var builtinRules = [
41817
43005
  sqlConstructionRule,
41818
43006
  targetBlankNoNoopenerRule,
41819
43007
  unsafeHtmlRenderRule,
43008
+ swiftFatalErrorThrownRule,
43009
+ swiftForceUnwrapRule,
43010
+ swiftImplicitlyUnwrappedOptionalRule,
43011
+ swiftPrintDebugRule,
43012
+ swiftStrongSelfCaptureRule,
41820
43013
  duplicateSetupRule,
41821
43014
  fakePlaceholderRule,
41822
43015
  missingEdgeCaseRule,
@@ -42535,9 +43728,9 @@ var signal_strength_default = {
42535
43728
  ratio: 1,
42536
43729
  precision: 0,
42537
43730
  lastCalibratedAt: "2026-07-01T00:00:00Z",
42538
- verdict: "DORMANT",
43731
+ verdict: "OK",
42539
43732
  defaultOff: false,
42540
- _calibrationNote: "v0.19: new rule, not yet calibrated. 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. Default stays on because the rule's 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.",
43733
+ _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.",
42541
43734
  aiSpecific: false,
42542
43735
  _v7Verdict: "DORMANT",
42543
43736
  _v7Lift: 1,
@@ -42545,8 +43738,39 @@ var signal_strength_default = {
42545
43738
  _v7FpRate: 0,
42546
43739
  _v7Precision: 0,
42547
43740
  _v8Verdict: "DORMANT",
42548
- _v8Lift: 1,
42549
- defaultOff: true
43741
+ _v8Lift: 1
43742
+ },
43743
+ "dup/near-duplicate": {
43744
+ recall: 0,
43745
+ fpRate: 0,
43746
+ ratio: 1,
43747
+ precision: 0,
43748
+ lastCalibratedAt: "2026-07-02T00:00:00Z",
43749
+ verdict: "DORMANT",
43750
+ defaultOff: true,
43751
+ _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.",
43752
+ aiSpecific: true,
43753
+ _v7Verdict: "DORMANT",
43754
+ _v7Lift: 1,
43755
+ _v7Recall: 0,
43756
+ _v7FpRate: 0,
43757
+ _v7Precision: 0
43758
+ },
43759
+ "dup/structural-clone": {
43760
+ recall: 0,
43761
+ fpRate: 0,
43762
+ ratio: 1,
43763
+ precision: 0,
43764
+ lastCalibratedAt: "2026-07-02T00:00:00Z",
43765
+ verdict: "DORMANT",
43766
+ defaultOff: true,
43767
+ _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.",
43768
+ aiSpecific: true,
43769
+ _v7Verdict: "DORMANT",
43770
+ _v7Lift: 1,
43771
+ _v7Recall: 0,
43772
+ _v7FpRate: 0,
43773
+ _v7Precision: 0
42550
43774
  },
42551
43775
  "go/error-wrap-without-context": {
42552
43776
  recall: 0,
@@ -43952,6 +45176,276 @@ var signal_strength_default = {
43952
45176
  _v8Verdict: "DORMANT",
43953
45177
  _v8Lift: 1,
43954
45178
  defaultOff: true
45179
+ },
45180
+ "kotlin/data-class-defaults-overuse": {
45181
+ recall: 0,
45182
+ fpRate: 0,
45183
+ ratio: 1,
45184
+ precision: 0,
45185
+ lastCalibratedAt: "2026-07-02T00:00:00Z",
45186
+ verdict: "DORMANT",
45187
+ _calibrationNote: "v0.24: new rule (data class with 3+ literal defaults). DORMANT until v9 Kotlin corpus calibration.",
45188
+ aiSpecific: true,
45189
+ _v7Verdict: "DORMANT",
45190
+ _v7Lift: 1,
45191
+ _v7Recall: 0,
45192
+ _v7FpRate: 0,
45193
+ _v7Precision: 0,
45194
+ _v8Verdict: "DORMANT",
45195
+ _v8Lift: 1,
45196
+ defaultOff: true
45197
+ },
45198
+ "kotlin/coroutine-global-scope": {
45199
+ recall: 0,
45200
+ fpRate: 0,
45201
+ ratio: 1,
45202
+ precision: 0,
45203
+ lastCalibratedAt: "2026-07-02T00:00:00Z",
45204
+ verdict: "DORMANT",
45205
+ _calibrationNote: "v0.24: new rule (GlobalScope.launch/async/runBlocking \u2014 bypasses structured concurrency). DORMANT until v9 Kotlin corpus calibration.",
45206
+ aiSpecific: true,
45207
+ _v7Verdict: "DORMANT",
45208
+ _v7Lift: 1,
45209
+ _v7Recall: 0,
45210
+ _v7FpRate: 0,
45211
+ _v7Precision: 0,
45212
+ _v8Verdict: "DORMANT",
45213
+ _v8Lift: 1,
45214
+ defaultOff: true
45215
+ },
45216
+ "kotlin/println-debug": {
45217
+ recall: 0,
45218
+ fpRate: 0,
45219
+ ratio: 1,
45220
+ precision: 0,
45221
+ lastCalibratedAt: "2026-07-02T00:00:00Z",
45222
+ verdict: "DORMANT",
45223
+ _calibrationNote: "v0.24: new rule (multi-println in Kotlin source \u2014 use Timber / android.util.Log). DORMANT until v9 Kotlin corpus calibration.",
45224
+ aiSpecific: true,
45225
+ _v7Verdict: "DORMANT",
45226
+ _v7Lift: 1,
45227
+ _v7Recall: 0,
45228
+ _v7FpRate: 0,
45229
+ _v7Precision: 0,
45230
+ _v8Verdict: "DORMANT",
45231
+ _v8Lift: 1,
45232
+ defaultOff: true
45233
+ },
45234
+ "kotlin/object-singleton-misuse": {
45235
+ recall: 0,
45236
+ fpRate: 0,
45237
+ ratio: 1,
45238
+ precision: 0,
45239
+ lastCalibratedAt: "2026-07-02T00:00:00Z",
45240
+ verdict: "DORMANT",
45241
+ _calibrationNote: "v0.24: new rule (Kotlin `object` singleton holding `var` \u2014 hidden shared state). DORMANT until v9 Kotlin corpus calibration.",
45242
+ aiSpecific: true,
45243
+ _v7Verdict: "DORMANT",
45244
+ _v7Lift: 1,
45245
+ _v7Recall: 0,
45246
+ _v7FpRate: 0,
45247
+ _v7Precision: 0,
45248
+ _v8Verdict: "DORMANT",
45249
+ _v8Lift: 1,
45250
+ defaultOff: true
45251
+ },
45252
+ "kotlin/string-concat-loop": {
45253
+ recall: 0,
45254
+ fpRate: 0,
45255
+ ratio: 1,
45256
+ precision: 0,
45257
+ lastCalibratedAt: "2026-07-02T00:00:00Z",
45258
+ verdict: "DORMANT",
45259
+ _calibrationNote: "v0.24: new rule (string concat inside a Kotlin loop \u2014 use buildString { ... }). DORMANT until v9 Kotlin corpus calibration.",
45260
+ aiSpecific: true,
45261
+ _v7Verdict: "DORMANT",
45262
+ _v7Lift: 1,
45263
+ _v7Recall: 0,
45264
+ _v7FpRate: 0,
45265
+ _v7Precision: 0,
45266
+ _v8Verdict: "DORMANT",
45267
+ _v8Lift: 1,
45268
+ defaultOff: true
45269
+ },
45270
+ "swift/force-unwrap": {
45271
+ recall: 0,
45272
+ fpRate: 0,
45273
+ ratio: 1,
45274
+ precision: 0,
45275
+ lastCalibratedAt: "2026-07-02T00:00:00Z",
45276
+ verdict: "DORMANT",
45277
+ _calibrationNote: "v0.24: new rule (Swift force-unwrap \u2014 `as!`, `try!`, `var!.prop` in production). DORMANT until v9 Swift corpus calibration.",
45278
+ aiSpecific: true,
45279
+ _v7Verdict: "DORMANT",
45280
+ _v7Lift: 1,
45281
+ _v7Recall: 0,
45282
+ _v7FpRate: 0,
45283
+ _v7Precision: 0,
45284
+ _v8Verdict: "DORMANT",
45285
+ _v8Lift: 1,
45286
+ defaultOff: true
45287
+ },
45288
+ "swift/print-debug": {
45289
+ recall: 0,
45290
+ fpRate: 0,
45291
+ ratio: 1,
45292
+ precision: 0,
45293
+ lastCalibratedAt: "2026-07-02T00:00:00Z",
45294
+ verdict: "DORMANT",
45295
+ _calibrationNote: "v0.24: new rule (multi-print in Swift source \u2014 use Logger / os.log). DORMANT until v9 Swift corpus calibration.",
45296
+ aiSpecific: true,
45297
+ _v7Verdict: "DORMANT",
45298
+ _v7Lift: 1,
45299
+ _v7Recall: 0,
45300
+ _v7FpRate: 0,
45301
+ _v7Precision: 0,
45302
+ _v8Verdict: "DORMANT",
45303
+ _v8Lift: 1,
45304
+ defaultOff: true
45305
+ },
45306
+ "swift/fatal-error-thrown": {
45307
+ recall: 0,
45308
+ fpRate: 0,
45309
+ ratio: 1,
45310
+ precision: 0,
45311
+ lastCalibratedAt: "2026-07-02T00:00:00Z",
45312
+ verdict: "DORMANT",
45313
+ _calibrationNote: "v0.24: new rule (`fatalError` / `preconditionFailure` in production Swift \u2014 replaces with typed default). DORMANT until v9 Swift corpus calibration.",
45314
+ aiSpecific: true,
45315
+ _v7Verdict: "DORMANT",
45316
+ _v7Lift: 1,
45317
+ _v7Recall: 0,
45318
+ _v7FpRate: 0,
45319
+ _v7Precision: 0,
45320
+ _v8Verdict: "DORMANT",
45321
+ _v8Lift: 1,
45322
+ defaultOff: true
45323
+ },
45324
+ "swift/implicitly-unwrapped-optional": {
45325
+ recall: 0,
45326
+ fpRate: 0,
45327
+ ratio: 1,
45328
+ precision: 0,
45329
+ lastCalibratedAt: "2026-07-02T00:00:00Z",
45330
+ verdict: "DORMANT",
45331
+ _calibrationNote: "v0.24: new rule (Swift implicitly unwrapped optional \u2014 declare as Type? and unwrap with guard let). DORMANT until v9 Swift corpus calibration.",
45332
+ aiSpecific: true,
45333
+ _v7Verdict: "DORMANT",
45334
+ _v7Lift: 1,
45335
+ _v7Recall: 0,
45336
+ _v7FpRate: 0,
45337
+ _v7Precision: 0,
45338
+ _v8Verdict: "DORMANT",
45339
+ _v8Lift: 1,
45340
+ defaultOff: true
45341
+ },
45342
+ "swift/strong-self-capture": {
45343
+ recall: 0,
45344
+ fpRate: 0,
45345
+ ratio: 1,
45346
+ precision: 0,
45347
+ lastCalibratedAt: "2026-07-02T00:00:00Z",
45348
+ verdict: "DORMANT",
45349
+ _calibrationNote: "v0.24: new rule (Swift closure captures `self` strongly \u2014 retain cycle. Use [weak self] / [unowned self]). DORMANT until v9 Swift corpus calibration.",
45350
+ aiSpecific: true,
45351
+ _v7Verdict: "DORMANT",
45352
+ _v7Lift: 1,
45353
+ _v7Recall: 0,
45354
+ _v7FpRate: 0,
45355
+ _v7Precision: 0,
45356
+ _v8Verdict: "DORMANT",
45357
+ _v8Lift: 1,
45358
+ defaultOff: true
45359
+ },
45360
+ "cpp/using-namespace-std": {
45361
+ recall: 0,
45362
+ fpRate: 0,
45363
+ ratio: 1,
45364
+ precision: 0,
45365
+ lastCalibratedAt: "2026-07-02T00:00:00Z",
45366
+ verdict: "DORMANT",
45367
+ _calibrationNote: "v0.24: new rule (`using namespace std;` in C++ header \u2014 pollutes every consumer). DORMANT until v9 C++ corpus calibration.",
45368
+ aiSpecific: true,
45369
+ _v7Verdict: "DORMANT",
45370
+ _v7Lift: 1,
45371
+ _v7Recall: 0,
45372
+ _v7FpRate: 0,
45373
+ _v7Precision: 0,
45374
+ _v8Verdict: "DORMANT",
45375
+ _v8Lift: 1,
45376
+ defaultOff: true
45377
+ },
45378
+ "cpp/raw-new-delete": {
45379
+ recall: 0,
45380
+ fpRate: 0,
45381
+ ratio: 1,
45382
+ precision: 0,
45383
+ lastCalibratedAt: "2026-07-02T00:00:00Z",
45384
+ verdict: "DORMANT",
45385
+ _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.",
45386
+ aiSpecific: true,
45387
+ _v7Verdict: "DORMANT",
45388
+ _v7Lift: 1,
45389
+ _v7Recall: 0,
45390
+ _v7FpRate: 0,
45391
+ _v7Precision: 0,
45392
+ _v8Verdict: "DORMANT",
45393
+ _v8Lift: 1,
45394
+ defaultOff: true
45395
+ },
45396
+ "cpp/c-style-cast": {
45397
+ recall: 0,
45398
+ fpRate: 0,
45399
+ ratio: 1,
45400
+ precision: 0,
45401
+ lastCalibratedAt: "2026-07-02T00:00:00Z",
45402
+ verdict: "DORMANT",
45403
+ _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.",
45404
+ aiSpecific: true,
45405
+ _v7Verdict: "DORMANT",
45406
+ _v7Lift: 1,
45407
+ _v7Recall: 0,
45408
+ _v7FpRate: 0,
45409
+ _v7Precision: 0,
45410
+ _v8Verdict: "DORMANT",
45411
+ _v8Lift: 1,
45412
+ defaultOff: true
45413
+ },
45414
+ "cpp/printf-debug": {
45415
+ recall: 0,
45416
+ fpRate: 0,
45417
+ ratio: 1,
45418
+ precision: 0,
45419
+ lastCalibratedAt: "2026-07-02T00:00:00Z",
45420
+ verdict: "DORMANT",
45421
+ _calibrationNote: "v0.24: new rule (printf family / std::cout debug printing in C++ \u2014 use spdlog / glog / AbslLog). DORMANT until v9 C++ corpus calibration.",
45422
+ aiSpecific: true,
45423
+ _v7Verdict: "DORMANT",
45424
+ _v7Lift: 1,
45425
+ _v7Recall: 0,
45426
+ _v7FpRate: 0,
45427
+ _v7Precision: 0,
45428
+ _v8Verdict: "DORMANT",
45429
+ _v8Lift: 1,
45430
+ defaultOff: true
45431
+ },
45432
+ "cpp/magic-numbers": {
45433
+ recall: 0,
45434
+ fpRate: 0,
45435
+ ratio: 1,
45436
+ precision: 0,
45437
+ lastCalibratedAt: "2026-07-02T00:00:00Z",
45438
+ verdict: "DORMANT",
45439
+ _calibrationNote: "v0.24: new rule (magic-number literal in C++ comparison / return \u2014 name it `constexpr int MAX = ...`). DORMANT until v9 C++ corpus calibration.",
45440
+ aiSpecific: true,
45441
+ _v7Verdict: "DORMANT",
45442
+ _v7Lift: 1,
45443
+ _v7Recall: 0,
45444
+ _v7FpRate: 0,
45445
+ _v7Precision: 0,
45446
+ _v8Verdict: "DORMANT",
45447
+ _v8Lift: 1,
45448
+ defaultOff: true
43955
45449
  }
43956
45450
  };
43957
45451
 
@@ -43982,7 +45476,23 @@ function applyRuleOverrides(issues, rules) {
43982
45476
  }
43983
45477
  return result;
43984
45478
  }
45479
+ function isExcludedBySelfScan(filePath, cwd, excludePaths) {
45480
+ if (!excludePaths || excludePaths.length === 0) return false;
45481
+ const rel = relative2(cwd, filePath).split(sep).join("/");
45482
+ return excludePaths.some((pattern) => minimatch(rel, pattern, { dot: true }));
45483
+ }
43985
45484
  async function scanFile(filePath, config, registry, cwd = process.cwd()) {
45485
+ if (isExcludedBySelfScan(filePath, cwd, config.selfScan?.excludePaths)) {
45486
+ return {
45487
+ filePath,
45488
+ componentCount: 0,
45489
+ issues: [],
45490
+ gapValues: [],
45491
+ styleSources: [],
45492
+ elementTags: [],
45493
+ unmatchedStringLiterals: []
45494
+ };
45495
+ }
43986
45496
  const cache = buildParserCacheConfig(cwd);
43987
45497
  const ext = extname4(filePath).toLowerCase();
43988
45498
  const UNSUPPORTED_LANGS = /* @__PURE__ */ new Set([
@@ -43997,7 +45507,6 @@ async function scanFile(filePath, config, registry, cwd = process.cwd()) {
43997
45507
  ".h",
43998
45508
  ".hpp",
43999
45509
  ".hxx",
44000
- ".java",
44001
45510
  ".rb",
44002
45511
  ".php"
44003
45512
  ]);