Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Copy link
Copy link
Closed
@kachkaev

Description

@kachkaev
Issue body actions

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 issueGo ahead, send a pull request that resolves this issueenhancement: plugin rule optionNew rule option for an existing eslint-plugin ruleNew rule option for an existing eslint-plugin rulegood first issueGood for newcomersGood for newcomerspackage: eslint-pluginIssues related to @typescript-eslint/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

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.