Change --type/funcattributes argument to prev-line

This commit is contained in:
Nick Lockwood
2020-07-25 09:02:36 +01:00
parent 6523b3d3b0
commit 799db2f920
6 changed files with 20 additions and 20 deletions
+6 -6
View File
@@ -119,17 +119,17 @@ swift version is set to 4.1 or above.
## attributes
Wrap @ attrubutes onto a separate line, or keep them on the same line.
Wrap @attributes onto a separate line, or keep them on the same line.
Option | Description
--- | ---
`--funcattributes` | Function @ attributes: "preserve", "new-line", or "same-line"
`--typeattributes` | Type @ attributes: "preserve", "new-line", or "same-line"
`--funcattributes` | Function @attributes: "preserve", "prev-line", or "same-line"
`--typeattributes` | Type @attributes: "preserve", "prev-line", or "same-line"
<details>
<summary>Examples</summary>
`--funcattributes new-line`
`--funcattributes prev-line`
```diff
- @objc func foo() {}
@@ -147,7 +147,7 @@ Option | Description
+ @objc func foo() {}
```
`--typeattributes new-line`
`--typeattributes prev-line`
```diff
- @objc class Foo {}
@@ -162,7 +162,7 @@ Option | Description
- @objc
- enum Foo { }
+ @objc enun Foo {}
+ @objc enum Foo {}
```
</details>
+3 -3
View File
@@ -1038,7 +1038,7 @@ private struct Examples {
"""
let attributes = """
`--funcattributes new-line`
`--funcattributes prev-line`
```diff
- @objc func foo() {}
@@ -1056,7 +1056,7 @@ private struct Examples {
+ @objc func foo() {}
```
`--typeattributes new-line`
`--typeattributes prev-line`
```diff
- @objc class Foo {}
@@ -1071,7 +1071,7 @@ private struct Examples {
- @objc
- enum Foo { }
+ @objc enun Foo {}
+ @objc enum Foo {}
```
"""
}
+1 -1
View File
@@ -86,7 +86,7 @@ public enum ArgumentStrippingMode: String {
// Wrap mode for @ attributes
public enum AttributeMode: String {
case newLine = "new-line"
case prevLine = "prev-line"
case sameLine = "same-line"
case preserve
}
+2 -2
View File
@@ -687,14 +687,14 @@ extension FormatOptions.Descriptor {
argumentName: "funcattributes",
propertyName: "funcAttributes",
displayName: "Function Attributes",
help: "Function @ attributes: \"preserve\", \"new-line\", or \"same-line\"",
help: "Function @attributes: \"preserve\", \"prev-line\", or \"same-line\"",
keyPath: \.funcAttributes
)
static let typeAttributes = FormatOptions.Descriptor(
argumentName: "typeattributes",
propertyName: "typeAttributes",
displayName: "Type Attributes",
help: "Type @ attributes: \"preserve\", \"new-line\", or \"same-line\"",
help: "Type @attributes: \"preserve\", \"prev-line\", or \"same-line\"",
keyPath: \.typeAttributes
)
+2 -2
View File
@@ -4387,7 +4387,7 @@ public struct _FormatRules {
/// Strip header comments from the file
public let attributes = FormatRule(
help: "Wrap @ attrubutes onto a separate line, or keep them on the same line.",
help: "Wrap @attributes onto a separate line, or keep them on the same line.",
options: ["funcattributes", "typeattributes"],
sharedOptions: ["linebreaks"]
) { formatter in
@@ -4441,7 +4441,7 @@ public struct _FormatRules {
switch attributeMode {
case .preserve:
return
case .newLine:
case .prevLine:
// Make sure there's a newline immediately following the attribute
if let nextTokenIndex = formatter.index(of: .nonSpaceOrComment, after: attributeEndIndex),
formatter.token(at: nextTokenIndex)?.isLinebreak != true {
+6 -6
View File
@@ -12019,7 +12019,7 @@ class RulesTests: XCTestCase {
@available(iOS 14.0, *)
func foo() {}
"""
let options = FormatOptions(funcAttributes: .newLine)
let options = FormatOptions(funcAttributes: .prevLine)
testFormatting(for: input, output, rule: FormatRules.attributes, options: options)
}
@@ -12028,7 +12028,7 @@ class RulesTests: XCTestCase {
@available(iOS 14.0, *)
func foo() {}
"""
let options = FormatOptions(funcAttributes: .newLine)
let options = FormatOptions(funcAttributes: .prevLine)
testFormatting(for: input, rule: FormatRules.attributes, options: options)
}
@@ -12059,7 +12059,7 @@ class RulesTests: XCTestCase {
@available(iOS 14.0, *)
func foo() {}
"""
let options = FormatOptions(funcAttributes: .newLine)
let options = FormatOptions(funcAttributes: .prevLine)
testFormatting(for: input, rule: FormatRules.attributes, options: options)
}
@@ -12071,7 +12071,7 @@ class RulesTests: XCTestCase {
@available(iOS 14.0, *)
class Foo {}
"""
let options = FormatOptions(typeAttributes: .newLine)
let options = FormatOptions(typeAttributes: .prevLine)
testFormatting(for: input, output, rule: FormatRules.attributes, options: options)
}
@@ -12080,7 +12080,7 @@ class RulesTests: XCTestCase {
@available(iOS 14.0, *)
struct Foo {}
"""
let options = FormatOptions(typeAttributes: .newLine)
let options = FormatOptions(typeAttributes: .prevLine)
testFormatting(for: input, rule: FormatRules.attributes, options: options)
}
@@ -12111,7 +12111,7 @@ class RulesTests: XCTestCase {
@available(iOS 14.0, *)
class Foo {}
"""
let options = FormatOptions(typeAttributes: .newLine)
let options = FormatOptions(typeAttributes: .prevLine)
testFormatting(for: input, rule: FormatRules.attributes, options: options)
}
}