Skip to content

Commit

Permalink
Merge pull request #182 from Automattic/improve/no-unused
Browse files Browse the repository at this point in the history
Improve no-unused rules
  • Loading branch information
chriszarate committed Oct 31, 2023
2 parents 2f9f8f7 + b111810 commit 7cd92a5
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 18 deletions.
2 changes: 1 addition & 1 deletion __fixtures__/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default {
things,
};

function someCoolDecorator( totallyRadArgument, value ): typeof totallyRadArgument {
function someCoolDecorator( totallyRadArgument, _value ): typeof totallyRadArgument {
return totallyRadArgument;
}

Expand Down
15 changes: 2 additions & 13 deletions __tests__/__snapshots__/check-fixtures.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ exports[`linting javascript.js fixture matches snapshot 1`] = `
"endColumn": 14,
"endLine": 14,
"line": 14,
"message": "'y' is defined but never used.",
"message": "'y' is defined but never used. Allowed unused args must match /^_/u.",
"messageId": "unusedVar",
"nodeType": "Identifier",
"ruleId": "no-unused-vars",
Expand Down Expand Up @@ -259,7 +259,7 @@ exports[`linting typescript.ts fixture matches snapshot 1`] = `
"endColumn": 61,
"endLine": 3,
"line": 3,
"message": "'three' is defined but never used.",
"message": "'three' is defined but never used. Allowed unused args must match /^_/u.",
"messageId": "unusedVar",
"nodeType": "Identifier",
"ruleId": "@typescript-eslint/no-unused-vars",
Expand Down Expand Up @@ -369,16 +369,5 @@ exports[`linting typescript.ts fixture matches snapshot 1`] = `
"ruleId": "@typescript-eslint/no-shadow",
"severity": 2,
},
{
"column": 49,
"endColumn": 54,
"endLine": 31,
"line": 31,
"message": "'value' is defined but never used.",
"messageId": "unusedVar",
"nodeType": "Identifier",
"ruleId": "@typescript-eslint/no-unused-vars",
"severity": 2,
},
]
`;
9 changes: 8 additions & 1 deletion configs/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,14 @@ module.exports = {

'no-unused-expressions': 'error',

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

'no-useless-computed-key': 'error',

Expand Down
13 changes: 10 additions & 3 deletions configs/typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ module.exports = {
// config, and is elevated to an error here.
'@typescript-eslint/no-explicit-any': 'error',

// Provide escape hatches around destructuring and arguments.
'@typescript-eslint/no-unused-vars': [
'error',
{
argsIgnorePattern: '^_',
destructuredArrayIgnorePattern: '^_',
ignoreRestSiblings: true,
},
],

// Disable some rules that TypeScript handles and are also a Performance
// issue. See:
// https://github.com/typescript-eslint/typescript-eslint/blob/main/docs/linting/troubleshooting/Performance.md#eslint-plugin-import
Expand All @@ -43,9 +53,6 @@ module.exports = {
'@typescript-eslint/no-shadow': 'error',
'import/no-duplicates': 'error',

// Handled by TS itself.
'no-unused-vars': 'off',

// Empty classes are allowed if they are accompanied by a decorator.
// This is common in frameworks such as Angular / nest.js.
'@typescript-eslint/no-extraneous-class': [
Expand Down

0 comments on commit 7cd92a5

Please sign in to comment.