mirror of
https://github.com/nicklockwood/SwiftFormat.git
synced 2026-06-16 10:34:34 +00:00
Rename attributes rule to wrapAttributes
This commit is contained in:
@@ -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.
|
||||
</details>
|
||||
<br/>
|
||||
|
||||
## 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"
|
||||
|
||||
<details>
|
||||
<summary>Examples</summary>
|
||||
|
||||
`--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 {}
|
||||
```
|
||||
|
||||
</details>
|
||||
<br/>
|
||||
|
||||
## blankLinesAroundMark
|
||||
|
||||
Insert blank line before and after `MARK:` comments.
|
||||
@@ -1642,6 +1591,57 @@ provided for `--wrapparameters`, the value for `--wraparguments` will be used.
|
||||
</details>
|
||||
<br/>
|
||||
|
||||
## 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"
|
||||
|
||||
<details>
|
||||
<summary>Examples</summary>
|
||||
|
||||
`--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 {}
|
||||
```
|
||||
|
||||
</details>
|
||||
<br/>
|
||||
|
||||
## wrapMultilineStatementBraces
|
||||
|
||||
Wrap the opening brace of multiline statements (if/guard/while/func).
|
||||
|
||||
@@ -1037,7 +1037,7 @@ private struct Examples {
|
||||
```
|
||||
"""
|
||||
|
||||
let attributes = """
|
||||
let wrapAttributes = """
|
||||
`--funcattributes prev-line`
|
||||
|
||||
```diff
|
||||
|
||||
+1
-1
@@ -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"]
|
||||
|
||||
@@ -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)'")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+14
-14
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user