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 prefer-array-includes rule #1062

Conversation

Fabrice-TIERCELIN
Copy link
Contributor

Add prefer-array-includes rule

I didn't write the snapshot test as I don't know how to get the file .js.snap.

Fixes #1058

Add `prefer-array-includes` rule
@yakov116
Copy link
Contributor

Update/create snapshot, use npx ava -u or npx ava test/xxxx.js -u.

Originally posted by @fisker in #1059 (comment)

@fisker
Copy link
Collaborator

fisker commented Jan 25, 2021

@Fabrice-TIERCELIN Have you seen this? And we can't copy so many lines from prefer-array-index-of.js, please reuse them.

Add tests
@Fabrice-TIERCELIN
Copy link
Contributor Author

Update/create snapshot, use npx ava -u or npx ava test/xxxx.js -u.

Originally posted by @fisker in #1059 (comment)

I will do this.

@fisker
Copy link
Collaborator

fisker commented Feb 8, 2021

I really don't understand what are you doing, these two points in this comment #1062 (comment), did you missed or is there something you don't understand?

@Fabrice-TIERCELIN
Copy link
Contributor Author

Fabrice-TIERCELIN commented Feb 8, 2021

I don't have handled this yet.

@Fabrice-TIERCELIN Fabrice-TIERCELIN marked this pull request as draft February 9, 2021 05:09
@Fabrice-TIERCELIN
Copy link
Contributor Author

OK, so I have looked at prefer-includes. Here is how I see the situation and then you will tell me what you decide to do.

No common code: One rule analyzes the inner code of a function and the other rule analyzes the outter code around a function in order that they do not share any code. So they can't be merged. They can only be put together.

No big process: Although they produce the same result with the same function includes(), the both rules are independent and unrelated. Let's imagine a case where a rule converts A to B and another rule converts B to C. So let's create a big process that converts A to C. Actually, we have a rule that converts A to C and a rule that converts B to C. So there is no point to merge.

✔️Simpler for the user: It's an "All in one" for the user. So when the user has to select the rules them wants, it's faster and simpler to choose.

You can decide what you want. It's only a point of view. If you want me to merge the rules, I'm OK. It's up to you. Tell me what you want.

@fisker
Copy link
Collaborator

fisker commented Feb 9, 2021

Extract code from prefer-array-index-of.js to a function in a shared file, call that function, return selector, listener, messages etc. Use them to create prefer-array-index-of rule.

Call that function with different method and replacement, add selector, listener, messages to prefer-include.

Do the same with tests(we don't even need write new tests, we can use the same one).

@Fabrice-TIERCELIN
Copy link
Contributor Author

Have you got a good code example?

@fisker
Copy link
Collaborator

fisker commented Feb 9, 2021

Do you want me do it? Won't take long.

@Fabrice-TIERCELIN
Copy link
Contributor Author

Either you give an example, or you do it. As you prefer. It will give me an example for the future features :)

@Fabrice-TIERCELIN Fabrice-TIERCELIN marked this pull request as ready for review February 9, 2021 07:23
@fisker
Copy link
Collaborator

fisker commented Feb 9, 2021

Check #1097

@fisker
Copy link
Collaborator

fisker commented Feb 9, 2021

@Fabrice-TIERCELIN Better check commits one by one, you'll understand how it's done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rule proposal: prefer-array-includes
3 participants