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
Rule proposal: prefer-set-has
#495
Comments
@fisker your would need to know that the array is never used anywhere else. Maybe items are pushed on laster that will have duplicate values. |
@yakov116 Yes, need check all references only called |
👍
I don't think it could consider I think this would be a useful rule, but I don't think it should be auto-fixable. |
Accepted |
@sindresorhus Why do you think it should not auto-fixable? I've made a prototype works fine with auto-fix. |
I guess if you can confidently check all references, it's fine. |
What would be the limitations of this rule? Say a external API passes a |
@silverwind I'm going to make it only work on Update: I didn't exclude Pass import externalArray from './some-where';
const array = externalArray;
if (array.includes('foo')) {} Fail import externalArray from './some-where';
const array = [...externalArray]; // `array` check result can't be effected by modifying `externalArray`
if (array.includes('foo')) {} |
I also wonder for cases where I have a small |
You can alway use |
Yeah of course. I generally try to avoid using |
Enforce use
Set
for existence check overArray#includes
.Fail
Pass
This rule might should not fail on this
Maybe only check variables and check references. Also perhaps the rule name
prefer-set-has
?real world case:
eslint-plugin-unicorn/rules/prefer-node-append.js
Lines 6 to 17 in d638e54
The text was updated successfully, but these errors were encountered: