Skip to content

Commit f3eb3f2

Browse files
committed
fix(mcp): leave rules turned off out of the SARIF rule list
pangular lint --format sarif listed every template rule, so a rule turned off in lint.rules still showed in code scanning as an active rule.
1 parent 8857f8d commit f3eb3f2

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

‎packages/devtools/src/__tests__/lint-export.test.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,15 @@ describe('runSourceLints', () => {
103103
});
104104

105105
describe('toSarif', () => {
106+
it('leaves template rules turned off out of the rule list', async () => {
107+
const sarif = toSarif(
108+
await runSourceLints(project(), { compiler, rules: { 'img-missing-alt': false } }),
109+
);
110+
const ids = sarif.runs[0]!.tool.driver.rules.map((rule) => rule.id);
111+
expect(ids).not.toContain('templates/img-missing-alt');
112+
expect(ids).toContain('templates/track-by-index');
113+
});
114+
106115
it('writes a SARIF 2.1.0 log with rules, levels and physical locations', async () => {
107116
const sarif = toSarif(await runSourceLints(project(), { compiler }));
108117
expect(sarif.version).toBe('2.1.0');

‎packages/devtools/src/lint-export.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ export interface LintRun {
5555
export interface LintExport {
5656
lints: LintRun[];
5757
findings: ExportFinding[];
58+
/** Rules turned off in `lint.rules`, which the SARIF rule list leaves out. */
59+
rulesOff?: string[];
5860
}
5961

6062
const SEVERITY_ORDER: Record<LintSeverity, number> = { error: 0, warning: 1, info: 2 };
@@ -146,7 +148,8 @@ export async function runSourceLints(
146148
(a.file ?? '').localeCompare(b.file ?? '') ||
147149
(a.line ?? 0) - (b.line ?? 0),
148150
);
149-
return { lints, findings };
151+
const rulesOff = Object.keys(rules ?? {}).filter((rule) => rules?.[rule] === false);
152+
return { lints, findings, ...(rulesOff.length ? { rulesOff } : {}) };
150153
}
151154

152155
export function lintNames(): SourceLint[] {
@@ -189,6 +192,7 @@ export function toSarif(result: LintExport) {
189192
for (const lint of result.lints) {
190193
if (lint.lint !== 'templates' || !lint.ran) continue;
191194
for (const [rule, level] of Object.entries(TEMPLATE_LINT_RULES)) {
195+
if (result.rulesOff?.includes(rule)) continue;
192196
rules.set(`templates/${rule}`, { id: `templates/${rule}`, level, lint: 'templates' });
193197
}
194198
}

0 commit comments

Comments
 (0)