Skip to content

Instantly share code, notes, and snippets.

@macshome
Last active October 30, 2023 17:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save macshome/67d2f80c7f6ceb69225bf2668a53d898 to your computer and use it in GitHub Desktop.
Save macshome/67d2f80c7f6ceb69225bf2668a53d898 to your computer and use it in GitHub Desktop.
The default settings for swift-format

swift-format Default Settings

Since I've not found anywhere that describes the default settings of swift-format other than the code, I've pulled those settings out and presented them here.

Rules that are opt-in are marked as such.

Formating-Only Rules

(Most of these rules are defined in the default config, not the rules folder.)

  1. maximumBlankLines = 1
  2. lineLength = 100
  3. tabWidth = 8
  4. indentation = .spaces(2)
  5. respectsExistingLineBreaks = true
  6. lineBreakBeforeControlFlowKeywords = false
  7. lineBreakBeforeEachArgument = false
  8. lineBreakBeforeEachGenericRequirement = false
  9. prioritizeKeepingFunctionOutputTogether = false
  10. indentConditionalCompilationBlocks = true
  11. lineBreakAroundMultilineExpressionChainComponents = false
  12. indentSwitchCaseLabels = false
  13. spacesAroundRangeFormationOperators = false
  14. UseEarlyExits = false (Opt-In)

Lint-Only Rules

You can find the code that defines all these rules in the SwiftFormatRules source folder.

  1. AllPublicDeclarationsHaveDocumentation = false (Opt-In)
  2. AlwaysUseLowerCamelCase = true
  3. AmbiguousTrailingClosureOverload = true
  4. BeginDocumentationCommentWithOneLineSummary = false (Opt-In)
  5. DontRepeatTypeInStaticProperties = true
  6. FileScopedDeclarationPrivacy = true
  7. IdentifiersMustBeASCII = true
  8. NeverForceUnwrap = false (Opt-In)
  9. NeverUseForceTry = false (Opt-In)
  10. NeverUseImplicitlyUnwrappedOptionals = false (Opt-In)
  11. NoBlockComments = true
  12. NoLeadingUnderscores = false (Opt-In)
  13. OnlyOneTrailingClosureArgument = true
  14. UseLetInEveryBoundCaseVariable = true
  15. UseShorthandTypeNames = true
  16. UseSynthesizedInitializer = true
  17. ValidateDocumentationComments = false (Opt-In)

Format and Lint Rules

Rules that are used by both the formatter and linter.

You can find the code that defines all these rules in the SwiftFormatRules source folder.

  1. DoNotUseSemicolons = true
  2. fileScopedDeclarationPrivacy = .private
  3. FullyIndirectEnum = true
  4. GroupNumericLiterals = true
  5. NoAccessLevelOnExtensionDeclaration = true
  6. NoAssignmentInExpressions = true
  7. NoCasesWithOnlyFallthrough = true
  8. NoEmptyTrailingClosureParentheses = true
  9. NoLabelsInCasePatterns = true
  10. NoParensAroundConditions = true
  11. NoVoidReturnOnFunctionSignature = true
  12. OneCasePerLine = true
  13. OneVariableDeclarationPerLine = true
  14. OrderedImports = true
  15. ReturnVoidInsteadOfEmptyTuple = true
  16. UseShorthandTypeNames = true
  17. UseSingleLinePropertyGetter = true
  18. UseTripleSlashForDocumentationComments = true
  19. UseWhereClausesInForLoops = false (Opt-In)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment