Skip to content

[no-var-requires] false negative when require statement includes a type cast #2125

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
adidahiya opened this issue May 29, 2020 · 1 comment · Fixed by #2139
Closed

[no-var-requires] false negative when require statement includes a type cast #2125

adidahiya opened this issue May 29, 2020 · 1 comment · Fixed by #2139
Labels
bug Something isn't working good first issue Good for newcomers package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@adidahiya
Copy link

adidahiya commented May 29, 2020

Repro

{
  "rules": {
    "@typescript-eslint/no-var-requires": "error",
  }
}
const myJson = require("./someFile.json") as MyJson;

(initially encountered in this PR)

Expected Result

lint error on this require statement, just like the TSLint rule

Actual Result

no error

Additional Info

easy enough to work around, since I can change the syntax and the rule will report the error as expected:

const myJson: MyJson = require("./someFile.json");

.. but nonetheless I think the rule should report an error in both cases.

Versions

package version
@typescript-eslint/eslint-plugin 3.0.1
@typescript-eslint/parser 3.0.1
TypeScript 3.9.3
ESLint 7.1.0
node 12.16.2
@adidahiya adidahiya added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels May 29, 2020
@adidahiya adidahiya changed the title [no-var-requires] false negative when require statement includes a cast [no-var-requires] false negative when require statement includes a type cast May 29, 2020
@adidahiya
Copy link
Author

adidahiya commented May 29, 2020

This also seems to produce a false negative when there is anything chained onto the require() statement, like:

const mySvg = require("raw-loader!./file.svg").default;

... which also diverges from the TSLint rule

@bradzacher bradzacher added bug Something isn't working good first issue Good for newcomers and removed triage Waiting for team members to take a look labels May 29, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 1, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working good first issue Good for newcomers package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
2 participants