Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

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

Closed
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
@kachkaev

Description

@kachkaev

Repro

  1. Enable the rule (seedocs)

  2. Either

    • Create a js file where numbers or strings are added
    exportconstf=(a,b)=>a+b;
    • Create a ts file, where arguments of type any are added
    exportconstf=(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 typenumber being added to a variable of known typestring). Errors in js files are especially unfortunate.

Would it be possible to optionally allowany 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

packageversion
@typescript-eslint/eslint-plugin1.5.0
@typescript-eslint/parser1.5.0
TypeScript3.3.4000
ESLint5.15.3
node10.15.2
yarn1.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


      [8]ページ先頭

      ©2009-2025 Movatter.jp