Skip to content

Instantly share code, notes, and snippets.

@faimin
Last active September 13, 2025 09:36
Show Gist options
  • Save faimin/d1a89a5b86b2217af3b42f738a752f5f to your computer and use it in GitHub Desktop.
Save faimin/d1a89a5b86b2217af3b42f738a752f5f to your computer and use it in GitHub Desktop.
Swiftformat格式化规则定制
# SwiftFormat config compliant with Google Swift Guideline
# https://google.github.io/swift/#control-flow-statements
# Specify version used in a project
--swiftversion 5.10
# Rules explicitly required by the guideline
--rules \
blankLinesAroundMark, \
blankLinesAtEndOfScope, \
blankLinesAtStartOfScope, \
blankLinesBetweenScopes, \
blankLinesBetweenImports, \
braces, \
consecutiveBlankLines, \
consecutiveSpaces, \
docComments, \
duplicateImports, \
elseOnSameLine, \
emptyBraces, \
enumNamespaces, \
extensionAccessControl, \
hoistPatternLet, \
indent, \
leadingDelimiters, \
linebreakAtEndOfFile, \
markTypes, \
organizeDeclarations, \ #修改声明顺序
redundantInit, \
redundantInternal, \
redundantParens, \
redundantPattern, \
redundantRawValues, \
redundantVoidReturnType, \
semicolons, \
spaceAroundBraces, \
spaceAroundBrackets, \
spaceAroundComments, \
spaceAroundGenerics, \
spaceAroundOperators, \
spaceAroundParens, \
spaceInsideBraces, \
spaceInsideBrackets, \
spaceInsideComments, \
spaceInsideGenerics, \
spaceInsideParens, \
todos, \
trailingCommas, \
trailingSpace, \
typeSugar, \
void, \
wrap, \
wrapArguments, \
wrapAttributes, \
wrapSingleLineComments, \
consistentSwitchCaseSpacing, \
#
#
# Additional rules not mentioned in the guideline, but helping to keep the codebase clean
# Quoting the guideline:
# Common themes among the rules in this section are:
# avoid redundancy, avoid ambiguity, and prefer implicitness over explicitness
# unless being explicit improves readability and/or reduces ambiguity.
#
#
andOperator, \
isEmpty, \
redundantBackticks, \
redundantBreak, \
redundantExtensionACL, \
redundantFileprivate, \
redundantNilInit, \
redundantObjc, \
strongifiedSelf, \
anyObjectProtocol, \
initCoderUnavailable, \
# 备忘
#redundantLetError,
#redundantSelf,
#redundantReturn,
#trailingClosures,
#opaqueGenericParameters, #some any
#redundantClosure,
#redundantGet,
#sortSwitchCases,
#sortImports,
#redundantType,
#blockComments, # /*注释转为 //
# Options for basic rules
--extensionacl on-extension
--funcattributes prev-line
--indent 4
--ifdef no-indent
#--xcodeindentation enabled
--maxwidth 120
--typeattributes prev-line
--storedvarattrs same-line
--wraparguments before-first
--wrapparameters before-first
--wrapcollections before-first
--wrapreturntype preserve #if-multiline
--wrapconditions after-first
--elseposition same-line #next-line
--guardelse auto
--organizationmode type #声明顺序
#--redundanttype inferred
# Option for additional rules
--self init-only
# Excluded folders
--exclude Pods,**/UNTESTED_TODO,vendor,fastlane
# https://github.com/NoemiRozpara/Google-SwiftFormat-Config
# Following is by Lava
--ifdef no-indent
# Why doesn't this work?
--modifierorder public,override,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment