-
-
Notifications
You must be signed in to change notification settings - Fork 456
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
Stricter ordering of imports #456
Comments
This repo includes perfectionist, but you have to enable the rules manually. For example: {
name: 'my-global-rules',
rules: {
'import/order': 'off', // handled by perfectionist
'sort-imports': 'off', // handled by perfectionist
'perfectionist/sort-imports': 'error',
'perfectionist/sort-named-imports': 'error',
'perfectionist/sort-exports': 'error',
},
} I don't know how it compares to |
Thanks for the reminder. This should also be an option. There is no need to introduce additional plug-ins now. |
Would you share some examples of the result of reach rule? To me, the current state seems to work fine. |
I don't quite remember the details, but there were scenarios where the vanilla sort rules would not handle, whereas the alternative rules from perfectionist was able to handle. It's been a while, but I think this was my main issue with it: import-js/eslint-plugin-import#1787 |
Close as it may not be a good idea. If you want it, you can try to use eslint-plugin-perfectionist or eslint-plugin-simple-import-sort. Example of how to use eslint-plugin-simple-import-sort: import antfu from '@antfu/eslint-config'
import simpleImportSort from 'eslint-plugin-simple-import-sort'
export default antfu(
{},
{
plugins: {
'simple-import-sort': simpleImportSort,
},
rules: {
'import/order': 'off',
'sort-imports': 'off',
'simple-import-sort/imports': 'error',
'simple-import-sort/exports': 'error',
},
},
) |
Hoping maybe this will help someone out who like me wants to use perfectionist but didn't understand why the above config didn't do much. The default perfectionist sort-imports doesn't define any groups. So my config pulls in the rules from the natural sort config. https://gist.github.com/JohnCampionJr/a082f8967dd6341c41d923ad8502e999 |
@antfu Would you be amenable to a PR adding an option to enable import sorting by perfectionist? Basically make this available by option (could be set to alpha, natural or line length) per perfectionist settings
|
My approach is to install perfectionist separately and then use its recommend rules like this: import antfu from '@antfu/eslint-config'
import perfectionist from 'eslint-plugin-perfectionist'
export default antfu(
// perfectionist
{
rules: {
'import/order': 'off',
...perfectionist.configs['recommended-natural'].rules,
},
},
) |
Clear and concise description of the problem
In some cases, users may cause the ordering of imports to change, either through manual adjustment or the editor's
Organize imports
feature. The current sorting rulesimport/order
andsort-imports
are not enough to unify the sorting style, which is unstable for git diff.I am willing to submit a pull request for this change.
Suggested solution
Bring in eslint-plugin-simple-import-sort.
Alternative
Additional context
Validations
The text was updated successfully, but these errors were encountered: