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

Applying blankLinesBetweenImports removes indentation of imported modules between pragma when indentation is disabled #1970

Open
acosmicflamingo opened this issue Feb 6, 2025 · 1 comment

Comments

@acosmicflamingo
Copy link

This is probably the smallest corner-case in the world, but thought I'd make this ticket in the off-chance it's an easy fix. I'm finding that when I try and commit this code, I see the following change:

// swiftformat:disable indent

import UIKit

#if DEBUG && canImport(SwiftUI)
  import ClientModels
- import MediaInterfaceFeature
- import SwiftUI
+import MediaInterfaceFeature
+import SwiftUI

#endif

// swiftformat:enable indent

This only happens when I disable indentation, which makes sense. But then I would've expected import ClientModels to also move in the same way.

@acosmicflamingo
Copy link
Author

I'm currently using SwiftFormat version 0.55.3, and this is the config I'm using:

# Rules can be found in the following URL:
#   - https://github.com/nicklockwood/SwiftFormat/blob/master/Rules.md

## File Options
# --conflictmarkers reject
--exclude */Derived
--exclude **/Autogen
# --fragment false

# Enabled Rules
--enable                        \
  acronyms,                     \
  anyObjectProtocol,            \
### Disabled because sometimes it is better to use the ampersand
### to demonstrate the AND condition
#  andOperator,                  \
  assertionFailures,            \
  applicationMain,              \
  blankLinesAroundMark,         \
  blankLinesAtStartOfScope,     \
### Disabled because it does not support @spi(Internals) import Foo
#  blankLineAfterImports,        \
### Disabled because it removes newlines after guard/else statements
#  blankLinesAtEndOfScope,       \
  blankLinesBetweenImports,     \
  blankLinesBetweenChainedFunctions, \
  blankLinesBetweenScopes,      \
  blockComments,                \
  braces,                       \
  conditionalAssignment,        \
  consecutiveBlankLines,        \
  consecutiveSpaces,            \
### Disabled because double parantheses are useful
### for general comments within functions
#  docComments,                  \
  duplicateImports,             \
  elseOnSameLine,               \
  emptyBraces,                  \
  enumNamespaces,               \
  extensionAccessControl,       \
  fileHeader,                   \
  genericExtensions,            \
  headerFileName,               \
  hoistAwait,                   \
  hoistPatternLet,              \
  hoistTry,                     \
  indent,                       \
  initCoderUnavailable,         \
  isEmpty,                      \
  leadingDelimiters,            \
  linebreakAtEndOfFile,         \
  linebreaks,                   \
  modifierOrder,                \
  numberFormatting,             \
  opaqueGenericParameters,      \
  preferKeyPath,                \
  redundantBackticks,           \
  redundantBreak,               \
  redundantClosure,             \
  redundantExtensionACL,        \
  redundantFileprivate,         \
  redundantGet,                 \
  redundantInit,                \
  redundantInternal,            \
  redundantLet,                 \
  redundantLetError,            \
  redundantNilInit,             \
  redundantObjc,                \
  redundantOptionalBinding,     \
  redundantParens,              \
  redundantPattern,             \
  redundantRawValues,           \
  redundantReturn,              \
  redundantSelf,                \
  redundantStaticSelf,          \
  redundantType,                \
  redundantVoidReturnType,      \
  semicolons,                   \
  sortDeclarations,             \
  sortImports,                  \
  sortSwitchCases,              \
  sortTypealiases,              \
  spaceAroundBraces,            \
  spaceAroundBrackets,          \
  spaceAroundComments,          \
  spaceAroundGenerics,          \
### Disable for now since it interferes with <@FunctionProxy>
### and adds a space when it should not
#  spaceAroundOperators,         \
  spaceAroundParens,            \
### Disabled because space inside braces do not look as nice
#  spaceInsideBraces,            \
  spaceInsideBrackets,          \
  spaceInsideComments,          \
  spaceInsideGenerics,          \
  spaceInsideParens,            \
  strongOutlets,                \
  strongifiedSelf,              \
  trailingClosures,             \
  trailingCommas,               \
  trailingSpace,                \
  todos,                        \
