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

feat(eslint-plugin): [naming-convention] add modifiers exported, global, and destructured modifiers - add selectors classProperty, objectLiteralProperty, typeProperty, classMethod, objectLiteralMethod, typeMethod #2802

Conversation

bradzacher
Copy link
Member

@bradzacher bradzacher commented Nov 24, 2020

Fixes #2239
Fixes #2512
Fixes #2318
Fixes #1477
Closes #2691

Big update to add a bunch of stuff.
I couldn't be bothered splitting this out into separate PRs.

Adds the following modifiers:

  • exported - matches anything that is exported from the module.
  • global - matches a variable/function declared in the top-level scope.
  • destructured - matches a variable declared via an object destructuring pattern (const {x, ignored: y, z = 2}).

Adds the following selectors (self explanatory - just breaking the selectors up):

  • classProperty
  • objectLiteralProperty
  • typeProperty
  • classMethod
  • objectLiteralMethod
  • typeMethod

Converts

  • property to a meta selector for classProperty, objectLiteralProperty, typeProperty
  • method to a meta selector for classMethod, objectLiteralMethod, typeMethod

@bradzacher bradzacher added the enhancement: plugin rule option New rule option for an existing eslint-plugin rule label Nov 24, 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.

@codecov
Copy link

codecov bot commented Nov 24, 2020

Codecov Report

Merging #2802 (cbac387) into master (49f86e8) will decrease coverage by 0.05%.
The diff coverage is 86.66%.

@@            Coverage Diff             @@
##           master    #2802      +/-   ##
==========================================
- Coverage   92.80%   92.75%   -0.06%     
==========================================
  Files         300      301       +1     
  Lines        9857    10189     +332     
  Branches     2769     2889     +120     
==========================================
+ Hits         9148     9451     +303     
- Misses        332      341       +9     
- Partials      377      397      +20     
Flag Coverage Δ
unittest 92.75% <86.66%> (-0.06%) ⬇️

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

Impacted Files Coverage Δ
...kages/eslint-plugin/src/rules/naming-convention.ts 88.43% <85.85%> (-0.88%) ⬇️
...ges/scope-manager/src/referencer/PatternVisitor.ts 77.50% <100.00%> (+8.45%) ⬆️
...ckages/scope-manager/src/referencer/VisitorBase.ts 85.29% <0.00%> (-4.00%) ⬇️
...ges/experimental-utils/src/ast-utils/predicates.ts 36.84% <0.00%> (-1.62%) ⬇️
packages/experimental-utils/src/ts-eslint/Scope.ts 100.00% <0.00%> (ø)
...ges/experimental-utils/src/ts-eslint/RuleTester.ts 100.00% <0.00%> (ø)
...s/eslint-plugin/src/util/collectUnusedVariables.ts 91.10% <0.00%> (ø)
packages/eslint-plugin/src/rules/no-unused-vars.ts 96.62% <0.00%> (+3.48%) ⬆️

Copy link
Member Author

@bradzacher bradzacher left a comment

Choose a reason for hiding this comment

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

TODO

  • add example for disabling naming convention for destructured variables.
  • fix destructured applying to names that aren't directly destructured names:
const {
  a,     // a should be matched
  b = 2, // b should be matched
  c: d,  // c should be ignored, d should not be matched
  e: f = 3, // e should be ignored, f should not not be matched
};

