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

Fix issue where type under organizeDeclarations line count threshold would ignore swiftformat:sort directive #1976

Merged
merged 1 commit into from
Feb 10, 2025

Conversation

calda
Copy link
Collaborator

@calda calda commented Feb 10, 2025

When sorting a type body with both sortDeclarations and organizeDeclarations are enabled, the sortDeclarations rule defers to the organizeDeclararions rule, which has a specialized sorting implementation.

However, the orgganizeDeclarations rule won't apply to any type below the configurable line count threshold. Since both sortDeclarations and organizeDeclarations are disabled in this case, any swiftformat:sort would be ignored.

Now, the sortDeclarations rule checks whether the type is under the organizeDeclarations threshold, and if so will now sort the type body.

@@ -155,12 +155,6 @@ class MetadataTests: XCTestCase {
allSharedOptions.subtract(ruleOptions)
var referencedOptions = [OptionDescriptor]()
for index in scopeStart + 1 ..< formatter.tokens.count {
guard (formatter.token(at: index - 1) == .operator(".", .infix)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These checks were filtering out the typeLengthExceedsOrganizationThreshold call in the organizeDeclarations rule, since it's in an extension Formatter and uses implicit self. Since we can remove this without getting any new unexpected issues, that seems reasonable.

Copy link

codecov bot commented Feb 10, 2025

Codecov Report

Attention: Patch coverage is 97.05882% with 1 line in your changes missing coverage. Please review.

Project coverage is 95.52%. Comparing base (ea8f96a) to head (b1d844e).
Report is 1 commits behind head on develop.

Files with missing lines Patch % Lines
Sources/FormattingHelpers.swift 96.55% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1976      +/-   ##
===========================================
- Coverage    95.53%   95.52%   -0.01%     
===========================================
  Files          139      139              
  Lines        25616    25620       +4     
===========================================
+ Hits         24472    24474       +2     
- Misses        1144     1146       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@calda calda merged commit bf5e04e into nicklockwood:develop Feb 10, 2025
10 of 11 checks passed
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.

1 participant