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

Rule suggestion: Suggest sortBy if using orderBy with just asc #190

Closed
garyking opened this issue Nov 27, 2018 · 4 comments
Closed

Rule suggestion: Suggest sortBy if using orderBy with just asc #190

garyking opened this issue Nov 27, 2018 · 4 comments

Comments

@garyking
Copy link
Contributor

Would it be a good rule idea to suggest to use sortBy if using orderBy with just asc?

So _.orderBy(arr, 'text', 'asc') would suggest to be replaced by _.sortBy(arr, 'text') instead, or _.orderBy(arr, ['a', 'b'], ['asc', 'asc']) would suggest to be replaced by _.sortBy(arr, ['a', 'b']) instead.

@ganimomer
Copy link
Contributor

ganimomer commented Nov 27, 2018

Thanks for the suggestion!
I'm not sure creating an opinionated rule here.
Some people might prefer the opposite to be more explicit, or even to use _.orderBy without the second parameter, which also works. (e.g. _.orderBy(arr, 'text') does the exact same thing as _.sortBy.
In these cases, what's usually done is a rule that accepts a parameter, and the recommended config is opinionated. For example, the chaining rule can either enforce that chains are never used, or that they're always used whenever there's a nested call. (In this case, IIRC the recommended has even actually changed over time).
Maybe a rule called collection-ordering that accepts a first parameter that's either sortBy, orderBy, or orderByExplicit, with the default (and the setting in the recommended config) being sortBy, and enforces that all cases are according to it.
@garyking What do you think?

@garyking
Copy link
Contributor Author

That sounds good! The idea of using _.orderBy to completely replace _.sortBy by some people is actually interesting, and I might adopt that in my own code, since it makes it easier to change if necessary (by simply adding a third parameter to explicitly specify sort options), and to search among projects.

@ganimomer ganimomer self-assigned this Nov 28, 2018
@ganimomer
Copy link
Contributor

Fixed in v5.0.0.

@garyking
Copy link
Contributor Author

Just a note, that the rule isn't listed in the readme.

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

No branches or pull requests

2 participants