@bradzacher bradzacher force-pushed the additional-naming-convention-selectors-and-modifiers branch from cbac387 to 5323fff Compare November 24, 2020 19:05
…lobal`, and `destructured` modifiers - add selectors `classProperty`, `objectLiteralProperty`, `typeProperty`, `classMethod`, `objectLiteralMethod`, `typeMethod`

Fixes #2239
Fixes #2512
Fixes #2318
Fixes #1477

Big update to add a bunch of stuff.
I couldn't be bothered splitting this out into separate PRs.

Adds the following modifiers:
- `exported` - matches anything that is exported from the module.
- `global` - matches a variable/function declared in the top-level scope.
- `destructured` - matches a variable declared via an object destructuring pattern (`const {x, ignored: y, z = 2}`).

Adds the following selectors (self explanatory - just breaking the selectors up):
- `classProperty`
- `objectLiteralProperty`
- `typeProperty`
- `classMethod`
- `objectLiteralMethod`
- `typeMethod`

Converts
- `property` to a meta selector for `classProperty`, `objectLiteralProperty`, `typeProperty`
- `method` to a meta selector for `classMethod`, `objectLiteralMethod`, `typeMethod`
@bradzacher bradzacher force-pushed the additional-naming-convention-selectors-and-modifiers branch from 5323fff to 3c91b53 Compare November 24, 2020 19:06
@bradzacher
Copy link
Member Author

I'm going to split this for commit cleanliness

@bradzacher bradzacher closed this Nov 24, 2020
bradzacher added a commit that referenced this pull request Nov 24, 2020
…` selectors into more granular `classXXX`, `objectLiteralXXX`, `typeXXX`

Fixes #1477
Closes #2802

This allows users to target different types of properties differently.

Adds the following selectors (self explanatory - just breaking the selectors up):

- `classProperty`
- `objectLiteralProperty`
- `typeProperty`
- `classMethod`
- `objectLiteralMethod`
- `typeMethod`

Converts
- `property` to a meta selector for `classProperty`, `objectLiteralProperty`, `typeProperty`
- `method` to a meta selector for `classMethod`, `objectLiteralMethod`, `typeMethod`
bradzacher added a commit that referenced this pull request Nov 24, 2020
…lobal`, and `destructured`

Fixes #2239
Fixes #2512
Fixes #2318
Closes #2802

Adds the following modifiers:
- `exported` - matches anything that is exported from the module.
- `global` - matches a variable/function declared in the top-level scope.
- `destructured` - matches a variable declared via an object destructuring pattern (`const {x, ignored: y, z = 2}`).
bradzacher added a commit that referenced this pull request Nov 24, 2020
…lobal`, and `destructured`

Fixes #2239
Fixes #2512
Fixes #2318
Closes #2802

Adds the following modifiers:
- `exported` - matches anything that is exported from the module.
- `global` - matches a variable/function declared in the top-level scope.
- `destructured` - matches a variable declared via an object destructuring pattern (`const {x, z = 2}`).
bradzacher added a commit that referenced this pull request Nov 24, 2020
…` selectors into more granular `classXXX`, `objectLiteralXXX`, `typeXXX` (#2807)

Fixes #1477
Closes #2802

This allows users to target different types of properties differently.

Adds the following selectors (self explanatory - just breaking the selectors up):

- `classProperty`
- `objectLiteralProperty`
- `typeProperty`
- `classMethod`
- `objectLiteralMethod`
- `typeMethod`

For backwards compatibility, also converts
- `property` to a meta selector for `classProperty`, `objectLiteralProperty`, `typeProperty`
- `method` to a meta selector for `classMethod`, `objectLiteralMethod`, `typeMethod`
bradzacher added a commit that referenced this pull request Nov 24, 2020
…lobal`, and `destructured`

Fixes #2239
Fixes #2512
Fixes #2318
Closes #2802

Adds the following modifiers:
- `exported` - matches anything that is exported from the module.
- `global` - matches a variable/function declared in the top-level scope.
- `destructured` - matches a variable declared via an object destructuring pattern (`const {x, z = 2}`).
@bradzacher bradzacher deleted the additional-naming-convention-selectors-and-modifiers branch November 24, 2020 19:39
bradzacher added a commit that referenced this pull request Nov 24, 2020
…lobal`, and `destructured` (#2808)

Fixes #2239
Fixes #2512
Fixes #2318
Closes #2802

Adds the following modifiers:
- `exported` - matches anything that is exported from the module.
- `global` - matches a variable/function declared in the top-level scope.
- `destructured` - matches a variable declared via an object destructuring pattern (`const {x, z = 2}`).
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.