Skip to content

[restrict-plus-operands] Allowing any for summands #386

Closed
@kachkaev

Description

@kachkaev

Repro

  1. Enable the rule (see docs)

  2. 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;
  3. 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

/cc @armano2 (author of #70)

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issueenhancement: plugin rule optionNew rule option for an existing eslint-plugin rulegood first issueGood for newcomerspackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions