Closed
Description
Repro
-
Enable the rule (see docs)
-
Either
- Create a js file where numbers or strings are added
export const f = (a, b) => a + b;
- Create a ts file, where arguments of type any are added
export const f = (a: any, b: any) => a + b;
-
Observe the following error in each case:
Operands of '+' operation must either be both strings or both numbers. eslint(@typescript-eslint/restrict-plus-operands)
.eslintrc.js
{
"rules": {
"@typescript-eslint/restrict-plus-operands": "error"
}
}
Expected Result
The current result is fine, however too much strictness out of which you cannot opt out may get the rule challenging to use in existing codebases. I just tried enabling it in a monorepo with mixed js and ts code and got hundreds of errors. I understand the value behind this, just find it impossible to start using the rule to catch real issues (variable of known type number
being added to a variable of known type string
). Errors in js files are especially unfortunate.
Would it be possible to optionally allow any
in the rule?
"@typescript-eslint/restrict-plus-operands": ["error", { allowAny: true }]
or even
"@typescript-eslint/restrict-plus-operands": ["error", { skipJs: true }]
"@typescript-eslint/restrict-plus-operands": ["error", { allowAny: true, skipJs: true }]
Or should js files just be always skipped?
Versions
package | version |
---|---|
@typescript-eslint/eslint-plugin |
1.5.0 |
@typescript-eslint/parser |
1.5.0 |
TypeScript |
3.3.4000 |
ESLint |
5.15.3 |
node |
10.15.2 |
yarn |
1.13.0 |
Metadata
Metadata
Assignees
Labels
Go ahead, send a pull request that resolves this issueGo ahead, send a pull request that resolves this issueNew rule option for an existing eslint-plugin ruleNew rule option for an existing eslint-plugin ruleGood for newcomersGood for newcomersIssues related to @typescript-eslint/eslint-pluginIssues related to @typescript-eslint/eslint-plugin