-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Closed
Labels
duplicateThis issue or pull request already existsThis issue or pull request already existsenhancement: new plugin ruleNew rule request for eslint-pluginNew rule request for eslint-pluginpackage: eslint-pluginIssues related to @typescript-eslint/eslint-pluginIssues related to @typescript-eslint/eslint-plugin
Description
Before You File a Proposal Please Confirm You Have Done The Following...
- I have searched for related issues and found none that match my proposal.
- I have searched the current rule list and found no rules that match my proposal.
- I have read the FAQ and my problem is not listed.
My proposal is suitable for this project
- My proposal specifically checks TypeScript syntax, or it proposes a check that requires type information to be accurate.
- My proposal is not a "formatting rule"; meaning it does not just enforce how code is formatted (whitespace, brace placement, etc).
- I believe my proposal would be useful to the broader TypeScript community (meaning it is not a niche proposal).
Description
Checking for array membership using in
is a common new JS developer mistake - it looks like it should work but it does not since in
checks for properties, and array values are not properties.
Fail Cases
const arr = ['a', 'b', 'c'];
const inArray = 'a' in arr;
Pass Cases
const arr = ['a', 'b', 'c'];
const inArray = arr.includes('a');
Additional Info
There is a very similar https://typescript-eslint.io/rules/no-for-in-array rule for for-in
loops specifically
Metadata
Metadata
Assignees
Labels
duplicateThis issue or pull request already existsThis issue or pull request already existsenhancement: new plugin ruleNew rule request for eslint-pluginNew rule request for eslint-pluginpackage: eslint-pluginIssues related to @typescript-eslint/eslint-pluginIssues related to @typescript-eslint/eslint-plugin