### Disabled because extension Array<S> is preferred to
### extension [S]
#  typeSugar,                    \
  unusedArguments,              \
### Disabled because it should be used with care
#  unusedPrivateDeclarations,    \
  void,                         \
  wrap,                         \
  wrapArguments,                \
  wrapAttributes,               \
### Disabled because conditional bodies should not be
### wrapped when they are guard/else type
#  wrapConditionalBodies,        \
  wrapEnumCases,                \
### Disabled because formatting of multiline statement
### braces is atrocious
#  wrapMultilineStatementBraces, \
  wrapSingleLineComments,       \
  wrapSwitchCases,              \
  yodaConditions

## Enabled Rules
--acronyms \
#  ID,      \
#  URL,     \
  UUID

# blankLinesAroundMark
--lineaftermarks true

# blankLinesAtStartOfScope
--typeblanklines remove

# braces
--allman false

# elseOnSameLine
--elseposition same-line
--guardelse next-line

# emptyBraces
--emptybraces no-space

# enumNamespaces
--enumnamespaces always

# extensionAccessControl
--extensionacl on-declarations

# fileHeader
--header ignore

# genericExtensions
--generictypes

# hoistAwait
--asynccapturing

# hoistTry
--throwcapturing

# hoistPatternLet
--patternlet hoist

# indent
--indent 2
--tabwidth unspecified
--smarttabs false
--indentcase false
--ifdef indent
--xcodeindentation disabled
--indentstrings true

# linebreaks
--linebreaks lf

### Disabled for now because it customizes too much
# # markTypes
# --marktypes always
# --typemark "MARK: - %t"
# --markextensions always
# --extensionmark "MARK: - %t + %c"
# --groupedextension "MARK: %c"

# modifierOrder
--modifierorder 

# numberFormatting
--decimalgrouping 3,6
--binarygrouping 4,8
--octalgrouping 4,8
--hexgrouping 2,4
--fractiongrouping disabled
--exponentgrouping disabled
--hexliteralcase uppercase
--exponentcase lowercase

# opaqueGenericParameters
--someAny true

### Disabled for now because it customizes too much
# # organizeDeclarations
# --categorymark "MARK: %c"
# --markcategories true
# --beforemarks 
# --lifecycle 
# --organizetypes  \
#     actor,       \
#     class,       \
#     enum,        \
#     struct
# --structthreshold 0
# --classthreshold 0
# --enumthreshold 0
# --extensionlength 0

# redundantSelf
--self init-only
--selfrequired

# redundantType
--redundanttype infer-locals-only

# redundantVoidReturnType
--closurevoid remove

# semicolons
--semicolons never

# spacesAroundOperators
--operatorfunc spaced
--ranges spaced
--typedelimiter space-after

# sortedImports
--importgrouping testable-last

### Disable for now since it interferes with <@FunctionProxy>
### and adds a space when it should not
# # spaceAroundOperators
# --operatorfunc spaced
# --nospaceoperators *,...,..<
# --ranges spaced

# trailingClosures
--trailingclosures 
--nevertrailing dependency

# trailingCommas
--commas always

# trailingSpace
--trimwhitespace always

### Disabled because extension Array<S> is preferred to
### extension [S]
# # typeSugar
# --shortoptionals always

# unusedArguments
--stripunusedargs unnamed-only

# void
--voidtype void

# wrap
--maxwidth 100
--nowrapoperators 
--assetliterals visual-width
--wrapternary before-operators

# wrapArguments
--wraparguments before-first
--wrapparameters before-first
--wrapcollections before-first
--closingparen balanced
--wrapreturntype preserve
--wrapconditions preserve
--wraptypealiases preserve
--wrapeffects preserve

# wrapAttributes
--funcattributes preserve
--typeattributes preserve
--varattributes preserve

# wrapEnumCases
--wrapenumcases always

# yodaConditions
--yodaswap always

## Disabled Rules (force opt-in)
--disable all

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

No branches or pull requests

1 participant