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

Feature – Import sorting #362

Merged
merged 2 commits into from
Jul 8, 2019
Merged

Feature – Import sorting #362

merged 2 commits into from
Jul 8, 2019

Conversation

webmaster128
Copy link
Contributor

As noted in #361, we sometimes check-in code with unsorted imports. Right now, this is not detected by the linter/CI and a manual Organize Imports run needs to be done in the IDE. This leads to the problem that the next person who runs an Organize Imports creates a diff in the imports code that is not related to the current work.

In order to avoid this issue, we should have import sorting as part of the default linting process, preferribly with auto-fixing. This gives us:

  1. a failing CI in case of unsorted imports
  2. automatic saving when the eslint plugin is setup with autofix on save

The explored options were:

  1. eslint's native sort-imports: sorts by imported members, not by module. This causes unnecessary diffs when one symbol was imported before and in a PR additional symbols from the same module are imported (multiple vs. single)
  2. eslint-plugin-import: does not support sorting within a group
  3. eslint-plugin-simple-import-sort: simple and does what we need

There are now two groups of imports, separated by a newline. The first group is global modules, the second one relative imports.

@webmaster128 webmaster128 merged commit 08b611c into master Jul 8, 2019
@webmaster128 webmaster128 deleted the feature/import-sorting branch July 8, 2019 08:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants