Comments (12)
@keemor Hi!
You need to put everything in the same array, like this:
{
"plugins": ["simple-import-sort"],
"extends": "react-app",
"rules": {
"simple-import-sort/sort": [
"warn",
{
"groups": [
[
// Packages. `react` related packages come first.
"^react",
"^@?\\w",
// Internal packages.
"^(components|modules|utils)(/.*|$)",
// Side effect imports.
"^\\u0000",
// Parent imports. Put `..` last.
"^\\.\\.(?!/?$)", "^\\.\\./?$",
// Other relative imports. Put same-folder imports and `.` last.
"^\\./(?=.*/)(?!/?$)", "^\\.(?!/?$)", "^\\./?$",
// Style imports.
"^.+\\.s?css$"
]
]
}
],
"import/first": "warn",
"import/newline-after-import": "warn",
"import/no-duplicates": "warn",
}
}
(I didn’t test that before posting, so forgive me if I made a mistake 🙏)
from eslint-plugin-simple-import-sort.
This is now possible in v5.0.0 using custom grouping.
For example:
{
"rules": {
"simple-import-sort/imports": [
"error",
{
"groups": [["^\\u0000", "^@?\\w", "^[^.]", "^\\."]]
}
]
}
}
(Edited for newer version based on #25 (comment))
from eslint-plugin-simple-import-sort.
Thanks for the reply. OK, I undetstand plugin design.
I want to remove line breaks between all import statements. This is my personal opinion because I usually don't put a newline between import statements. So, not important. But I would be happy if option was provided like https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/order.md#newlines-between-ignorealwaysalways-and-inside-groupsnever.
Thank you for your polite response!
from eslint-plugin-simple-import-sort.
Hi,
Having this option would be nice for people using typescript.
Migrating from tslint to eslint, this plugin is the only one that can behave like tslint ordered-imports rule... except that tslint default rule configuration disables new line between groups.
Would be great to be able to have the same configuration as tslint.
from eslint-plugin-simple-import-sort.
This is now possible in v5.0.0 using custom grouping.
For example:
{ "rules": { "simple-import-sort/sort": [ "error", { "groups": [["^\\u0000", "^@?\\w", "^[^.]", "^\\."]] } ] } }
Just to expand on this.
For future visitors, "simple-import-sort/sort" will give error (above v6.0.0)
Definition for rule 'simple-import-sort/sort' was not found.eslint(simple-import-sort/sort)
Replace the "simple-import-sort/sort" with "simple-import-sort/imports", like this
"simple-import-sort/imports": [
"error",
{
"groups": [["^\\u0000", "^@?\\w", "^[^.]", "^\\."]]
}
]
It's also mentioned in the readme here.
Thanks.
from eslint-plugin-simple-import-sort.
I have a thing coming up that will allow customizing this.
from eslint-plugin-simple-import-sort.
This feature of grouping is great but will be nice to make an example on the documentation because it was clear only after searching newline
from eslint-plugin-simple-import-sort.
Hi!
This plugin has no options by design. There is currently no way of removing that newline.
Would you like to tell me more about this unwanted line break? Do you want no linebreaks at all between imports? Or just between those two groups that you showed? Why is it important? Etc.
from eslint-plugin-simple-import-sort.
@hrougier https://palantir.github.io/tslint/rules/ordered-imports/
Groups of imports are delineated by blank lines.
But you say the default is having no blank lines between groups?
from eslint-plugin-simple-import-sort.
But you say the default is having no blank lines between groups?
That's it, blank lines between groups is an option which is not enabled by default:
"rules": {
"ordered-imports": true // rule activated, no blank lines
}
"rules": {
"ordered-imports": [true, { "grouped-imports": true }] // to enable blank lines
}
from eslint-plugin-simple-import-sort.
Ok. I guess their docs is a little misleading, then. I have an idea for this that I want to play with this week.
from eslint-plugin-simple-import-sort.
Hi @santomegonzalo, @lydell :)
How to remove empty lines between groups? My .eslint looks like this:
{
"plugins": ["simple-import-sort"],
"extends": "react-app",
"rules": {
"simple-import-sort/sort": [
"warn",
{
"groups": [
// Packages. `react` related packages come first.
["^react", "^@?\\w"],
// Internal packages.
["^(components|modules|utils)(/.*|$)"],
// Side effect imports.
["^\\u0000"],
// Parent imports. Put `..` last.
["^\\.\\.(?!/?$)", "^\\.\\./?$"],
// Other relative imports. Put same-folder imports and `.` last.
["^\\./(?=.*/)(?!/?$)", "^\\.(?!/?$)", "^\\./?$"],
// Style imports.
["^.+\\.s?css$"]
]
}
],
"import/first": "warn",
"import/newline-after-import": "warn",
"import/no-duplicates": "warn",
}
}
from eslint-plugin-simple-import-sort.
Related Issues (20)
- How can I make imports with a capitalized first letter always come first? HOT 2
- Question: relative side-effect imports are placed before relative imports HOT 2
- Question: how to approach the workaround for padding-line-between-statements? HOT 2
- Please update your docs HOT 2
- Named imports with `as` aren't sure where to go HOT 2
- Using without new lines between groups HOT 2
- Error with aliased imports and eslint-plugin-import HOT 1
- Support for namespace imports HOT 8
- Prepare for ESLint 9: Deprecated methods
- sorted import specifiers missing space HOT 2
- how to make side effect always be top HOT 2
- I thought library imports were supposed to come before relative imports? HOT 4
- Error: Run autofix to sort these imports! HOT 7
- Duplicate imports are not being removed HOT 1
- Conflict between eslint-plugin-simple-import-sort and esbenp.prettier-vscode HOT 2
- TypeError: parentNode.body is not iterable in v11 HOT 6
- Import in group despite not being matched by regex expression HOT 2
- What is the difference vs eslint-plugin-import HOT 1
- Add TypeScript types HOT 7
- Explore configuration with real regex instead of strings
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from eslint-plugin-simple-import-sort.