Skip to content

Add grouping option to the sorted_imports rule - #4935

Merged
SimplyDanny merged 9 commits into
realm:mainfrom
hiltonc:sorted_imports_grouping
May 19, 2023
Merged

SimplyDanny merged 9 commits into
realm:mainfrom
hiltonc:sorted_imports_grouping

Conversation

@hiltonc

@hiltonc hiltonc commented Apr 25, 2023

Copy link
Copy Markdown
Contributor

Adds a grouping option to the sorted_import rule. With this configuration:

sorted_imports:
  grouping: attributes

It puts all the @testable imports at the top of the import groups.

@hiltonc
hiltonc force-pushed the sorted_imports_grouping branch from a930d40 to ce49660 Compare April 25, 2023 22:54
@SwiftLintBot

SwiftLintBot commented Apr 25, 2023 •

Copy link
Copy Markdown
1 Warning
⚠️ This PR may need tests.
17 Messages
📖 Linting Aerial with this PR took 1.11s vs 1.09s on main (1% slower)
📖 Linting Alamofire with this PR took 1.41s vs 1.4s on main (0% slower)
📖 Linting Brave with this PR took 7.59s vs 7.6s on main (0% faster)
📖 Linting DuckDuckGo with this PR took 3.69s vs 3.7s on main (0% faster)
📖 Linting Firefox with this PR took 9.58s vs 9.6s on main (0% faster)
📖 Linting Kickstarter with this PR took 10.23s vs 10.24s on main (0% faster)
📖 Linting Moya with this PR took 0.58s vs 0.58s on main (0% slower)
📖 Linting NetNewsWire with this PR took 3.16s vs 3.16s on main (0% slower)
📖 Linting Nimble with this PR took 0.66s vs 0.66s on main (0% slower)
📖 Linting PocketCasts with this PR took 7.58s vs 7.58s on main (0% slower)
📖 Linting Quick with this PR took 0.35s vs 0.34s on main (2% slower)
📖 Linting Realm with this PR took 11.14s vs 11.12s on main (0% slower)
📖 Linting Sourcery with this PR took 2.26s vs 2.25s on main (0% slower)
📖 Linting Swift with this PR took 4.77s vs 4.75s on main (0% slower)
📖 Linting VLC with this PR took 1.36s vs 1.36s on main (0% slower)
📖 Linting Wire with this PR took 8.39s vs 8.39s on main (0% slower)
📖 Linting WordPress with this PR took 11.85s vs 11.78s on main (0% slower)

Generated by 🚫 Danger

@hiltonc
hiltonc force-pushed the sorted_imports_grouping branch from ce49660 to 47ee139 Compare April 25, 2023 22:56
@hiltonc hiltonc changed the title Add grouping option to the sorted_imports rule Add grouping option to the sorted_imports rule Apr 25, 2023
@mildm8nnered

Copy link
Copy Markdown
Collaborator

So swift-format's OrderedImports rule takes the view that regular imports should precede testable imports.

It also sorts imports slightly differently as well - #4810

Not sure what the right answer is here, but it's a shame that we can't have some compatibility so that people can use both together, without the linters fighting over which is the correct order.

@hiltonc

hiltonc commented Apr 26, 2023 •

Copy link
Copy Markdown
Contributor Author

@mildm8nnered There’s definitely room for different import sort strategies. I’m open to changing the naming to allow for adding a swift-format compatible strategy down the line.

Maybe grouping -> strategy and attributes -> testableFirst.

@mildm8nnered

Copy link
Copy Markdown
Collaborator

@mildm8nnered There’s definitely room for different import sort strategies. I’m open to changing the naming to allow for adding a swift-format compatible strategy down the line.

Maybe grouping -> strategy and attributes -> testableFirst.

I think I wouldn't worry about it too much for now. I don't think that many people actually run swift-format linting anyway, but it is just kind of annoying that they have different conventions, or at least, cannot be configured to be compatible, although swift-format offers very little in the way of configurability.

@SimplyDanny SimplyDanny left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the contribution! I have a few remarks.

The most important point is that attributes do not necessarily have to stand on the same line like the import statement.

Comment thread CHANGELOG.md Resolved
Comment thread CHANGELOG.md Resolved
@hiltonc
hiltonc force-pushed the sorted_imports_grouping branch 2 times, most recently from 2c22a3c to f0c35e8 Compare May 9, 2023 22:39
@hiltonc
hiltonc requested a review from SimplyDanny May 9, 2023 22:49
@hiltonc
hiltonc force-pushed the sorted_imports_grouping branch from 65d7929 to 49017df Compare May 16, 2023 17:29
@hiltonc
hiltonc requested a review from SimplyDanny May 16, 2023 17:51
@hiltonc
hiltonc requested a review from SimplyDanny May 18, 2023 21:58
@SimplyDanny
SimplyDanny force-pushed the sorted_imports_grouping branch from dae615b to 47ba61d Compare May 19, 2023 19:27

@SimplyDanny SimplyDanny left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your work and your patience!

I've just rebased your branch since there were some conflicts caused by recent refactorings on main.

@SimplyDanny
SimplyDanny enabled auto-merge (squash) May 19, 2023 19:30
@SimplyDanny
SimplyDanny merged commit 1094a3b into realm:main May 19, 2023
@hiltonc
hiltonc deleted the sorted_imports_grouping branch May 22, 2023 17:03
@hiltonc

hiltonc commented May 22, 2023

Copy link
Copy Markdown
Contributor Author

Thanks @SimplyDanny!

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.

4 participants