🛠️

当たり障りない swift-format の Configuration

2021/07/06に公開1

swift-format をとりあえず導入したいという人におすすめの、当たり障りないConfigurationのjson例を示す。

ただ、私自信は以下のルールの有効無効は悩みどころ。

  • NoCasesWithOnlyFallthrough
  • NoLabelsInCasePatterns
  • NoParensAroundConditions
  • OnlyOneTrailingClosureArgument
.swift-format
{
  "version": 1,
  "lineLength": 100,
  "indentation": {
    "spaces": 4
  },
  "tabWidth": 4,
  "maximumBlankLines": 1,
  "respectsExistingLineBreaks": true,
  "lineBreakBeforeControlFlowKeywords": false,
  "lineBreakBeforeEachArgument": true,
  "lineBreakBeforeEachGenericRequirement": true,
  "prioritizeKeepingFunctionOutputTogether": false,
  "indentConditionalCompilationBlocks": false,
  "lineBreakAroundMultilineExpressionChainComponents": true,
  "indentSwitchCaseLabels": false,
  "fileScopedDeclarationPrivacy": {
    "accessLevel": "private"
  },
  "rules": {
    "AllPublicDeclarationsHaveDocumentation": false,
    "AlwaysUseLowerCamelCase": false,
    "AmbiguousTrailingClosureOverload": false,
    "BeginDocumentationCommentWithOneLineSummary": false,
    "DoNotUseSemicolons": true,
    "DontRepeatTypeInStaticProperties": false,
    "FileScopedDeclarationPrivacy": false,
    "FullyIndirectEnum": false,
    "GroupNumericLiterals": false,
    "IdentifiersMustBeASCII": false,
    "NeverForceUnwrap": false,
    "NeverUseForceTry": false,
    "NeverUseImplicitlyUnwrappedOptionals": false,
    "NoAccessLevelOnExtensionDeclaration": false,
    "NoBlockComments": false,
    "NoCasesWithOnlyFallthrough": false,
    "NoEmptyTrailingClosureParentheses": true,
    "NoLabelsInCasePatterns": true,
    "NoLeadingUnderscores": false,
    "NoParensAroundConditions": true,
    "NoVoidReturnOnFunctionSignature": true,
    "OneCasePerLine": true,
    "OneVariableDeclarationPerLine": true,
    "OnlyOneTrailingClosureArgument": false,
    "OrderedImports": true,
    "ReturnVoidInsteadOfEmptyTuple": true,
    "UseLetInEveryBoundCaseVariable": false,
    "UseShorthandTypeNames": true,
    "UseSingleLinePropertyGetter": true,
    "UseSynthesizedInitializer": false,
    "UseTripleSlashForDocumentationComments": false,
    "ValidateDocumentationComments": false
  }
}

参考

Discussion

KyomeKyome

lineLengthのせいで変なところで改行が入ってしまう場合は、respectsExistingLineBreaksを有効にして、予め納得のいく位置に改行を入れておくのがお勧めです。