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] Allow underscore prefix for unused parameters #1510

Closed
glen-84 opened this issue Jan 24, 2020 · 12 comments · Fixed by #2810
Closed

[naming-convention] Allow underscore prefix for unused parameters #1510

glen-84 opened this issue Jan 24, 2020 · 12 comments · Fixed by #2810
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

@glen-84
Copy link
Contributor

glen-84 commented Jan 24, 2020

Repro

{
  "rules": {
    "@typescript-eslint/naming-convention": [
      "error",
      {
        "selector": "default",
        "format": ["strictCamelCase"]
      }
    ]
  }
}
onComplete: (_id, name, responseJson) => {
    // Using name and responseJson, but not id.
}

Expected Result

No error on _id.

Actual Result

Error on _id.

Additional Info

As mentioned here with Brad's response here.

When using the noUnusedParameters compiler option, you have to use an underscore to suppress TypeScript's error. However, this shouldn't be done unless the parameter is actually unused.

Versions

package version
@typescript-eslint/eslint-plugin 2.16.0
@typescript-eslint/parser 2.16.0
TypeScript 3.7.5
ESLint 6.8.0
node 12.14.1
npm 6.13.4
@glen-84 glen-84 added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels Jan 24, 2020
@bradzacher bradzacher added enhancement: plugin rule option New rule option for an existing eslint-plugin rule and removed triage Waiting for maintainers to take a look labels Jan 24, 2020
@bradzacher
Copy link
Member

I need to figure out how to do this in a performant way. Using typescript's diagnostics would be awesome, but they're super slow - ~50ms to get the diagnostics for a file, which is too slow for linting (related: #1335).

I should test tsutils's unused variables function. If that's quick, then that's a decent compromise.

The only problem with both of these routes is that without #716, this would require type information. Though we're planning on starting the 3.0.0 release soon, so that isn't that far off.

@nstepien

This comment has been minimized.

@glen-84

This comment has been minimized.

@bradzacher

This comment has been minimized.

@aggmoulik
Copy link
Contributor

Hy @bradzacher I think there is nothing to work in this issue so we can close it.

@bradzacher
Copy link
Member

Sorry, the last few comments were unrelated to the root issue.

For a bit of background; the naming-convention rule was derived from a 3rd party rule made for tslint.

When I wrote it, I cut some features from that rule for the purpose of keeping complexity down and cutting features until we saw how people used them.
One feature I cut was the unused modifier. This modifier would cause a selector to only match unused variables.

Right now you can only say "all variables can have leading underscores".
With this modifier, it would allow you to instead say "only unused variables can have leading underscores".

@aggmoulik
Copy link
Contributor

So, I can work on it.

@bradzacher
Copy link
Member

This needs some exploration to find an efficient way to check if a variable is unused. You're certainly welcome to explore this if you'd like.

I don't have a clear idea of how to do this in a performant manner yet.

@bradzacher
Copy link
Member

Once #2039 lands this should be pretty simple to do.

@tcodes0
Copy link

tcodes0 commented Oct 3, 2020

@bradzacher nice, #2039 got merged 💯

@evanjmg
Copy link

evanjmg commented Nov 23, 2020

How do we use it? I can't get this to work

@glen-84
Copy link
Contributor Author

glen-84 commented Nov 23, 2020

@evanjmg Use what? This hasn't been implemented yet.

bradzacher added a commit that referenced this issue Nov 24, 2020
Fixes #1510

Leverages the infra added in #2768 to mark variables as unused
bradzacher added a commit that referenced this issue Nov 24, 2020
Fixes #1510

Leverages the infra added in #2768 to mark variables as unused
@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.
Labels
enhancement: plugin rule option New rule option for an existing eslint-plugin rule package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants