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

refactor(eslint-plugin): avoid looking for nodes that do not match the provided options #3922

Conversation

rafaelss95
Copy link
Contributor

Context: #3899 (comment)

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @rafaelss95!

typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community.

The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately.

Thanks again!


🙏 Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/typescript-eslint. As a thank you, your profile/company logo will be added to our main README which receives thousands of unique visitors per day.

context,
[
{
arrayDestructuring,
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 went with destructuring options to avoid options[Option.xyz] everywhere, but I can revert this part if desired.

@rafaelss95 rafaelss95 changed the title refactor(eslint-plugin): avoiding looking for nodes which doesn't corresponds given options refactor(eslint-plugin): avoid looking for nodes which doesn't corresponds given options Sep 23, 2021
@rafaelss95 rafaelss95 changed the title refactor(eslint-plugin): avoid looking for nodes which doesn't corresponds given options refactor(eslint-plugin): avoid looking for nodes that do not match the provided options Sep 23, 2021
@rafaelss95 rafaelss95 force-pushed the refactor/remove-unnecessary-nodes-given-options branch 2 times, most recently from 206ae6e to 87d54b7 Compare September 23, 2021 23:16
@rafaelss95 rafaelss95 marked this pull request as ready for review September 23, 2021 23:20
@rafaelss95 rafaelss95 force-pushed the refactor/remove-unnecessary-nodes-given-options branch from 87d54b7 to b84b05f Compare September 23, 2021 23:59
@codecov
Copy link

codecov bot commented Sep 24, 2021

Codecov Report

Merging #3922 (467fa6c) into master (7842090) will increase coverage by 0.24%.
The diff coverage is 85.59%.

@@            Coverage Diff             @@
##           master    #3922      +/-   ##
==========================================
+ Coverage   93.12%   93.37%   +0.24%     
==========================================
  Files         277      153     -124     
  Lines        9781     8132    -1649     
  Branches     2851     2576     -275     
==========================================
- Hits         9109     7593    -1516     
+ Misses        244      182      -62     
+ Partials      428      357      -71     
Flag Coverage Δ
unittest 93.37% <85.59%> (+0.24%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...plugin/src/rules/explicit-module-boundary-types.ts 89.47% <ø> (ø)
...kages/eslint-plugin/src/rules/init-declarations.ts 81.25% <ø> (-1.11%) ⬇️
...nt-plugin/src/rules/lines-between-class-members.ts 92.85% <0.00%> (ø)
...es/eslint-plugin/src/rules/no-duplicate-imports.ts 95.55% <ø> (-0.10%) ⬇️
...s/eslint-plugin/src/rules/no-unused-expressions.ts 89.47% <0.00%> (ø)
...lugin/src/rules/prefer-readonly-parameter-types.ts 100.00% <ø> (ø)
.../eslint-plugin/src/rules/method-signature-style.ts 85.71% <75.60%> (-1.50%) ⬇️
packages/eslint-plugin/src/rules/typedef.ts 92.10% <82.60%> (-3.95%) ⬇️
...lugin/src/rules/consistent-indexed-object-style.ts 90.00% <95.45%> (ø)
packages/eslint-plugin-tslint/src/rules/config.ts 97.36% <100.00%> (ø)
... and 137 more

@rafaelss95 rafaelss95 force-pushed the refactor/remove-unnecessary-nodes-given-options branch 4 times, most recently from 2544848 to 72ad35b Compare September 24, 2021 01:36
@rafaelss95 rafaelss95 force-pushed the refactor/remove-unnecessary-nodes-given-options branch 2 times, most recently from 2d047c1 to 48b3de8 Compare October 2, 2021 04:49
@bradzacher bradzacher added the refactor PRs that refactor code only label Oct 3, 2021
@rafaelss95 rafaelss95 force-pushed the refactor/remove-unnecessary-nodes-given-options branch 2 times, most recently from 250dd28 to d7c2e70 Compare October 12, 2021 23:12
@rafaelss95 rafaelss95 force-pushed the refactor/remove-unnecessary-nodes-given-options branch from 499e847 to 612f02d Compare October 12, 2021 23:17
Copy link
Member

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

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

I love it 🚀 !

Wondering if it would be doable to make a lint rule for ESLint rules that enforces this kind of check...

@bradzacher
Copy link
Member

it's probably too complicated to statically analyse for.
I wonder if instead there was a way we could build an API for this style to make it easier to build for.

@bradzacher bradzacher merged commit 713fd77 into typescript-eslint:master Oct 18, 2021
Comment on lines +178 to +180
!node.value ||
!isVariableDeclarationIgnoreFunction(node.value) ||
!node.typeAnnotation
Copy link
Member

Choose a reason for hiding this comment

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

this change in logic is incorrect - #4033
There was no "valid" test case covering memberVariableDeclaration: true - hence this slipped through

old logic

if (
  !(node.value && isVariableDeclarationIgnoreFunction(node.value)) &&
  !node.typeAnnotation
) {
  report();
}

new logic

if (
  !node.value ||
  !isVariableDeclarationIgnoreFunction(node.value) ||
  !node.typeAnnotation
) {
  report();
}

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 20, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
refactor PRs that refactor code only
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants