Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions scripts/custom-oxlint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ async function rawScan(directory: string, allowed: Set<string>, policy: string)
return {counts, findings};
}

function fits(current: Suppressions, baseline: Suppressions) {
function fits(current: Suppressions, baseline: Suppressions, findings: Finding[] = []) {
const increases: string[] = [];
for (const [file, rules] of Object.entries(current)) {
for (const [rule, {count}] of Object.entries(rules)) {
Expand All @@ -334,6 +334,14 @@ function fits(current: Suppressions, baseline: Suppressions) {
}
}
if (increases.length > 0) {
if (findings.length > 0) {
increases.push('Current violations for over-budget file/rule pairs:');
for (const {file, line, column, rule, message} of findings) {
if (current[file]![rule]!.count > (baseline[file]?.[rule]?.count ?? 0)) {
increases.push(`${file}:${line}:${column} ${rule} ${message}`);
}
}
}
process.exitCode = 1;
throw new Error(`New incubator violations:\n${increases.join('\n')}`);
}
Expand Down Expand Up @@ -697,7 +705,7 @@ Native oxlint options:
}
}
}
fits(current.counts, reduced);
fits(current.counts, reduced, current.findings);
replacement = reduced;
} else {
if (command !== 'ci' || values.base) {
Expand All @@ -710,17 +718,19 @@ Native oxlint options:
current.counts,
await (command === 'ci'
? ciBaseline(base, allowed, policy)
: baseScan(base, allowed, policy))
: baseScan(base, allowed, policy)),
current.findings
);
}
if (command === 'enroll') {
replacement = current.counts;
} else if (command === 'ci') {
assert(committed, 'The suppression asset must be committed');
fits(current.counts, committed, current.findings);
if (serialize(committed) !== serialize(current.counts)) {
process.exitCode = 1;
throw new Error(
'Suppression budgets do not match live debt. Run pnpm run fix:oxlint after cleanup, or pnpm run lint:js --prune for remaining budgets. Use pnpm run lint:js --enroll --base REF for changed policy using trusted source.'
'Suppression budgets are stale. Run pnpm run lint:js --prune and commit the updated oxlint-suppressions.json.'
);
}
}
Expand Down
44 changes: 43 additions & 1 deletion scripts/customOxlint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,10 @@ test('base scans resolve installed dependencies and use base workspace source',
changed.stderr,
/index.ts typescript\/no-floating-promises: 1 violations, budget 0/
);
assert.match(
changed.stderr,
/packages\/example\/index.ts:4:1 typescript\/no-floating-promises Promises must be awaited/
);
});

test('CI scans head once and rejects increased or stale budgets', t => {
Expand All @@ -297,14 +301,43 @@ test('CI scans head once and rejects increased or stale budgets', t => {
const increase = ci(1);
assert.equal(increase.status, 1, increase.stderr);
assert.match(increase.stderr, /2 violations, budget 1/);
assert.match(
increase.stderr,
/source.js:1:1 no-debugger `debugger` statement is not allowed/
);
assert.match(
increase.stderr,
/source.js:1:11 no-debugger `debugger` statement is not allowed/
);
write('source.js', '');
const stale = ci(1);
assert.equal(stale.status, 1, stale.stderr);
assert.match(stale.stderr, /Suppression budgets do not match live debt/);
assert.match(stale.stderr, /Suppression budgets are stale/);
assert.match(stale.stderr, /pnpm run lint:js --prune/);
assert.match(stale.stderr, /commit the updated oxlint-suppressions.json/);
assert.doesNotMatch(stale.stderr, /fix:oxlint|--enroll|New incubator violations/);
write('oxlint-suppressions.json', '{}');
assert.equal(ci(1).status, 0);
});

test('CI and prune report violations exceeding committed budgets', t => {
const {directory, write, lint, ci} = ciFixture(t);
write('oxlint-suppressions.json', '{}');
for (const result of [ci(1), lint('--ci'), lint('--prune')]) {
assert.equal(result.status, 1, result.stderr);
assert.match(result.stderr, /source.js no-debugger: 1 violations, budget 0/);
assert.match(
result.stderr,
/source.js:1:1 no-debugger `debugger` statement is not allowed/
);
assert.doesNotMatch(result.stderr, /stale|pnpm run lint:js --prune/);
}
assert.equal(
readFileSync(path.join(directory, 'oxlint-suppressions.json'), 'utf8'),
'{}'
);
});

test('CI transfers exact rename budgets but rejects copies and edited renames', t => {
const {directory, write, git, ci} = ciFixture(t);
renameSync(path.join(directory, 'source.js'), path.join(directory, 'moved.js'));
Expand Down Expand Up @@ -358,6 +391,15 @@ test('CI rescans the base for changed policy or a missing baseline', t => {
const increase = ci(2);
assert.equal(increase.status, 1, increase.stderr);
assert.match(increase.stderr, /no-alert: 2 violations, budget 1/);
assert.match(
increase.stderr,
/source.js:1:11 no-alert `alert`, `confirm` and `prompt` functions are not allowed/
);
assert.match(
increase.stderr,
/source.js:1:30 no-alert `alert`, `confirm` and `prompt` functions are not allowed/
);
assert.doesNotMatch(increase.stderr, /no-debugger/);
rmSync(path.join(directory, 'oxlint-suppressions.json'));
commit();
write(
Expand Down
Loading