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

enable @typescript-eslint/no-unused-vars #57123

Merged
merged 25 commits into from
Jan 29, 2024

Conversation

abrahamguo
Copy link
Contributor

@abrahamguo abrahamguo commented Jan 22, 2024

Resolves the TODO comment regarding enabling the ESLint rule @typescript-eslint/no-unused-vars

Fixes #57124

@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Jan 22, 2024
@typescript-bot
Copy link
Collaborator

This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise.

@abrahamguo
Copy link
Contributor Author

@microsoft-github-policy-service agree

@abrahamguo abrahamguo changed the title enable @typescript-eslint/no-unused-vars enable @typescript-eslint/no-unused-vars Jan 22, 2024
Copy link
Member

@jakebailey jakebailey left a comment

Choose a reason for hiding this comment

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

You should see #55139 for context. There are some unfortunate caveats, I'm afraid.

@jakebailey
Copy link
Member

jakebailey commented Jan 22, 2024

Well, we could of course ignore lines for JSDoc, like you've done here. Maybe that's enough and we can live with it to avoid compiler errors.

package-lock.json Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
@abrahamguo
Copy link
Contributor Author

Yes, I think that (at least for now) it seems like an easy task to suppress the <5 places with JSDoc issues in order to get the benefit of this rule applying throughout the whole codebase.

package.json Outdated Show resolved Hide resolved
@jakebailey
Copy link
Member

Generally speaking, I prefer the settings and changes in #55139, besides the JSDoc plugin thing.

That being said, the regex should probably be changed to ^_[^_] as your PR has pointed out that __String is treated as used which isn't intentional.

.eslintrc.json Outdated Show resolved Hide resolved
src/compiler/core.ts Outdated Show resolved Hide resolved
@jakebailey
Copy link
Member

I also think we could remove allowUnusedLabels too, we're already getting no-unused-labels from eslint.

.eslintrc.json Outdated Show resolved Hide resolved
@jakebailey
Copy link
Member

The scripts are currently inconsistent as to their use of typedefs or import type nodes; can you switch them all to be import type nodes? At least for the ones that aren't compound like CallOrNewExpression?

@abrahamguo
Copy link
Contributor Author

Sure — my thinking was to create typedefs for ones that are used more than once, since the imports are long, but I can inline the typedefs if you like that 👍🏻

@jakebailey
Copy link
Member

That makes sense, though I think having the code be more easily copy-paste-able between the rules is probably worthwhile.

Eventually we'll have #57207, though. That'll be awesome.

Copy link
Member

@jakebailey jakebailey left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks for bearing with all of my comments.

@typescript-bot typescript-bot added For Backlog Bug PRs that fix a backlog bug and removed For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Jan 29, 2024
@abrahamguo
Copy link
Contributor Author

No worries! Thanks for the detailed review.

Would you be open to future PRs turning on other ESLint rules for the codebase?
In particular, I've been looking at prefer-destructuring or logical-assignment-operators which are both autofixable, as well as some of the rules from @typescript-eslint/recommended-requiring-type-checking.
I wasn't sure if there was any bigger vision one way or another.

@jakebailey
Copy link
Member

jakebailey commented Jan 29, 2024

Enabling the rules that use type checking is a bit of a perf hole; I wouldn't attempt to enable any of those unless there are some that look super valuable.

Last I checked logical-assignment-operators it had a load of false positives; I tried to enable it and fix everything but I had to sift through hundreds of changes to make sure none caused a behavior change.

There may be others that are valuable but I think it really depends.

@abrahamguo
Copy link
Contributor Author

logical-assignment-operators looks to just change a = a || b to a ||= b (and same with && ??), so it looks to be guaranteed correctly autofixable.

I'll look into the type-checked lint rules and maybe do some performance monitoring.

@jakebailey
Copy link
Member

Ah, I was thinking of prefer-nullish-coalescing.

But generally, know that it isn't a goal to enable every lint rule; the codebase is huge and it slows down linting and editor performance. Most on the team don't even run eslint in the editor for that reason. We really only want cheap rules / rules that have high value.

@jakebailey jakebailey merged commit 3c9aea3 into microsoft:main Jan 29, 2024
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Backlog Bug PRs that fix a backlog bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

enable @typescript-eslint/no-unused-vars
3 participants