Skip to content
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

Merged
merged 3 commits into from Nov 25, 2016
Merged

Update: add fixer for sort-imports #7535

merged 3 commits into from Nov 25, 2016

Conversation

not-an-aardvark
Copy link
Member

@not-an-aardvark not-an-aardvark commented Nov 4, 2016

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:

import {foo, baz, bar} from 'qux.js';

// Previously, both 'baz' and 'bar' would have been reported. Now, only 'baz' will be reported.
// However, this statement will be correctly autofixed to:

import {bar, baz, foo} from 'qux.js';

Is there anything you'd like reviewers to focus on?

Nothing in particular.

@not-an-aardvark not-an-aardvark added enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion labels Nov 4, 2016
@not-an-aardvark not-an-aardvark self-assigned this Nov 4, 2016
@mention-bot
Copy link

@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.

@eslintbot
Copy link

LGTM

Copy link
Member

@nzakas nzakas left a 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';",
Copy link
Member

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.

@eslintbot
Copy link

LGTM

@not-an-aardvark
Copy link
Member Author

not-an-aardvark commented Nov 16, 2016

That's a good point about comments, I hadn't thought of that.

  • Added a test with linebreaks
  • Updated the fixer to not fix cases where the imported bindings have comments between them, and added tests to verify this.

@platinumazure platinumazure added accepted There is consensus among the team that this change meets the criteria for inclusion and removed evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion labels Nov 24, 2016
@nzakas nzakas merged commit 474e444 into master Nov 25, 2016
@not-an-aardvark not-an-aardvark deleted the sort-imports-fixer branch November 25, 2016 17:47
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 6, 2018
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Feb 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants