Skip to content
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

Add rule S4125: "typeof" expressions should only be compared to valid values #625

Closed
fmallet opened this issue Jul 27, 2017 · 4 comments · Fixed by #3166
Closed

Add rule S4125: "typeof" expressions should only be compared to valid values #625

fmallet opened this issue Jul 27, 2017 · 4 comments · Fixed by #3166
Assignees
Labels
topic: quality type: new rule Creating a new rule not existing before
Milestone

Comments

@fmallet
Copy link
Contributor

fmallet commented Jul 27, 2017

Implements RSPEC-4125)

@fmallet fmallet added this to the 3.2 milestone Jul 27, 2017
@vilchik-elena vilchik-elena removed this from the 3.2 milestone Sep 12, 2017
@vilchik-elena
Copy link
Contributor

vilchik-elena commented Aug 30, 2018

ESLint rule key valid-typeof

@vilchik-elena vilchik-elena added type: new rule Creating a new rule not existing before and removed rule labels Jul 1, 2020
@vilchik-elena vilchik-elena added this to the New Rules milestone Apr 25, 2022
@vilchik-elena vilchik-elena modified the milestones: New Rules, 9.4 Jun 7, 2022
@ilia-kebets-sonarsource ilia-kebets-sonarsource changed the title Rule: "typeof" expressions should only be compared to valid values Add rule S4125: "typeof" expressions should only be compared to valid values Jun 7, 2022
@ilia-kebets-sonarsource
Copy link
Contributor

Ref to ESLint rule: https://eslint.org/docs/2.0.0/rules/valid-typeof

@ilia-kebets-sonarsource
Copy link
Contributor

ilia-kebets-sonarsource commented Jun 7, 2022

TypeScript compiler complains when typeof is compared to the wrong literal, so there is no sense for us to have this rule enabled for TypeScript.

Message from typescript compiler:

This condition will always return 'false' since the types '"string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"' and '"Number"' have no overlap.ts(2367)

@vilchik-elena
Copy link
Contributor

@ilia-kebets-sonarsource indeed, it seems this rule does not make sense for TS as such code would be invalid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: quality type: new rule Creating a new rule not existing before
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants