Skip to content
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

ref: enable type-aware linting #88072

Merged
merged 21 commits into from
Apr 4, 2025
Merged

ref: enable type-aware linting #88072

merged 21 commits into from
Apr 4, 2025

Conversation

TkDodo
Copy link
Contributor

@TkDodo TkDodo commented Mar 27, 2025

This PR enables linting with type information; As this is quite slow, I have disabled those rules and the projectService for the pre-commit task. Linting with type information might generally not be compatible with file-by-file linting, as changing one thing can lead to lint errors in another file.

To cover for that, I’ve created a new CI task eslint that will run eslint with the full set of rules on the whole repository. This means we now have:

  • linting in your IDE with the full set of rules
  • linting on pre-commit with a faster sub-set of rules (without type information)
  • linting in CI on the whole repo with the full set of rules (on every PR that has frontend changes)

I’m expecting TypeScript to get significantly faster with v7 (typescript rewrite in go), at which point we could re-consider this split and potentially remove it.

@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Mar 27, 2025
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this eslint config is used during pre-commit. It amends the regular config by turning off all rules that need type information.

Comment on lines 40 to 47
// lint rules that need type information need to go here
export const typeAwareLintRules = {
name: 'plugin/typescript-eslint/typed-aware-linting',
rules: {
'@typescript-eslint/no-unnecessary-type-assertion': 'error',
},
};

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m exporting the rules that need type information separately here so that we can easily loop over them in the eslint-pre-commit config.

no-unnecessary-type-assertion is just an example rule to turn on, we can add more here later, but we can’t really use any presets because we want to be able to explicitly turn them off.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: I found an even better way that doesn’t involve exporting the rules. We can just use:

extends: [typescript.configs.disableTypeChecked]

which is a built-in way to disable all rules that rely on the type checker

- added|modified: '**/*.[tj]{s,sx}'
- added|modified: '**/*.{ts,tsx,js,jsx,mjs}'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’ve included .mjs files here because they are also frontend related files, e.g. the eslint config files are in .mjs format.

@github-actions github-actions bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Mar 27, 2025
Copy link
Contributor

🚨 Warning: This pull request contains Frontend and Backend changes!

It's discouraged to make changes to Sentry's Frontend and Backend in a single pull request. The Frontend and Backend are not atomically deployed. If the changes are interdependent of each other, they must be separated into two pull requests and be made forward or backwards compatible, such that the Backend or Frontend can be safely deployed independently.

Have questions? Please ask in the #discuss-dev-infra channel.

@TkDodo TkDodo marked this pull request as ready for review March 27, 2025 13:55
@TkDodo TkDodo requested review from a team as code owners March 27, 2025 13:55
@TkDodo TkDodo requested a review from a team March 27, 2025 13:56
Copy link
Member

@JonasBa JonasBa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work @TkDodo, this one is worth announcing in #discuss-frontend and at the frontend TSC!

Copy link

codecov bot commented Apr 3, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #88072      +/-   ##
==========================================
+ Coverage   87.71%   87.83%   +0.11%     
==========================================
  Files       10064    10044      -20     
  Lines      569158   568454     -704     
  Branches    22352    22144     -208     
==========================================
+ Hits       499264   499315      +51     
+ Misses      69498    68723     -775     
- Partials      396      416      +20     

Copy link
Member

@natemoo-re natemoo-re left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, excited to unblock #85552!

@TkDodo TkDodo enabled auto-merge (squash) April 4, 2025 08:29
@TkDodo TkDodo merged commit 4c1f8f5 into master Apr 4, 2025
54 checks passed
@TkDodo TkDodo deleted the tkdodo/ref/typed-linting-poc branch April 4, 2025 08:40
andrewshie-sentry pushed a commit that referenced this pull request Apr 8, 2025
This PR enables linting with type information; As this is quite slow, I
have disabled those rules and the `projectService` for the pre-commit
task. Linting with type information might generally not be compatible
with file-by-file linting, as changing one thing can lead to lint errors
in another file.

To cover for that, I’ve created a new CI task `eslint` that will run
eslint with the full set of rules on the whole repository. This means we
now have:

- linting in your IDE with the full set of rules
- linting on pre-commit with a faster sub-set of rules (without type
information)
- linting in CI on the whole repo with the full set of rules (on every
PR that has frontend changes)

I’m expecting TypeScript to get significantly faster with v7 (typescript
rewrite in go), at which point we could re-consider this split and
potentially remove it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Scope: Backend Automatically applied to PRs that change backend components Scope: Frontend Automatically applied to PRs that change frontend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants