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

Consider argsIgnorePattern for no-unused-vars rule #97

Open
joshuacurtiss opened this issue Dec 22, 2023 · 1 comment
Open

Consider argsIgnorePattern for no-unused-vars rule #97

joshuacurtiss opened this issue Dec 22, 2023 · 1 comment
Assignees

Comments

@joshuacurtiss
Copy link
Contributor

There are instances, such as implementing/extending a class with a function that has an argument that your implementation won't use, which will trigger the no-unused-vars eslint rule.

Typically, we may just disable no-unused-vars when this occurs, such as here:
https://github.com/silvermine/service-web/blob/77db28f0/service-web-core/src/model/Web.ts#L48

In these cases, we nearly always use a prepended underscore by convention to signify the arg is unused, but still have to disable the rule.

If we modify the rule like this:

'no-unused-vars': [ 'error', { 'argsIgnorePattern': '^_' } ],

Then the convention we are already using will automatically be ignored by the rule and we'll no longer have to explicitly disable the rule with an eslint-disable-line comment.

diff --git a/index.js b/index.js
index f8b966b..25051e9 100644
--- a/index.js
+++ b/index.js
@@ -140,7 +140,7 @@ module.exports = {
       'no-shadow-restricted-names': 'error',
       'no-undef': 'error',
       'no-undef-init': 'error',
-      'no-unused-vars': 'error',
+      'no-unused-vars': [ 'error', { 'argsIgnorePattern': '^_' } ],
       'no-use-before-define': [ 'error', { 'functions': false } ],
 
       'callback-return': [ 'error', [ 'callback', 'cb', 'next', 'done' ] ],
@@ -284,7 +284,7 @@ module.exports = {
             // The standard ESLint `no-unused-vars' rule will throw false positives with
             // class properties in TypeScript. The TypeScript-specific rule fixes this.
             'no-unused-vars': 'off',
-            '@typescript-eslint/no-unused-vars': 'error',
+            '@typescript-eslint/no-unused-vars': [ 'error', { 'argsIgnorePattern': '^_' } ],
             // For TypeScript code, `const`/`let` should be used exclusively
             'no-var': 'error',
             // new-cap throws errors with property decorators
@jthomerson
Copy link
Member

I like it. @onebytegone thoughts?

@pbredenberg pbredenberg self-assigned this Mar 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants