Skip to content

[restrict-plus-operands] Throws "this rule requires you to use @typescript-eslint/parser" #130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
scottohara opened this issue Jan 23, 2019 · 5 comments · Fixed by #132
Closed
Labels
package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look

Comments

@scottohara
Copy link
Contributor

Repro

{
  "parser": "@typescript-eslint/parser",
  "plugins": ["@typescript-eslint"],
  "rules": {
    "@typescript-eslint/restrict-plus-operands": "error"
  }
}
const a: string = '1.1' + 1;

Expected Result

Operands of '+' operation must either be both strings or both numbers

Actual Result

Error: Error while loading rule '@typescript-eslint/restrict-plus-operands': This rule requires you to use `@typescript-eslint/parser`.
    at Object.exports.getParserServices.context [as getParserServices]

Additional Info

Versions

package version
@typescript-eslint/eslint-plugin 1.1.0
@typescript-eslint/parser 1.1.0
TypeScript 3.2.1
ESLint 5.11.1
node 11.5.0
npm 6.5.0
@scottohara scottohara added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels Jan 23, 2019
@JamesHenry
Copy link
Member

Sorry for the confusion, this is a genuine error - but with the wrong message.

In order to use rules which require type information, you have to provide a reference to your tsconfig.json.

I have opened #132 to address this. I'm afraid with the huge migration of everything, we haven't got around to improving the docs too much yet.

@scottohara
Copy link
Contributor Author

Thanks @JamesHenry.

Just an FYI, re: performance...

In a project containing ~200 x *.ts files, I recorded some timings for a full linting run before/after enabling this rule and adding parserOptions.project: <path to tsconfig.json>:

Rule off

"rules": {
  "restrict-plus-operands": "off"
}
real  0m10.094s
user  0m16.304s
sys	  0m0.720s

Rule off + parserOptions.project set

"parserOptions": {
  "project": "./tsconfig.json"
},
"rules": {
  "restrict-plus-operands": "off"
}
real  0m54.436s
user  1m15.434s
sys   0m8.106s

Rule on

"parserOptions": {
  "project": "./tsconfig.json"
},
"rules": {
  "restrict-plus-operands": "error"
}
real  1m17.327s
user  1m42.875s
sys   0m9.295s

Simply setting parserOptions.project to point to my tsconfig.json caused the linting time to jump from ~16s to ~1m 15s (presumably setting this option causes tsc to run during parsing?).

Then with the restrict-plus-operands rule, the total run time goes to ~1m 42s.

This 6x slowdown may make it impractical for some large projects to enable this rule (or any future rules that rely on tsconfig.json reference being set).

@aboyton
Copy link
Contributor

aboyton commented Jan 23, 2019

Out of curiosity, how does it compare to TSLint for any rules that require type checking? c.f. #55

@JamesHenry
Copy link
Member

Tagging @uniqueiniquity

@uniqueiniquity
Copy link
Contributor

Hi @scottohara, thanks for sharing the perf numbers you're getting.
@aboyton, I'm in the process of writing a handful of semantic rules with the intent of doing a larger-scale perf comparison. In my experience so far, the two tools have been pretty comparable, but I haven't fully tested yet. Moving forward, I'm planning on iterating on the support for generating semantic information so we can get that perf hit down as much as we can. The current support is definitely a first cut.

@typescript-eslint typescript-eslint locked as resolved and limited conversation to collaborators Feb 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants