-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
[import/order] Force sort order of certain packages within "external" group #1665
Comments
At @blockstack we'd love this feature too. |
You should be able to add |
@ljharb Thanks for the response. As far as I can tell, the The module.exports = {
rules: {
'import/order': ['error', {
groups: ['builtin', 'external', 'internal'],
pathGroups: [
{
pattern: 'react', // this doesn't seem to work because react is `external`
group: 'external',
position: 'before',
},
],
'newlines-between': 'always',
alphabetize: {
order: 'asc',
caseInsensitive: true,
},
}],
} |
this worked for me
|
Thanks @egemon! Your solution worked for me. I was missing the Here's configuration that forces // in .eslintrc.js
module.exports = {
rules: {
'import/order': ['error', {
groups: ['builtin', 'external', 'internal'],
pathGroups: [
{
pattern: 'react',
group: 'external',
position: 'before',
},
],
pathGroupsExcludedImportTypes: [
'react',
],
'newlines-between': 'always',
alphabetize: {
order: 'asc',
caseInsensitive: true,
},
}],
} I think there's an opportunity to improve the documentation for the |
Glad you figured it out :-) so is this resolved? Happy to reopen if not. |
@ljharb it is. I think I should open PR and issue to add smth like that into documentation? |
Thanks, that'd be great. |
@ljharb Yes, this is resolved. Thanks! |
We're using the
import/order
rule to enforce a convention in module imports. Here's how theimport/order
rule is currently configured in our project.This will result in the following import conventions:
All is well and good, except that our team's convention is to import
React
first when a module has React components. Therefore, the example above would become:Is it possible to achieve this desired sort order using the
import/order
rule? I was a bit confused by the documentation of thepathGroups
andpathGroupsExcludedImportTypes
and I wasn't sure if these options could be used to achieve this result. Thanks in advance for the help and keep up the great work on this plugin!The text was updated successfully, but these errors were encountered: