From 40bff9e99d05ac4609bb7d7343d2ef1bac9a738b Mon Sep 17 00:00:00 2001 From: Nick Lockwood Date: Sun, 6 Mar 2022 22:40:16 +0000 Subject: [PATCH] Group rules in Rules.md by default status --- Rules.md | 30 ++++++++++++++++++------------ Tests/MetadataTests.swift | 24 ++++++++++++++++++++---- 2 files changed, 38 insertions(+), 16 deletions(-) diff --git a/Rules.md b/Rules.md index 1ba6879b6..49805c83d 100644 --- a/Rules.md +++ b/Rules.md @@ -1,15 +1,12 @@ -# Rules +# Default Rules (enabled by default) -* [acronyms](#acronyms) * [andOperator](#andOperator) * [anyObjectProtocol](#anyObjectProtocol) * [assertionFailures](#assertionFailures) * [blankLinesAroundMark](#blankLinesAroundMark) * [blankLinesAtEndOfScope](#blankLinesAtEndOfScope) * [blankLinesAtStartOfScope](#blankLinesAtStartOfScope) -* [blankLinesBetweenImports](#blankLinesBetweenImports) * [blankLinesBetweenScopes](#blankLinesBetweenScopes) -* [blockComments](#blockComments) * [braces](#braces) * [consecutiveBlankLines](#consecutiveBlankLines) * [consecutiveSpaces](#consecutiveSpaces) @@ -22,15 +19,11 @@ * [hoistPatternLet](#hoistPatternLet) * [indent](#indent) * [initCoderUnavailable](#initCoderUnavailable) -* [isEmpty](#isEmpty) * [leadingDelimiters](#leadingDelimiters) * [linebreakAtEndOfFile](#linebreakAtEndOfFile) * [linebreaks](#linebreaks) -* [markTypes](#markTypes) * [modifierOrder](#modifierOrder) * [numberFormatting](#numberFormatting) -* [organizeDeclarations](#organizeDeclarations) -* [preferDouble](#preferDouble) * [preferKeyPath](#preferKeyPath) * [redundantBackticks](#redundantBackticks) * [redundantBreak](#redundantBreak) @@ -53,7 +46,6 @@ * [semicolons](#semicolons) * [sortDeclarations](#sortDeclarations) * [sortedImports](#sortedImports) -* [sortedSwitchCases](#sortedSwitchCases) * [spaceAroundBraces](#spaceAroundBraces) * [spaceAroundBrackets](#spaceAroundBrackets) * [spaceAroundComments](#spaceAroundComments) @@ -65,7 +57,6 @@ * [spaceInsideComments](#spaceInsideComments) * [spaceInsideGenerics](#spaceInsideGenerics) * [spaceInsideParens](#spaceInsideParens) -* [specifiers *(deprecated)*](#specifiers) * [strongOutlets](#strongOutlets) * [strongifiedSelf](#strongifiedSelf) * [todos](#todos) @@ -78,11 +69,26 @@ * [wrap](#wrap) * [wrapArguments](#wrapArguments) * [wrapAttributes](#wrapAttributes) +* [wrapMultilineStatementBraces](#wrapMultilineStatementBraces) +* [yodaConditions](#yodaConditions) + +# Opt-in Rules (disabled by default) + +* [acronyms](#acronyms) +* [blankLinesBetweenImports](#blankLinesBetweenImports) +* [blockComments](#blockComments) +* [isEmpty](#isEmpty) +* [markTypes](#markTypes) +* [organizeDeclarations](#organizeDeclarations) +* [preferDouble](#preferDouble) +* [sortedSwitchCases](#sortedSwitchCases) * [wrapConditionalBodies](#wrapConditionalBodies) * [wrapEnumCases](#wrapEnumCases) -* [wrapMultilineStatementBraces](#wrapMultilineStatementBraces) * [wrapSwitchCases](#wrapSwitchCases) -* [yodaConditions](#yodaConditions) + +# Deprecated Rules (do not use) + +* [specifiers](#specifiers) ---------- diff --git a/Tests/MetadataTests.swift b/Tests/MetadataTests.swift index 112c2f16c..7cc847acd 100644 --- a/Tests/MetadataTests.swift +++ b/Tests/MetadataTests.swift @@ -40,11 +40,27 @@ class MetadataTests: XCTestCase { // NOTE: if test fails, just run it again locally to update rules file func testGenerateRulesDocumentation() throws { - var result = "# Rules\n" - for rule in FormatRules.all { - let annotation = rule.isDeprecated ? " *(deprecated)*" : "" - result += "\n* [\(rule.name)\(annotation)](#\(rule.name))" + var result = "# Default Rules (enabled by default)\n" + for rule in FormatRules.default { + result += "\n* [\(rule.name)](#\(rule.name))" + } + + result += "\n\n# Opt-in Rules (disabled by default)\n" + for rule in FormatRules.named(FormatRules.disabledByDefault) { + guard !rule.isDeprecated else { + continue + } + result += "\n* [\(rule.name)](#\(rule.name))" } + + let deprecatedRules = FormatRules.all.filter { $0.isDeprecated } + if !deprecatedRules.isEmpty { + result += "\n\n# Deprecated Rules (do not use)\n" + for rule in deprecatedRules { + result += "\n* [\(rule.name)](#\(rule.name))" + } + } + result += "\n\n----------" for rule in FormatRules.all { result += "\n\n## \(rule.name)\n\n\(rule.help)"