-
Notifications
You must be signed in to change notification settings - Fork 394
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
app: sort es6 imports #789
Comments
@jorgeorpinel 👍 let's try. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@jorgeorpinel having a single standard is great, but not every criteria can be considered reasonable. I agree with @iAdramelk that sorting by name == random and it makes it hard to work with (read and understand code), hard to maintain it manually, etc. |
This comment has been minimized.
This comment has been minimized.
p.s. actually I checked and fortunately, the commits that changed this in that big PR are consecutive: 43303c0...b633778 so it may be possible to revert with |
Yes
I would expect them to be split into block - third party libraries as a separate block and always comes first or last (?), internal imports spilt into components and everything else at least (utils, constants). Not sure if we need to split anything further. @iAdramelk should have a better idea. Multiple members from the same component - probably one import. |
it should be easy to just remove those comments |
About my problems. I will add here an example of how I usually sort dependencies in my projects (it's slightly different from Just resorting example above. Current:
Preferred by me:
There are a few separate groups. Components inside the group are sorted by full import path and not the file name. When I open such file I can understand a few things from the start:
Then I edit this file I:
With a new structure I can't do any of this stuff. Also, this is my first time seeing it in the real project, and none of the popular eslint presets (like airbnb or standard) are using it, so I'm not sure if we can call it industry standard or best practice. |
@jorgeorpinel what have we decided on this? |
I vote for disabling that auto sort asap, reverting if possible some changes (does it make sense, will you be able to merge @iAdramelk ?), and keep rule in mind that Alex described while preserving reasonable sorting manually. As second-order task - check if there are better tools that can understand semantics and maintain a reasonable order. |
Sorry, haven't had time to get onto this yet but my plan is to revert indeed, and then play with the rule's settings to hopefully come up with an OK standard based on the desired criteria you guys have expressed. If it's getting in your way maybe change the rule to "warning" value in your branch for now @iAdramelk |
@jorgeorpinel my current problems is that I want to merge master into community page and it requires solving conflicts with this changes, and if we later revert this commits it will break code again, also I'm working on the new branch now, than will require moving all components to If you don't have time right now, do you mind that I revert them myself in master? |
Yeah no worries, thanks for reverting. OK sounds like ESLint To summarize, sounds like we would prefer to have groups:
Questions: @iAdramelk suggests to sort alphabetically but not based on the module name, rather on the import path. Why is this better Alex? Seems equally arbitrary. Why not forget about alphabetical order altogether and put the more important stuff or the things used first in the code (like React and Next) in the top of the group?
Sorry @shcheklein, didn't get that. What do you mean "spilt into components" and "everything else at least"?
I see 4 groups in your example Alex. The last 2 groups (which only have 1 statement each) don't look like obviously different from the 2nd group with all the components.
Well, with an automatic tool you don't have to worry about this. You can put it anywhere and it gets moved to the right place 😉 but I haven't found any other tool. Will research some more. |
I found renke/import-sort import-sort-cli and a bunch other similar ones on GH but they're all based onthe ESLint rule. So seems like we would have to do all this manually 🙁 |
@jorgeorpinel close this for now then? |
I implemented this for the commonjs style files ( TBH I think manual sorting it's to "labor-intensive". I don't want to go sort the other 36 files with import nor do I think people will remember to update the sort order when something changes in each one. Just given that I would still prefer the ESLint rule. But anyway, should we just close this ticket and leave things as they are now? |
Just noticed that @shcheklein. Yes. |
Currently there's not much order in js file imports. Some files group them with comments or spaces in between e.g.
dvc.org/pages/doc.js
Lines 3 to 24 in 9c8cc54
or
dvc.org/src/Documentation/SidebarMenu/SidebarMenu.js
Lines 1 to 14 in 9c8cc54
I suggest we remove all these comments, which don't really add any value, and apply this ESLint rule: https://eslint.org/docs/rules/sort-imports
The text was updated successfully, but these errors were encountered: