-
-
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
Add extensions order support for import/order #1239
Comments
Would be perfect if we could add this feature. We have the same case with |
Would love to see this as well. |
I thought this could be accomplished with the "pathGroups": [
{
"pattern": "**/*.scss",
"group": "index",
"position": "after"
}
] But I can't seem to get this to work. |
After some experimenting, this seems to do the trick: "pathGroups": [
{
"pattern": "./*.scss",
"group": "sibling",
"position": "after"
}
] |
Im also stuck with it. |
"pathGroups": [
{
"pattern": "**/*.+(css|sass|less|scss|pcss|styl)",
"patternOptions": {"dot": true, "nocomment": true},
"group": "unknown",
"position": "after"
},
{
"pattern": "{.,..}/**/*.+(css|sass|less|scss|pcss|styl)",
"patternOptions": {"dot": true, "nocomment": true},
"group": "unknown",
"position": "after"
}
], Used 2 patterns to cover all cases |
Nice, I've been using the following pattern lately:
But I have some imports that start with This is frustrating |
|
Unfortunately this is a known problem of Minimatch. And the solution is ugly - list all possible "up" paths (1,2,3,4,5... levels up) |
To solve this, you can set {
pathGroups: [
{
pattern: '*.scss',
group: 'index',
patternOptions: { matchBase: true },
position: 'after'
]
} |
@MoradiDavijani This is amazing. You made my day ❤️ |
Doesn't work for me (typescript project)
expected
Any ideas? |
@yuri-sakharov you may also need to set up the import/extensions settings as described in the readme. |
@yuri-sakharov this is expected to work so. You faced a completely different issue. There are already several opened tickets for this https://github.com/benmosher/eslint-plugin-import/issues?q=is%3Aissue+is%3Aopen+side+effect+label%3A%22import%2Fexport+ordering%22+ |
@yuri-sakharov I was having trouble just like you with other solutions, such as with solutions by @constgen and @MoradiDavijani, which were helpful in solving the issue. After some toying around with it, I figured out that I had to set Once I did that, it started picking up on the unassigned imports (e.g. Here's my configuration: Eslint version: 7.31.0 Import orderimport './foo.scss';
import barModule from '../../barModule';
import bazModule from './bazModule'; ESLint configuration'import/order': [
// other config here
'pathGroups': [
{
pattern: '{.,..}/*\.scss', // same directory only
// pattern: '{.,..}/**/*\.scss' // same & outside directories (e.g. import '../foo/foo.scss')
group: 'object',
position: 'after'
}
],
'warnOnUnassignedImports': true
}
] |
@nickvirdenlegalshield getting the same issue. |
@nickvirdenlegalshield unfortunately |
In summary, to match one or more extensions, including unassigned imports: 'pathGroups': [
{
pattern: '*.{css,scss}',
patternOptions: {matchBase: true},
group: 'unknown',
position: 'after',
},
],
// no auto-fix
'warnOnUnassignedImports': true, |
It would be nice to order imports based on their extension. For our case, we want to leave all css modules imported at the end of the imports list
The text was updated successfully, but these errors were encountered: