diff --git a/Rules.md b/Rules.md index 59ebfc6c..64d42fb3 100644 --- a/Rules.md +++ b/Rules.md @@ -2,7 +2,6 @@ * [andOperator](#andOperator) * [anyObjectProtocol](#anyObjectProtocol) -* [attributes](#attributes) * [blankLinesAroundMark](#blankLinesAroundMark) * [blankLinesAtEndOfScope](#blankLinesAtEndOfScope) * [blankLinesAtStartOfScope](#blankLinesAtStartOfScope) @@ -63,6 +62,7 @@ * [void](#void) * [wrap](#wrap) * [wrapArguments](#wrapArguments) +* [wrapAttributes](#wrapAttributes) * [wrapMultilineStatementBraces](#wrapMultilineStatementBraces) * [yodaConditions](#yodaConditions) @@ -117,57 +117,6 @@ swift version is set to 4.1 or above.
-## attributes - -Wrap @attributes onto a separate line, or keep them on the same line. - -Option | Description ---- | --- -`--funcattributes` | Function @attributes: "preserve", "prev-line", or "same-line" -`--typeattributes` | Type @attributes: "preserve", "prev-line", or "same-line" - -
-Examples - -`--funcattributes prev-line` - -```diff -- @objc func foo() {} - -+ @objc -+ func foo() { } -``` - -`--funcattributes same-line` - -```diff -- @objc -- func foo() { } - -+ @objc func foo() {} -``` - -`--typeattributes prev-line` - -```diff -- @objc class Foo {} - -+ @objc -+ class Foo { } -``` - -`--typeattributes same-line` - -```diff -- @objc -- enum Foo { } - -+ @objc enum Foo {} -``` - -
-
- ## blankLinesAroundMark Insert blank line before and after `MARK:` comments. @@ -1642,6 +1591,57 @@ provided for `--wrapparameters`, the value for `--wraparguments` will be used.
+## wrapAttributes + +Wrap @attributes onto a separate line, or keep them on the same line. + +Option | Description +--- | --- +`--funcattributes` | Function @attributes: "preserve", "prev-line", or "same-line" +`--typeattributes` | Type @attributes: "preserve", "prev-line", or "same-line" + +
+Examples + +`--funcattributes prev-line` + +```diff +- @objc func foo() {} + ++ @objc ++ func foo() { } +``` + +`--funcattributes same-line` + +```diff +- @objc +- func foo() { } + ++ @objc func foo() {} +``` + +`--typeattributes prev-line` + +```diff +- @objc class Foo {} + ++ @objc ++ class Foo { } +``` + +`--typeattributes same-line` + +```diff +- @objc +- enum Foo { } + ++ @objc enum Foo {} +``` + +
+
+ ## wrapMultilineStatementBraces Wrap the opening brace of multiline statements (if/guard/while/func). diff --git a/Sources/Examples.swift b/Sources/Examples.swift index fde91a11..437b9a6f 100644 --- a/Sources/Examples.swift +++ b/Sources/Examples.swift @@ -1037,7 +1037,7 @@ private struct Examples { ``` """ - let attributes = """ + let wrapAttributes = """ `--funcattributes prev-line` ```diff diff --git a/Sources/Rules.swift b/Sources/Rules.swift index 376aef89..2cfed71e 100644 --- a/Sources/Rules.swift +++ b/Sources/Rules.swift @@ -4386,7 +4386,7 @@ public struct _FormatRules { } /// Strip header comments from the file - public let attributes = FormatRule( + public let wrapAttributes = FormatRule( help: "Wrap @attributes onto a separate line, or keep them on the same line.", options: ["funcattributes", "typeattributes"], sharedOptions: ["linebreaks"] diff --git a/Tests/MetadataTests.swift b/Tests/MetadataTests.swift index d1bf0c9a..70aba4bf 100644 --- a/Tests/MetadataTests.swift +++ b/Tests/MetadataTests.swift @@ -193,7 +193,7 @@ class MetadataTests: XCTestCase { func testAllExamplesMatchRule() { for key in FormatRules.examplesByName.keys { - XCTAssertNotNil(FormatRules.byName[key], "Examples includes entry for unknown rule 'key'") + XCTAssertNotNil(FormatRules.byName[key], "Examples includes entry for unknown rule '\(key)'") } } diff --git a/Tests/RulesTests.swift b/Tests/RulesTests.swift index 65f64f1c..f37a93c3 100644 --- a/Tests/RulesTests.swift +++ b/Tests/RulesTests.swift @@ -11994,21 +11994,21 @@ class RulesTests: XCTestCase { testFormatting(for: input, rule: FormatRules.wrapMultilineStatementBraces) } - // MARK: - attributes + // MARK: - wrapAttributes func testPreserveWrappedFuncAttributeByDefault() { let input = """ @objc func foo() {} """ - testFormatting(for: input, rule: FormatRules.attributes) + testFormatting(for: input, rule: FormatRules.wrapAttributes) } func testPreserveUnwrappedFuncAttributeByDefault() { let input = """ @objc func foo() {} """ - testFormatting(for: input, rule: FormatRules.attributes) + testFormatting(for: input, rule: FormatRules.wrapAttributes) } func testWrapFuncAttribute() { @@ -12020,7 +12020,7 @@ class RulesTests: XCTestCase { func foo() {} """ let options = FormatOptions(funcAttributes: .prevLine) - testFormatting(for: input, output, rule: FormatRules.attributes, options: options) + testFormatting(for: input, output, rule: FormatRules.wrapAttributes, options: options) } func testMultipleAttributesNotSeparated() { @@ -12032,7 +12032,7 @@ class RulesTests: XCTestCase { func foo {} """ let options = FormatOptions(funcAttributes: .prevLine) - testFormatting(for: input, output, rule: FormatRules.attributes, + testFormatting(for: input, output, rule: FormatRules.wrapAttributes, options: options, exclude: ["redundantObjc"]) } @@ -12042,7 +12042,7 @@ class RulesTests: XCTestCase { func foo() {} """ let options = FormatOptions(funcAttributes: .prevLine) - testFormatting(for: input, rule: FormatRules.attributes, options: options) + testFormatting(for: input, rule: FormatRules.wrapAttributes, options: options) } func testUnwrapFuncAttribute() { @@ -12054,7 +12054,7 @@ class RulesTests: XCTestCase { @available(iOS 14.0, *) func foo() {} """ let options = FormatOptions(funcAttributes: .sameLine) - testFormatting(for: input, output, rule: FormatRules.attributes, options: options) + testFormatting(for: input, output, rule: FormatRules.wrapAttributes, options: options) } func testFuncAttributeStaysUnwrapped() { @@ -12062,7 +12062,7 @@ class RulesTests: XCTestCase { @objc func foo() {} """ let options = FormatOptions(funcAttributes: .sameLine) - testFormatting(for: input, rule: FormatRules.attributes, options: options) + testFormatting(for: input, rule: FormatRules.wrapAttributes, options: options) } func testVarAttributeIsNotWrapped() { @@ -12073,7 +12073,7 @@ class RulesTests: XCTestCase { func foo() {} """ let options = FormatOptions(funcAttributes: .prevLine) - testFormatting(for: input, rule: FormatRules.attributes, options: options) + testFormatting(for: input, rule: FormatRules.wrapAttributes, options: options) } func testWrapTypeAttribute() { @@ -12085,7 +12085,7 @@ class RulesTests: XCTestCase { class Foo {} """ let options = FormatOptions(typeAttributes: .prevLine) - testFormatting(for: input, output, rule: FormatRules.attributes, options: options) + testFormatting(for: input, output, rule: FormatRules.wrapAttributes, options: options) } func testTypeAttributeStaysWrapped() { @@ -12094,7 +12094,7 @@ class RulesTests: XCTestCase { struct Foo {} """ let options = FormatOptions(typeAttributes: .prevLine) - testFormatting(for: input, rule: FormatRules.attributes, options: options) + testFormatting(for: input, rule: FormatRules.wrapAttributes, options: options) } func testUnwrapTypeAttribute() { @@ -12106,7 +12106,7 @@ class RulesTests: XCTestCase { @available(iOS 14.0, *) enum Foo {} """ let options = FormatOptions(typeAttributes: .sameLine) - testFormatting(for: input, output, rule: FormatRules.attributes, options: options) + testFormatting(for: input, output, rule: FormatRules.wrapAttributes, options: options) } func testTypeAttributeStaysUnwrapped() { @@ -12114,7 +12114,7 @@ class RulesTests: XCTestCase { @objc class Foo {} """ let options = FormatOptions(typeAttributes: .sameLine) - testFormatting(for: input, rule: FormatRules.attributes, options: options) + testFormatting(for: input, rule: FormatRules.wrapAttributes, options: options) } func testTestableImportIsNotWrapped() { @@ -12125,6 +12125,6 @@ class RulesTests: XCTestCase { class Foo {} """ let options = FormatOptions(typeAttributes: .prevLine) - testFormatting(for: input, rule: FormatRules.attributes, options: options) + testFormatting(for: input, rule: FormatRules.wrapAttributes, options: options) } }