nicklockwood / SwiftFormat

A command-line tool and Xcode Extension for formatting Swift code
MIT License
7.66k stars 623 forks source link

enumNamespaces ignored when located after an import #1569

Closed paul1893 closed 8 months ago

paul1893 commented 8 months ago

Describe the bug

enumNamespaces rule seems to be ignored if the class/struct is at specific position. Here is some source code, before and after swiftformat run with enumNamespaces rule enabled:

Before After
```swift import Foundation final class MyViewModel { static let = "A" } final class MyViewModel2 { static let = "A" } ``` ```swift import Foundation final class MyViewModel { static let = "A" } enum MyViewModel2 { static let = "A" } ```
Before After
```swift final class MyViewModel { static let = "A" } import Foundation final class MyViewModel2 { static let = "A" } ``` ```swift enum MyViewModel { static let = "A" } import Foundation final class MyViewModel2 { static let = "A" } ```
Before After
```swift final class MyViewModel { static let = "A" } final class MyViewModel2 { static let = "A" } import Foundation ``` ```swift enum MyViewModel { static let = "A" } enum MyViewModel2 { static let = "A" } import Foundation ```

import seems to have a side effect on the following entity.

Environment

swiftformat version: 0.52.8 swiftformat configuration file:

--lineaftermarks true
--typeblanklines remove
--allman false
--emptybraces no-space
--enumnamespaces always
--asynccapturing
--patternlet hoist
--throwcapturing
--modifierorder
--someAny false
--self insert
--redundanttype inferred
--closurevoid remove
--semicolons never
--importgrouping alpha
--operatorfunc spaced
--nospaceoperators
--ranges spaced
--trailingclosures
--nevertrailing
--commas inline
--trimwhitespace always
--shortoptionals always
--stripunusedargs always
--voidtype void
--yodaswap always
--elseposition same-line
--guardelse auto
--indent 4
--smarttabs enabled
--indentcase true
--ifdef indent
--indentstrings false
--decimalgrouping 3,6
--binarygrouping 4,8
--octalgrouping 4,8
--hexgrouping 4,8
--fractiongrouping disabled
--exponentgrouping disabled
--hexliteralcase uppercase
--exponentcase uppercase
--operatorfunc spaced
--maxwidth none
--assetliterals visual-width
--wraparguments before-first
--wrapparameters before-first
--wrapcollections before-first
--closingparen balanced
--wrapreturntype preserve
--wrapconditions preserve
--wrapeffects preserve
--funcattributes preserve
--typeattributes preserve
--varattributes preserve
--conflictmarkers reject
--extensionmark "MARK: - %t + %c"
--fragment false
--groupedextension "MARK: %c"
--linebreaks lf
--nowrapoperators
--swiftversion 5.8
--selfrequired
--tabwidth unspecified
--typemark "MARK: - %t"
--wrapternary default
--wraptypealiases preserve
--xcodeindentation disabled
--enable andOperator, anyObjectProtocol, assertionFailures, blankLineAfterImports, blankLinesAtEndOfScope, blankLinesBetweenScopes, blockComments, conditionalAssignment, consecutiveBlankLines, consecutiveSpaces, docComments, duplicateImports, initCoderUnavailable, leadingDelimiters, preferKeyPath, redundantBackticks, redundantBreak, redundantClosure, redundantExtensionACL, redundantFileprivate, redundantGet, redundantInit, redundantLet, redundantLetError, redundantNilInit, redundantObjc, redundantOptionalBinding, redundantParens, redundantPattern, spaceAroundBraces, spaceAroundBrackets, spaceAroundComments, spaceAroundGenerics, spaceAroundParens, spaceInsideBraces, spaceInsideBrackets, spaceInsideComments, spaceInsideGenerics, spaceInsideParens, strongOutlets, strongifiedSelf, todos
--disable acronyms, fileHeader, isEmpty, extensionAccessControl, redundantReturn, sortDeclarations, genericExtensions, redundantRawValues, redundantReturn, sortedSwitchCases, wrapConditionalBodies, wrapenumcases, wrapMultilineStatementBraces, wrapSingleLineComments, wrapSwitchCases, markTypes, organizeDeclarations
calda commented 8 months ago

Here's a fix: https://github.com/nicklockwood/SwiftFormat/pull/1576

paul1893 commented 8 months ago

Thank you for adressing this so quickly 🙏

nicklockwood commented 8 months ago

@paul1893 fixed in 0.52.9