-
-
Notifications
You must be signed in to change notification settings - Fork 308
chore: block new problems from being added to the suppressions files #10314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
cryptodev-2s
wants to merge
28
commits into
main
Choose a base branch
from
tsc-suppressions-ratchet
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+477
−46
Open
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
c096585
feat: block new type errors from being added to the suppressions file
cryptodev-2s 95bbaa9
chore: use execa's named export in the ratchet
cryptodev-2s 5cd129c
chore: use .ts import extensions in the ratchet
cryptodev-2s fde5960
chore: apply review feedback to the ratchet
cryptodev-2s c9c09fc
chore: let the merge commit supply the baseline
cryptodev-2s d2b5e8d
feat: guard the oxlint suppressions too, and deduplicate
cryptodev-2s 197abc3
chore: drop the comment above fetch-depth
cryptodev-2s 15b2767
chore: drop the jest.unstable_mockModule comment
cryptodev-2s f565e57
chore: name the oxlint suppressions file
cryptodev-2s 4981df8
Merge branch 'main' into tsc-suppressions-ratchet
cryptodev-2s 70e0a7c
chore: drop the strip types flag
cryptodev-2s 4feb1d0
chore: rename to lint:suppressions
cryptodev-2s fe17f7b
chore: make the check work locally without arguments
cryptodev-2s c78ee09
chore: assert the git calls without indexing them
cryptodev-2s 9b97e79
fix: only trust the first parent in CI
cryptodev-2s 131f07e
chore: reword the comment about resetting global state
cryptodev-2s 2c02eff
Merge branch 'main' into tsc-suppressions-ratchet
cryptodev-2s 39074d1
feat: let a label waive the suppressions check
cryptodev-2s d888d1a
fix: read the waiver label back over the API
cryptodev-2s 18da785
refactor: move the suppressions check to its own workflow
cryptodev-2s bc5d8d8
chore: drop a comment
cryptodev-2s 19e0119
chore: drop a comment
cryptodev-2s d5f622d
feat: give core platform ownership of the suppressions files
cryptodev-2s dd64190
chore: stop pointing everyone at the waiver label
cryptodev-2s 22907bf
chore: let the check speak for itself on failure
cryptodev-2s 2f63e00
chore: check the waiver label before running the check
cryptodev-2s 76171d7
chore: guard the whole job with the waiver label
cryptodev-2s 89fa89f
Merge branch 'main' into tsc-suppressions-ratchet
cryptodev-2s File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| name: Lint Suppressions | ||
|
|
||
| on: | ||
| pull_request: | ||
| types: [opened, synchronize, labeled, unlabeled] | ||
| merge_group: | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| lint-suppressions: | ||
| name: Lint suppressions | ||
| if: ${{ github.event_name != 'merge_group' && !contains(github.event.pull_request.labels.*.name, 'allow-new-suppressions') }} | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| matrix: | ||
| node-version: [24.x] | ||
| steps: | ||
| - name: Checkout and setup environment | ||
| uses: MetaMask/action-checkout-and-setup@v3 | ||
| with: | ||
| is-high-risk-environment: false | ||
| persist-credentials: false | ||
| node-version: ${{ matrix.node-version }} | ||
| fetch-depth: 2 | ||
| - name: Run yarn lint:suppressions | ||
| run: yarn lint:suppressions | ||
| - name: Require clean working directory | ||
| shell: bash | ||
| run: | | ||
| if ! git diff --exit-code; then | ||
| echo "Working tree dirty at end of job" | ||
| exit 1 | ||
| fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,227 @@ | ||
| import { jest } from '@jest/globals'; | ||
|
|
||
| jest.unstable_mockModule('execa', () => ({ | ||
| execa: jest.fn(), | ||
| })); | ||
|
|
||
| jest.unstable_mockModule('./tsc-suppressions.ts', () => ({ | ||
| SUPPRESSIONS_FILE_NAME: 'tsc-suppressions.json', | ||
| readSuppressions: jest.fn(), | ||
| })); | ||
|
|
||
| const { execa } = await import('execa'); | ||
| const tscSuppressions = await import('./tsc-suppressions.ts'); | ||
| const { findAddedSuppressions, printAddedSuppressions, lintSuppressions } = | ||
| await import('./lint-suppressions.ts'); | ||
|
|
||
| describe('findAddedSuppressions', () => { | ||
| it('flags a file that the baseline does not suppress at all', () => { | ||
| expect( | ||
| findAddedSuppressions({ | ||
| current: { 'a.ts': { 'no-shadow': { count: 1 } } }, | ||
| base: {}, | ||
| }), | ||
| ).toStrictEqual([ | ||
| { filePath: 'a.ts', rule: 'no-shadow', count: 1, baseCount: 0 }, | ||
| ]); | ||
| }); | ||
|
|
||
| it('flags a rule that the baseline does not suppress within a file it does', () => { | ||
| expect( | ||
| findAddedSuppressions({ | ||
| current: { | ||
| 'a.ts': { 'no-shadow': { count: 1 }, 'id-length': { count: 1 } }, | ||
| }, | ||
| base: { 'a.ts': { 'no-shadow': { count: 1 } } }, | ||
| }), | ||
| ).toStrictEqual([ | ||
| { filePath: 'a.ts', rule: 'id-length', count: 1, baseCount: 0 }, | ||
| ]); | ||
| }); | ||
|
|
||
| it('flags a count that has grown', () => { | ||
| expect( | ||
| findAddedSuppressions({ | ||
| current: { 'a.ts': { TS2322: { count: 3 } } }, | ||
| base: { 'a.ts': { TS2322: { count: 2 } } }, | ||
| }), | ||
| ).toStrictEqual([ | ||
| { filePath: 'a.ts', rule: 'TS2322', count: 3, baseCount: 2 }, | ||
| ]); | ||
| }); | ||
|
|
||
| it('allows a count that is unchanged', () => { | ||
| expect( | ||
| findAddedSuppressions({ | ||
| current: { 'a.ts': { TS2322: { count: 2 } } }, | ||
| base: { 'a.ts': { TS2322: { count: 2 } } }, | ||
| }), | ||
| ).toStrictEqual([]); | ||
| }); | ||
|
|
||
| it('allows a count that has shrunk', () => { | ||
| expect( | ||
| findAddedSuppressions({ | ||
| current: { 'a.ts': { TS2322: { count: 1 } } }, | ||
| base: { 'a.ts': { TS2322: { count: 5 } } }, | ||
| }), | ||
| ).toStrictEqual([]); | ||
| }); | ||
|
|
||
| it('allows a rule or a file to disappear entirely', () => { | ||
| expect( | ||
| findAddedSuppressions({ | ||
| current: {}, | ||
| base: { 'a.ts': { TS2322: { count: 5 }, TS7005: { count: 1 } } }, | ||
| }), | ||
| ).toStrictEqual([]); | ||
| }); | ||
|
|
||
| it('reports every addition, not just the first', () => { | ||
| expect( | ||
| findAddedSuppressions({ | ||
| current: { | ||
| 'a.ts': { TS2322: { count: 1 } }, | ||
| 'b.ts': { TS7005: { count: 2 } }, | ||
| }, | ||
| base: {}, | ||
| }), | ||
| ).toHaveLength(2); | ||
| }); | ||
| }); | ||
|
|
||
| describe('printAddedSuppressions', () => { | ||
| beforeEach(() => { | ||
| jest.spyOn(console, 'log').mockReturnValue(undefined); | ||
| }); | ||
|
|
||
| it('announces success when nothing was added, naming the file', () => { | ||
| printAddedSuppressions('oxlint-suppressions.json', []); | ||
|
|
||
| expect(console.log).toHaveBeenCalledWith( | ||
| '✅ Nothing has been added to oxlint-suppressions.json. Good job!', | ||
| ); | ||
| }); | ||
|
|
||
| it('prints each addition and how to resolve it', () => { | ||
| printAddedSuppressions('oxlint-suppressions.json', [ | ||
| { filePath: 'a.ts', rule: 'no-shadow', count: 3, baseCount: 2 }, | ||
| ]); | ||
|
|
||
| const output = jest.mocked(console.log).mock.calls.flat().join('\n'); | ||
| expect(output).toContain('oxlint-suppressions.json'); | ||
| expect(output).toContain('a.ts'); | ||
| expect(output).toContain('no-shadow'); | ||
| expect(output).toContain('3'); | ||
| expect(output).toContain('2'); | ||
| }); | ||
| }); | ||
|
|
||
| /** | ||
| * Stubs the Git commands the check runs. | ||
| * | ||
| * @param suppressions - The baseline the commands should produce. | ||
| */ | ||
| function mockGit(suppressions = '{}'): void { | ||
| jest.mocked(execa).mockImplementation((async ( | ||
| _file: string, | ||
| args: string[], | ||
| ) => { | ||
| if (args[0] === 'merge-base') { | ||
| return { stdout: 'abc123\n' }; | ||
| } | ||
| return { stdout: suppressions }; | ||
| }) as never); | ||
| } | ||
|
|
||
| describe('lintSuppressions', () => { | ||
| let originalProcess: typeof globalThis.process; | ||
|
|
||
| beforeEach(() => { | ||
| originalProcess = globalThis.process; | ||
| // The exit code is reset because another test file may have set it. | ||
| // `GITHUB_ACTIONS` is cleared because this suite runs in CI, where it is | ||
| // set, which would otherwise send every test down the CI path. | ||
| globalThis.process = { | ||
| ...globalThis.process, | ||
| exitCode: undefined, | ||
| env: { ...globalThis.process.env, GITHUB_ACTIONS: undefined }, | ||
| }; | ||
| jest.spyOn(console, 'log').mockReturnValue(undefined); | ||
| mockGit(); | ||
| jest.mocked(tscSuppressions.readSuppressions).mockResolvedValue({}); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| globalThis.process = originalProcess; | ||
| }); | ||
|
|
||
| it('reads the baseline from the first parent of the merge commit CI checks out', async () => { | ||
| process.env.GITHUB_ACTIONS = 'true'; | ||
|
|
||
| await lintSuppressions([]); | ||
|
|
||
| expect(execa).toHaveBeenCalledWith( | ||
| 'git', | ||
| ['show', 'HEAD^1:oxlint-suppressions.json'], | ||
| expect.anything(), | ||
| ); | ||
| expect(execa).toHaveBeenCalledWith( | ||
| 'git', | ||
| ['show', 'HEAD^1:tsc-suppressions.json'], | ||
| expect.anything(), | ||
| ); | ||
| }); | ||
|
|
||
| it('takes the merge base when running outside of CI, where a merge commit means something else', async () => { | ||
| await lintSuppressions([]); | ||
|
|
||
| expect(jest.mocked(execa)).toHaveBeenCalledWith( | ||
| 'git', | ||
| ['merge-base', 'HEAD', 'origin/main'], | ||
| expect.anything(), | ||
| ); | ||
| expect(execa).toHaveBeenCalledWith( | ||
| 'git', | ||
| ['show', 'abc123:oxlint-suppressions.json'], | ||
| expect.anything(), | ||
| ); | ||
| expect(execa).toHaveBeenCalledWith( | ||
| 'git', | ||
| ['show', 'abc123:tsc-suppressions.json'], | ||
| expect.anything(), | ||
| ); | ||
| }); | ||
|
|
||
| it('takes the merge base against the branch it is given', async () => { | ||
| await lintSuppressions(['origin/release']); | ||
|
|
||
| expect(jest.mocked(execa)).toHaveBeenCalledWith( | ||
| 'git', | ||
| ['merge-base', 'HEAD', 'origin/release'], | ||
| expect.anything(), | ||
| ); | ||
| }); | ||
|
|
||
| it('leaves the exit code alone when nothing has been added', async () => { | ||
| await lintSuppressions([]); | ||
|
|
||
| expect(process.exitCode).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('exits with a non-zero code when a file has grown', async () => { | ||
| jest | ||
| .mocked(tscSuppressions.readSuppressions) | ||
| .mockResolvedValue({ 'a.ts': { 'no-shadow': { count: 1 } } }); | ||
|
|
||
| await lintSuppressions([]); | ||
|
|
||
| expect(process.exitCode).toBe(1); | ||
| }); | ||
|
|
||
| it('throws when a baseline cannot be read, rather than passing', async () => { | ||
| jest.mocked(execa).mockRejectedValue(new Error('unknown revision')); | ||
|
|
||
| await expect(lintSuppressions([])).rejects.toThrow('unknown revision'); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.