-
Notifications
You must be signed in to change notification settings - Fork 53
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
Sort destructured props #12138
Comments
On the contrary, this rule enforces unnecessary thinking in that the coder has to alphabetize the properties 😞 I would rather we didn't do this. Editors are powerful these days (finding variables is easy) so I'm not sure why we need it. However, I understand that people other than me prefer to see things alphabetized so if this new rule minimizes those comments in code reviews then I'm fine with it. Carry on. |
I don't know where this comes from to be honest, but I got a comment every time I was not applying this rule on props, imported symbols, imports etc. (and, I started contributing on this project almost a year ago). Since this was the only comment I got every time and Prettier could not help me fix it, I wrote a fixable rule to automate such changes, because you're right: that's not something people have to do. There were basically two options to get rid of those comments, either a tool or we stop leaving such comments. I guess I bet on the wrong option 😋 |
Oh, it's fixable? That changes things. I am still waiting for someone to tell me why we need to alphabetize destructured variables but if they can convince me then I guess we can add another pre-PR script like |
haha yes, I would have never done the changes myself 🤣
We tend to sort everything for some reasons, I guess main reasons are: consistency and easier to find a specific "thing" (prop, react prop, variable, import, etc.). I tend to like the idea of having vars/props starting with an underscore first because those are vars we use for "dependency injection" usually (so I can skip them when I want to find the props I am supposed to pass in the production code). Nothing super fancy though, and I can understand the fear of maintenance burden.
|
So, I think we can close this issue and mark it as wontfix. The eslint rule in https://github.com/mozilla/eslint-plugin-amo#sort-destructured-props is not enabled by default (i.e. not part of the recommended rules), but still there if we ever want to re-open this issue. FTR, the eslint rule automatically fixes the code, there is not need to manually sort the props. |
This issue is a follow-up to some comments in mozilla/addons-frontend#5652. When upgrading to React Router v4, most of the props have been sorted but some might have been missed, and we did not have an ESLint rule for that. The ESLint rule has since been created: https://github.com/mozilla/eslint-plugin-amo#sort-destructured-props.
We (try to) enforce sorted destructured properties in function arguments and destructured assignements:
This rule allows us to always know where to insert a new property, thus avoiding unnecessary thinking. We follow the "natural sort order":
The ESLint rule will probably try to re-order the list of props as follows:
But another ESLint rule will throw an error because
userId
is used before it is declared. In this case, it is best to disable theamo/sort-destructured-props
props:The text was updated successfully, but these errors were encountered: