Skip to content

Conversation

@SimplyDanny
Copy link
Collaborator

Fixes #6317.

@jszumski
Copy link
Contributor

I'm still getting some unexpected diffs with this change:

 //
 // Copyright © Foo
 //
 
+import AAA // a comment
 import DDD
 import FFF
-
-// some comment
-import AAA // a comment
 import NNN
 import RRR
 import SSS

and

 //
 // Copyright © Foo
 //
 
 import DDD
-import SSS
 
 // some comment
 import FFF // a comment
+import SSS

@SwiftLintBot
Copy link

SwiftLintBot commented Oct 24, 2025

18 Messages
📖 Building this branch resulted in a binary size of 26388.18 KiB vs 26370.71 KiB when built on main (0% larger).
📖 Linting Aerial with this PR took 0.79 s vs 0.84 s on main (5% faster).
📖 Linting Alamofire with this PR took 1.05 s vs 1.06 s on main (0% faster).
📖 Linting Brave with this PR took 6.89 s vs 6.88 s on main (0% slower).
📖 Linting DuckDuckGo with this PR took 22.0 s vs 21.99 s on main (0% slower).
📖 Linting Firefox with this PR took 10.85 s vs 10.86 s on main (0% faster).
📖 Linting Kickstarter with this PR took 7.61 s vs 7.65 s on main (0% faster).
📖 Linting Moya with this PR took 0.43 s vs 0.44 s on main (2% faster).
📖 Linting NetNewsWire with this PR took 2.45 s vs 2.41 s on main (1% slower).
📖 Linting Nimble with this PR took 0.64 s vs 0.64 s on main (0% slower).
📖 Linting PocketCasts with this PR took 6.8 s vs 6.76 s on main (0% slower).
📖 Linting Quick with this PR took 0.41 s vs 0.4 s on main (2% slower).
📖 Linting Realm with this PR took 3.25 s vs 3.33 s on main (2% faster).
📖 Linting Sourcery with this PR took 1.86 s vs 1.87 s on main (0% faster).
📖 Linting Swift with this PR took 4.23 s vs 4.22 s on main (0% slower).
📖 Linting VLC with this PR took 1.15 s vs 1.13 s on main (1% slower).
📖 Linting Wire with this PR took 17.39 s vs 17.4 s on main (0% faster).
📖 Linting WordPress with this PR took 11.5 s vs 11.52 s on main (0% faster).

Generated by 🚫 Danger

@SimplyDanny
Copy link
Collaborator Author

I'm still getting some unexpected diffs with this change:

 //
 // Copyright © Foo
 //
 
+import AAA // a comment
 import DDD
 import FFF
-
-// some comment
-import AAA // a comment
 import NNN
 import RRR
 import SSS

and

 //
 // Copyright © Foo
 //
 
 import DDD
-import SSS
 
 // some comment
 import FFF // a comment
+import SSS

They should all be fine with the latest update. Are they, @jszumski?

@jszumski
Copy link
Contributor

So close! just this one edge case left:

+import BBB
 //
 // Copyright © Foo
 //
 
 import class CCC
-import BBB
 import LLL

I guess if the trivia of the old first item ends with a newline then a replacement into the first position should append to that old trivia?

@SimplyDanny
Copy link
Collaborator Author

I guess if the trivia of the old first item ends with a newline then a replacement into the first position should append to that old trivia?

Yeah, sort of that. 😅 The condition was too vague. The case of an empty line between the comment and the first imports wasn't decently handled.

Could you give it another try? That really helps getting this properly sorted (pun indented).

@jszumski
Copy link
Contributor

Also close, but if any replacement is made in a position >1 it chomps the first position's trivia:

 //
 //  Copyright © Foo
 //
-
 import AAA
-import class CCC2.View
 import CCC1
+import class CCC2.View

@SimplyDanny
Copy link
Collaborator Author

Next try ...

Copy link
Contributor

@jszumski jszumski left a comment

Choose a reason for hiding this comment

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

Perfect!

@SimplyDanny SimplyDanny merged commit 7b4335a into main Oct 26, 2025
25 checks passed
@SimplyDanny SimplyDanny deleted the sorted-imports branch October 26, 2025 07:26
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.

sorted_imports in 0.62.0 doesn't correctly distinguish groups

3 participants