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

[naming-convention] modifier export - Allow selecting only exported members #2239

Closed
RebeccaStevens opened this issue Jun 23, 2020 · 5 comments · Fixed by #2808
Closed

[naming-convention] modifier export - Allow selecting only exported members #2239

RebeccaStevens opened this issue Jun 23, 2020 · 5 comments · Fixed by #2808
Labels
enhancement: plugin rule option New rule option for an existing eslint-plugin rule package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@RebeccaStevens
Copy link
Contributor

Repro

{
  "rules": {
    "@typescript-eslint/naming-convention": [
      "error",
      { "selector": "variable", "format": ["camelCase"] },
      // { "selector": "variable", "modifiers": ["export"], "format": ["UPPER_CASE"] }
    ]
  }
}
export const FOO = 'hello';
const bar = 'world';

Expected Result

The ability to enforce a naming convention that only applies to exported members.

Actual Result

Cannot narrow down selector enough.

Additional Info

Related to: #1612

Versions

package version
@typescript-eslint/eslint-plugin 3.4.0
@typescript-eslint/parser 3.4.0
TypeScript 3.9.5
ESLint 7.2.0
node 14.4.0
npm 6.14.5
@RebeccaStevens RebeccaStevens added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels Jun 23, 2020
@bradzacher
Copy link
Member

how come you want to specifically name exported variables differently to non-exported variables?

@bradzacher bradzacher added awaiting response Issues waiting for a reply from the OP or another party and removed triage Waiting for maintainers to take a look labels Jun 24, 2020
@RebeccaStevens
Copy link
Contributor Author

When importing constants, I tend to like them being in upper case so that I can tell they are a constant at a glance and not something else like a function.

When just using constants in a module (without exporting them), there's no need to make upper case as it is clear from context what they are.

@bradzacher bradzacher added enhancement: plugin rule option New rule option for an existing eslint-plugin rule and removed awaiting response Issues waiting for a reply from the OP or another party labels Jun 26, 2020
@Mossop
Copy link

Mossop commented Jul 22, 2020

I came to suggest the same thing but because I do things the other way around. I tend to use constants within a module for magic numbers and such but for exported objects prefer camel case.

@nicolas-cherel
Copy link

how come you want to specifically name exported variables differently to non-exported variables?

Looks to me that it is the reasons for public/private class members applies really well for exported and non exported identifiers within a module

@nicolas-cherel
Copy link

I'd also add this modifier for typeLike selector

bradzacher added a commit that referenced this issue Nov 24, 2020
…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.
bradzacher added a commit that referenced this issue Nov 24, 2020
…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 added a commit that referenced this issue Nov 24, 2020
…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 added a commit that referenced this issue 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 issue 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 issue 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 issue 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.