Skip to content

Add sort order option for sorted imports#6665

Open
ayushnagpal570-ai wants to merge 1 commit into
realm:mainfrom
ayushnagpal570-ai:configurable-sorted-imports-order
Open

Add sort order option for sorted imports#6665
ayushnagpal570-ai wants to merge 1 commit into
realm:mainfrom
ayushnagpal570-ai:configurable-sorted-imports-order

Conversation

@ayushnagpal570-ai

Copy link
Copy Markdown

Summary

  • add a sort_order option to sorted_imports with case_insensitive as the existing default and lexicographic as the new alternative
  • thread the configured sort order through linting and autocorrection
  • cover the new ordering mode in rule examples and the default configuration fixture

Closes #4810.

Tests

  • swift test --filter SortedImportsRuleGeneratedTests
  • swift test --filter RuleConfigurationTests
  • swift test --filter IntegrationTests
  • git diff --check

@SwiftLintBot

Copy link
Copy Markdown
19 Messages
📖 Building this branch resulted in a binary size of 27464.07 KiB vs 27458.24 KiB when built on main (0% larger).
📖 Linting Aerial with this PR took 0.75 s vs 0.74 s on main (1% slower).
📖 Linting Alamofire with this PR took 1.04 s vs 1.03 s on main (0% slower).
📖 Linting Brave with this PR took 7.09 s vs 7.07 s on main (0% slower).
📖 Linting DuckDuckGo with this PR took 28.69 s vs 28.65 s on main (0% slower).
📖 Linting Firefox with this PR took 12.06 s vs 12.1 s on main (0% faster).
📖 Linting Kickstarter with this PR took 8.24 s vs 8.18 s on main (0% slower).
📖 Linting Moya with this PR took 0.43 s vs 0.42 s on main (2% slower).
📖 Linting NetNewsWire with this PR took 2.72 s vs 2.72 s on main (0% slower).
📖 Linting Nimble with this PR took 0.63 s vs 0.61 s on main (3% slower).
📖 Linting PocketCasts with this PR took 7.84 s vs 7.95 s on main (1% faster).
📖 Linting Quick with this PR took 0.4 s vs 0.41 s on main (2% faster).
📖 Linting Realm with this PR took 2.91 s vs 2.9 s on main (0% slower).
📖 Linting Sourcery with this PR took 1.83 s vs 1.8 s on main (1% slower).
📖 Linting Swift with this PR took 4.6 s vs 4.6 s on main (0% slower).
📖 Linting SwiftLintPerformanceTests with this PR took 0.29 s vs 0.27 s on main (7% slower).
📖 Linting VLC with this PR took 1.18 s vs 1.17 s on main (0% slower).
📖 Linting Wire with this PR took 18.37 s vs 18.38 s on main (0% faster).
📖 Linting WordPress with this PR took 12.36 s vs 12.34 s on main (0% slower).

Generated by 🚫 Danger

@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, @ayushnagpal570-ai!

I wonder if case_insensitive and lexicographic are the clearest pair of names here. lexicographic is technically accurate, but it doesn’t feel parallel with case_insensitive, so the distinction may be a little harder to grasp from the config alone. If the practical difference is just whether case affects ordering, would case_insensitive/case_sensitive be clearer and more consistent?

let offset: Int
let attributes: String
let modifier: UInt8
let sortOrder: SortedImportsConfiguration.SortOrder

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.

I don't think this should be a property of an import, but of the comparison. What if I set one style for one import and another one for the other? That doesn't happen here, but the API would suggest that it would work ...

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.

Feature request: lexicographic sorting options for sorted_imports

3 participants