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

fix: correct decorator traversal for AssignmentPattern #2375

Merged
merged 1 commit into from Aug 9, 2020

Conversation

bradzacher
Copy link
Member

Fixes #2369

BREAKING CHANGE:

  • Removed decorators property from several Nodes that could never semantically have them (FunctionDeclaration, TSEnumDeclaration, and TSInterfaceDeclaration)
  • Removed AST_NODE_TYPES.Import. This is a minor breaking change as the node type that used this was removed ages ago.

This was an interesting bug to fix!
We had a bug in our visitor keys here - they didn't declare the decorators key for AssignmentPattern, this meant that when ESLint traversed the tree, it wouldn't traverse assignment pattern's decorators, so it wouldn't add the parent property.

So when no-unused-vars attempted to get the parent of the Optional Identifier for the decorator, it wouldn't find one, and hence it would crash.

This PR:

  • adds the missing visitor keys for AssignmentPattern
  • removes decorator keys for nodes that aren't semantically allowed to have them.
    • I'm not sure why we ever bothered emitting invalid code here because:
      • TS will parse-time allow it, but will semantic error. And then it scrubs the decorator from compiled code, so the decorator is 100% invalid in all these cases.
      • Babel will parse-time error.
  • removes AST_NODE_TYPES.Import
  • adds a funky typecheck-time test to ensure all AST_NODE_TYPES members have an associated TSESTree.Node type (so we don't forget to delete them ever again)
  • adds strict types to vistor-keys so that IDEs give autocomplete, and we ensure that both the array of keys is valid, and that the node types all exist in AST_NODE_TYPES.

@bradzacher bradzacher added bug Something isn't working breaking change This change will require a new major version to be released labels Aug 8, 2020
@bradzacher bradzacher added this to the 4.0.0 milestone Aug 8, 2020
@typescript-eslint
Copy link
Contributor

Thanks for the PR, @bradzacher!

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.

@bradzacher bradzacher force-pushed the 2369-decorator-traversal branch 2 times, most recently from 2b75c5b to 60a6051 Compare August 9, 2020 00:21
@codecov
Copy link

codecov bot commented Aug 9, 2020

Codecov Report

Merging #2375 into v4 will decrease coverage by 0.03%.
The diff coverage is 66.66%.

@@            Coverage Diff             @@
##               v4    #2375      +/-   ##
==========================================
- Coverage   93.00%   92.96%   -0.04%     
==========================================
  Files         286      286              
  Lines        9060     9038      -22     
  Branches     2523     2513      -10     
==========================================
- Hits         8426     8402      -24     
- Misses        304      305       +1     
- Partials      330      331       +1     
Flag Coverage Δ
#unittest 92.96% <66.66%> (-0.04%) ⬇️

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

Impacted Files Coverage Δ
...kages/eslint-plugin/src/rules/no-empty-function.ts 77.14% <0.00%> (-6.65%) ⬇️
...nt-plugin/src/rules/no-unused-vars-experimental.ts 91.48% <ø> (ø)
packages/typescript-estree/src/convert.ts 98.34% <ø> (-0.02%) ⬇️
...pt-estree/src/ts-estree/estree-to-ts-node-types.ts 100.00% <ø> (ø)
packages/visitor-keys/src/visitor-keys.ts 100.00% <100.00%> (ø)
...ckages/eslint-plugin/src/rules/no-throw-literal.ts 96.07% <0.00%> (-0.85%) ⬇️

@bradzacher bradzacher merged commit 5ab473c into v4 Aug 9, 2020
@bradzacher bradzacher deleted the 2369-decorator-traversal branch August 9, 2020 00:42
bradzacher added a commit that referenced this pull request Aug 9, 2020
BREAKING CHANGE:
- Removed decorators property from several Nodes that could never semantically have them (FunctionDeclaration, TSEnumDeclaration, and TSInterfaceDeclaration)
- Removed AST_NODE_TYPES.Import. This is a minor breaking change as the node type that used this was removed ages ago.
bradzacher added a commit that referenced this pull request Aug 10, 2020
BREAKING CHANGE:
- Removed decorators property from several Nodes that could never semantically have them (FunctionDeclaration, TSEnumDeclaration, and TSInterfaceDeclaration)
- Removed AST_NODE_TYPES.Import. This is a minor breaking change as the node type that used this was removed ages ago.
bradzacher added a commit that referenced this pull request Aug 19, 2020
BREAKING CHANGE:
- Removed decorators property from several Nodes that could never semantically have them (FunctionDeclaration, TSEnumDeclaration, and TSInterfaceDeclaration)
- Removed AST_NODE_TYPES.Import. This is a minor breaking change as the node type that used this was removed ages ago.
bradzacher added a commit that referenced this pull request Aug 29, 2020
BREAKING CHANGE:
- Removed decorators property from several Nodes that could never semantically have them (FunctionDeclaration, TSEnumDeclaration, and TSInterfaceDeclaration)
- Removed AST_NODE_TYPES.Import. This is a minor breaking change as the node type that used this was removed ages ago.
bradzacher added a commit that referenced this pull request Aug 29, 2020
BREAKING CHANGE:
- Removed decorators property from several Nodes that could never semantically have them (FunctionDeclaration, TSEnumDeclaration, and TSInterfaceDeclaration)
- Removed AST_NODE_TYPES.Import. This is a minor breaking change as the node type that used this was removed ages ago.
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
breaking change This change will require a new major version to be released bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[no-unused-vars] Exception hit with default parameter in v.4.0.0-alpha.5
1 participant