diff --git a/config/scripts/check-changed-code-quality.mjs b/config/scripts/check-changed-code-quality.mjs index 2a3542e78b9..8fc95203640 100644 --- a/config/scripts/check-changed-code-quality.mjs +++ b/config/scripts/check-changed-code-quality.mjs @@ -15,7 +15,13 @@ export const OXLINT_SCANS = [ }, { label: 'type-aware code quality', - args: ['--type-aware', '--config', 'config/oxlint-code-quality-type-aware.json'] + args: ['--type-aware', '--config', 'config/oxlint-code-quality-type-aware.json'], + // Why: type-aware rules need the types to RESOLVE, and mobile's live only in + // mobile/node_modules. Linting them under the root config turns every such import into an + // `error` type, which `no-redundant-type-constituents` then reports as a real finding. The + // package script scopes this scan to `src config tests` for the same reason; the changed-file + // gate has to agree with it or it invents findings the repo cannot reproduce. + excludes: (file) => file === 'mobile' || file.startsWith('mobile/') }, { label: 'React Doctor', @@ -195,7 +201,12 @@ export function main( let failures = 0 for (const scan of OXLINT_SCANS) { - const diagnostics = runOxlintScan(root, scan, files).filter((diagnostic) => + const scanned = scan.excludes ? files.filter((file) => !scan.excludes(file)) : files + if (scanned.length === 0) { + console.log(`${scan.label}: 0 new finding(s) across 0 changed file(s).`) + continue + } + const diagnostics = runOxlintScan(root, scan, scanned).filter((diagnostic) => diagnosticTouchesAddedLines(diagnostic, rangesByFile, root) ) for (const diagnostic of diagnostics) { @@ -203,7 +214,7 @@ export function main( } failures += diagnostics.length console.log( - `${scan.label}: ${diagnostics.length} new finding(s) across ${files.length} changed file(s).` + `${scan.label}: ${diagnostics.length} new finding(s) across ${scanned.length} changed file(s).` ) } diff --git a/config/scripts/check-changed-code-quality.test.mjs b/config/scripts/check-changed-code-quality.test.mjs index 5daca8da49e..afca9484c52 100644 --- a/config/scripts/check-changed-code-quality.test.mjs +++ b/config/scripts/check-changed-code-quality.test.mjs @@ -51,4 +51,19 @@ describe('changed-code quality line matching', () => { expect(scan.args).not.toContain('--config') expect(scan.args).not.toContain('--disable-nested-config') }) + + // Why: the type-aware scan DOES pin the root config, and mobile's types resolve only from + // mobile/node_modules. Linting mobile under the root config makes every such import an `error` + // type, which no-redundant-type-constituents reports as a real finding — findings the package + // script cannot reproduce, because it scopes this scan to `src config tests`. + it('keeps the type-aware scan off mobile, whose types the root config cannot resolve', () => { + const scan = OXLINT_SCANS.find((candidate) => candidate.label === 'type-aware code quality') + + expect(scan.args).toContain('--type-aware') + expect(scan.excludes('mobile/src/session/use-mobile-structured-attachments.test.ts')).toBe(true) + expect(scan.excludes('mobile')).toBe(true) + expect(scan.excludes('src/main/runtime/orca-runtime.ts')).toBe(false) + // A path that merely starts with the same letters is not inside the package. + expect(scan.excludes('mobile-shim/src/a.ts')).toBe(false) + }) })