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
Update: add fixer for sort-imports
#7535
Conversation
@not-an-aardvark, thanks for your PR! By analyzing the history of the files in this pull request, we identified @vitorbal, @cschuller and @mysticatea to be potential reviewers. |
LGTM |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also add a test where the imported bindings have line breaks between them?
}, | ||
{ | ||
code: "import /* a */ { /* b */ foo /* c */ , /* d */ bar /* e */ , /* f */ baz /* g */ , /* h */ } /* i */ from 'qux.js';", | ||
output: "import /* a */ { /* b */ bar /* c */ , /* d */ baz /* e */ , /* f */ foo /* g */ , /* h */ } /* i */ from 'qux.js';", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should be attempting to autofix if there are comments present. Chances are that the comments are somehow related to the bindings being imported, so keeping them in place while switching the order of the identifiers is confusing.
509572c
to
33ac719
Compare
LGTM |
That's a good point about comments, I hadn't thought of that.
|
What is the purpose of this pull request? (put an "X" next to item)
[ ] Documentation update
[ ] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[x] Add autofixing to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:
What changes did you make? (Give an overview)
This adds a fixer for
sort-imports
.It only sorts
ImportSpecifiers
, and does not sort multiple import statements. Sorting multiple import statements would cause the evaluation order of the imported files to change.This also makes a slight change to the
sort-imports
rule; it reports at most one specifier from a given import statement. This allows the entire list of specifiers to be sorted as a whole. For example:Is there anything you'd like reviewers to focus on?
Nothing in particular.