You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The matching system of organizeImports is by nature ordered.
In the following example, the second matcher is useless because all import type are matched in the first group.
When I implemented organizeImports, I chose this system for several reasons:
Once you know the matching is ordered, it is easy to predict how imports are sorted
Implementation-wise it is pretty efficient because you can stop at the first matching group for each import.
Unfortunately, the use of these systems revealed two main issues:
Users want to express complex sorting constraints. This leads to very verbose configuration as demonstrated here or there.
Some users are confused by the in-order nature of our matching system.
Addressing (2) could require a new matching system with a new semantic. Some import sorters use a more complex system based on selector precedences (for example type has precedence on source) and matching specificity (for example a matcher with two type and source is more specific than a matcher with only type). I am really not fond of the matching by specificity. However, I could be open to introduce some selector precedence.
For example, it could make sense to make type and the future kind selectors have a higher precedence than source.
So the two examples at the start of this post could be identical in terms of matching behavior, because { "type": true, source: ":PACKAGE:" } got matched before { source: ":PACKAGE:" }.
I am really hesitant to introduce a such system because this makes things harder to explain.
This is why I thought about a more explicit approach: we could make matching priority explicit by introducing a priority field.
So the first example could be written as follows:
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
The matching system of
organizeImportsis by nature ordered.In the following example, the second matcher is useless because all
import typeare matched in the first group.In order to be effective, the first group has to exclude
import type:When I implemented
organizeImports, I chose this system for several reasons:Unfortunately, the use of these systems revealed two main issues:
Addressing (2) could require a new matching system with a new semantic. Some import sorters use a more complex system based on selector precedences (for example
typehas precedence onsource) and matching specificity (for example a matcher with twotypeandsourceis more specific than a matcher with onlytype). I am really not fond of the matching by specificity. However, I could be open to introduce some selector precedence.For example, it could make sense to make
typeand the futurekindselectors have a higher precedence thansource.So the two examples at the start of this post could be identical in terms of matching behavior, because
{ "type": true, source: ":PACKAGE:" }got matched before{ source: ":PACKAGE:" }.I am really hesitant to introduce a such system because this makes things harder to explain.
This is why I thought about a more explicit approach: we could make matching priority explicit by introducing a
priorityfield.So the first example could be written as follows:
priorityis like a CSS'szindex. By default, it is set to0: higher it is, higher the matcher priority is.We could allow negative priorities.
Note that this explicit system doesn't address (2) (user confusion). However, it could reduce the verbosity of complex configurations.
Beta Was this translation helpful? Give feedback.
All reactions