Replies: 4 comments 3 replies
-
My vote is on integrating it as part of the formatter.
Doesn't that apply anyway, whether it's part of the formatter, the linter, or a separate command? Configuration for it could be something like this {
"formatter": {
"//": "disabled",
"organizeImports": false,
"//": "enabled with default config",
"organizeImports": true,
"//": "enabled with custom config",
"organizeImports": { ... },
}, |
Beta Was this translation helpful? Give feedback.
-
Could you please expand on this? Why would the feature be split in two? I think sorting imports in JavaScript is not necessarily something related to the formatter, I would say it depends on where a developer comes from. For example, I come from some experience where sorting imports is part of a linter/analyzer: https://github.com/lydell/eslint-plugin-simple-import-sort I also come from an experience where the order of the imports matters, for example, when using webpack, CSS modules, and importing CSS inside components. Very often, webpack couldn't "guess" the correct order of CSS when bundling for production (this problem might not exist inside rome). I would personally prefer having the sorting under the formatter umbrella, but ultimately, I think the safest bet, in the long run, is to have it under the analyzer ( Here are some of the motivations:
As for the configuration, I think it needs to go under the {
"javascript": {
"organizeImports": {}
}
} I don't know if the imports should go under a lint rule... I don't have strong feelings. But I would prefer to have it a separate task of the rome check --organize-imports-enabled=false {
"organizeImports": {
"enabled": false
},
"javascript": {
"organizeImports": {
// I am inventing stuff here
"order": ["foo", "bar", "etc."]
}
},
"css": {
"organizeImports": {
// I am inventing stuff here
"type": "natural"
}
}
} This is mainly because we already know that |
Beta Was this translation helpful? Give feedback.
-
this is useful, I would run this in addition part of my prettier checks (but ONLY this part of the Rome cli formatting-wise, I would use prettier for everything else), as the prettier 3rd party sort imports plugin isn't reliable enough. |
Beta Was this translation helpful? Give feedback.
-
https://github.com/trivago/prettier-plugin-sort-imports Here are the things! I'm pretty satisfied with this lib. When using monorepo, our import looks messy after file scale-up business logic with multiple imported packages. So this lib is like the saver for us to format something we want! The first stage should be the Js, ts, and TSX file extensions.
@leops Hope you guys add this feature to the backlog soon 😆. Always favor ROME! |
Beta Was this translation helpful? Give feedback.
-
Starting with version 11.0.0, Rome will ship with an experimental imports sorting feature. For the initial implementation this new feature is only accessible through the "Organize Imports" code actions in editors, but we want to eventually make it available through the CLI. Exactly how that will works is still open to discussion though as all the ways we could perform this integration have pros and cons:
Run in
rome format
Pros
Prettier has widely used plugins for sorting imports, making it likely most users would expect this action to run along with the formatter.
Cons
We've generally avoided introducing "side-effects" to the formatter, but re-ordering imports can change the semantics of the code.
Run in
rome check
Pros
The "Organize Imports" action is implemented through the same Analyzer infrastructure as the linter, so the integration effort should be minimal. If we go in this direction we may even turn the action into a
style/useSortedImports
lint rule and integrate it fully into the linter.Cons
Users might find this confusing since we would have both a linter and formatter, with the feature of "formatting" split between the two. Specifically for the point of "turning the action into a full lint rule", this would mean the in-editor "Organize Imports" action would stop working it the linter (or rule) is disabled. If we don't go with a lint rule, this also asks the question of where we should put the configuration for the action in the
rome.json
file (since it wouldn't make sense to put it under thelinter
section).Run in
rome sort-imports
This new command would also be run by
rome ci
, in the same wayformat
andcheck
are alreadyPros
This clearly separates the "Imports Sorting" feature from the "Formatting" and "Linting" on the CLI, in the same way they are separated in the editor and internally in the Rome codebase.
Cons
Introduce a very specialized command to the CLI that's possibly hard to discover and requires special handling to integrate into existing workflows. Doing it this way would also probably warrant creating a
sortImports
section at the root of therome.json
file for configuring this command, which once again seems overly specialized and hard to discover.Beta Was this translation helpful? Give feedback.
All reactions