mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-07-31 04:12:10 +03:00
Collapse duplicate CI spend while keeping each gate's existence reason: - quality.yml: TIA __RUN_ALL__ defers full unit to fast-unit 4-shard (#6781); path filters via classify-pr-changes; docs-gates split; draft skip - ci.yml: wire docs/i18n/code path filters; ESLint JSON artifact for quality-gate; drop advisory typecheck:noimplicit; float actions/cache@v6 - TIA parity: memory/usage/combo/serial; **/*.test.mjs any depth; electron/bin no longer force unit __RUN_ALL__ - check:complexity-ratchets: one ESLint walk, ruleId-isolated baselines + cache - check:api-docs-refs + lib/apiRoutes: shared API route inventory - husky pre-push: intentionally light (gates live in pre-commit); CLAUDE.md + QUALITY_GATES.md docs synced - collect-metrics / lint:json: path.resolve cache path; Windows-safe eslint bin - env-doc allowlist for ESLINT_RESULTS_JSON / COMPLEXITY_ESLINT_REPORT - release-green --full-ci expects check:api-docs-refs (not docs-symbols alone) Tests: select-impacted, classify-pr-changes, api-routes lib, complexity-rule-count, validate-release-green. Reconciled after #6781 (fast-unit 2→4 shards) per maintainer request on #6716. Co-authored-by: Diego Rodrigues de Sa e Souza <8016841+diegosouzapw@users.noreply.github.com>
65 lines
2.3 KiB
JavaScript
65 lines
2.3 KiB
JavaScript
#!/usr/bin/env node
|
|
// scripts/check/check-complexity.mjs
|
|
// Catraca de complexidade de código (cyclomatic + max-lines-per-function).
|
|
// Shares one ESLint walk with cognitive-complexity via complexityEslintReport.mjs
|
|
// / eslint.complexity-ratchets.config.mjs. Counts by ruleId so cognitive
|
|
// violations never inflate this baseline.
|
|
import fs from "node:fs";
|
|
import path from "node:path";
|
|
import { pathToFileURL } from "node:url";
|
|
import {
|
|
ESLINT_ARGS,
|
|
countComplexityViolations,
|
|
getComplexityEslintReport,
|
|
} from "./complexityEslintReport.mjs";
|
|
|
|
const ROOT = process.cwd();
|
|
const BASELINE_PATH = path.resolve(
|
|
process.argv.includes("--baseline")
|
|
? process.argv[process.argv.indexOf("--baseline") + 1]
|
|
: path.join(ROOT, "config/quality/complexity-baseline.json")
|
|
);
|
|
const UPDATE = process.argv.includes("--update");
|
|
|
|
// Re-export for tests that lock scan scope (src+open-sse+electron+bin).
|
|
export { ESLINT_ARGS };
|
|
|
|
/** Avalia a contagem atual de violações contra o baseline. */
|
|
export function evaluateComplexity(current, baseline) {
|
|
return {
|
|
regressed: current > baseline,
|
|
improved: current < baseline,
|
|
};
|
|
}
|
|
|
|
function measureComplexityCount() {
|
|
return countComplexityViolations(getComplexityEslintReport());
|
|
}
|
|
|
|
function main() {
|
|
if (!fs.existsSync(BASELINE_PATH)) {
|
|
console.error(`[complexity] FAIL — ${path.basename(BASELINE_PATH)} ausente.`);
|
|
process.exit(2);
|
|
}
|
|
const baseline = JSON.parse(fs.readFileSync(BASELINE_PATH, "utf8"));
|
|
const current = measureComplexityCount();
|
|
const { regressed, improved } = evaluateComplexity(current, baseline.count);
|
|
|
|
if (UPDATE && improved) {
|
|
console.log(`[complexity] baseline ratcheado: ${current} (era ${baseline.count})`);
|
|
baseline.count = current;
|
|
fs.writeFileSync(BASELINE_PATH, JSON.stringify(baseline, null, 2) + "\n");
|
|
}
|
|
if (regressed) {
|
|
console.error(
|
|
`[complexity] REGRESSÃO — ${current} violações > baseline ${baseline.count}\n` +
|
|
` → quebre a função em helpers menores (reduza ramos/tamanho) ou rode\n` +
|
|
` 'node scripts/check/check-complexity.mjs --update' se a contagem caiu legitimamente.`
|
|
);
|
|
process.exit(1);
|
|
}
|
|
console.log(`[complexity] OK — ${current} violações (baseline ${baseline.count})`);
|
|
}
|
|
|
|
if (import.meta.url === pathToFileURL(process.argv[1] || "").href) main();
|