mirror of
https://github.com/nicklockwood/SwiftFormat.git
synced 2026-06-16 10:34:34 +00:00
Deprecated —comments option
This commit is contained in:
@@ -469,7 +469,6 @@ Option | Description
|
||||
--- | ---
|
||||
`--indent` | Number of spaces to indent, or "tab" to use tabs
|
||||
`--indentcase` | Indent cases inside a switch: "true" or "false" (default)
|
||||
`--comments` | Indenting of comment bodies: "indent" (default) or "ignore"
|
||||
`--ifdef` | #if indenting: "indent" (default), "no-indent" or "outdent"
|
||||
|
||||
<details>
|
||||
|
||||
@@ -189,11 +189,6 @@ private struct Inference {
|
||||
options.trailingCommas = (trailing >= noTrailing)
|
||||
}
|
||||
|
||||
let indentComments = OptionInferrer { _, options in
|
||||
// No way to infer this
|
||||
options.indentComments = true
|
||||
}
|
||||
|
||||
let truncateBlankLines = OptionInferrer { formatter, options in
|
||||
var truncated = 0, untruncated = 0
|
||||
var scopeStack = [Token]()
|
||||
|
||||
@@ -217,7 +217,6 @@ extension FormatOptions.Descriptor {
|
||||
useVoid,
|
||||
indentCase,
|
||||
trailingCommas,
|
||||
indentComments,
|
||||
truncateBlankLines,
|
||||
allmanBraces,
|
||||
fileHeader,
|
||||
@@ -242,6 +241,7 @@ extension FormatOptions.Descriptor {
|
||||
trailingClosures,
|
||||
|
||||
// Deprecated
|
||||
indentComments,
|
||||
insertBlankLines,
|
||||
removeBlankLines,
|
||||
|
||||
@@ -584,6 +584,7 @@ extension FormatOptions.Descriptor {
|
||||
// MARK: - DEPRECATED
|
||||
|
||||
static let deprecatedMessage = [
|
||||
indentComments.argumentName: "`--comments` option is deprecated. Relative indent within multiline comments is now preserved by default.",
|
||||
insertBlankLines.argumentName: "`--insertlines` option is deprecated. Use `--enable blankLinesBetweenScopes` or `--enable blankLinesAroundMark` or `--disable blankLinesBetweenScopes` or `--disable blankLinesAroundMark` instead.",
|
||||
removeBlankLines.argumentName: "`--removelines` option is deprecated. Use `--enable blankLinesAtStartOfScope` or `--enable blankLinesAtEndOfScope` or `--disable blankLinesAtStartOfScope` or `--disable blankLinesAtEndOfScope` instead",
|
||||
hexLiterals.argumentName: "`--hexliterals` option is deprecated. Use `--hexliteralcase` instead",
|
||||
|
||||
+3
-8
@@ -522,10 +522,8 @@ public struct _FormatRules {
|
||||
/// Add space inside comments, taking care not to mangle headerdoc or
|
||||
/// carefully preformatted comments, such as star boxes, etc.
|
||||
public let spaceInsideComments = FormatRule(
|
||||
help: "Adds a space inside `/* ... */` comments and at the start of `//` comments",
|
||||
sharedOptions: ["comments"] // TODO: should this rule even use this option?
|
||||
help: "Adds a space inside `/* ... */` comments and at the start of `//` comments"
|
||||
) { formatter in
|
||||
guard formatter.options.indentComments else { return }
|
||||
formatter.forEach(.startOfScope("//")) { i, _ in
|
||||
guard let nextToken = formatter.token(at: i + 1),
|
||||
case let .commentBody(string) = nextToken else { return }
|
||||
@@ -828,7 +826,7 @@ public struct _FormatRules {
|
||||
/// indenting can be configured with the `options` parameter of the formatter.
|
||||
public let indent = FormatRule(
|
||||
help: "Adjusts leading whitespace based on scope and line wrapping",
|
||||
options: ["indent", "indentcase", "comments", "ifdef"],
|
||||
options: ["indent", "indentcase", "ifdef"],
|
||||
sharedOptions: ["trimwhitespace", "linebreaks"]
|
||||
) { formatter in
|
||||
var scopeStack: [Token] = []
|
||||
@@ -1100,8 +1098,7 @@ public struct _FormatRules {
|
||||
}
|
||||
// Check if line on which scope ends should be unindented
|
||||
let start = formatter.startOfLine(at: i)
|
||||
if !isCommentedCode(at: start), formatter.options.indentComments ||
|
||||
formatter.next(.nonSpace, after: start - 1) != .startOfScope("/*"),
|
||||
if !isCommentedCode(at: start),
|
||||
let nextToken = formatter.next(.nonSpaceOrCommentOrLinebreak, after: start - 1),
|
||||
nextToken.isEndOfScope || nextToken == .keyword("@unknown"),
|
||||
!nextToken.isMultilineStringDelimiter {
|
||||
@@ -1254,8 +1251,6 @@ public struct _FormatRules {
|
||||
return
|
||||
}
|
||||
formatter.insertSpace(indent, at: i + 1)
|
||||
case .startOfScope("/*"), .commentBody, .endOfScope("*/"):
|
||||
if formatter.options.indentComments { fallthrough }
|
||||
default:
|
||||
formatter.insertSpace(indent, at: i + 1)
|
||||
}
|
||||
|
||||
@@ -159,7 +159,7 @@ class ArgumentsTests: XCTestCase {
|
||||
}
|
||||
|
||||
func testCommandLineArgumentsAreCorrect() {
|
||||
let output = ["allman": "false", "wraparguments": "preserve", "stripunusedargs": "always", "self": "remove", "header": "ignore", "importgrouping": "alphabetized", "fractiongrouping": "disabled", "binarygrouping": "4,8", "octalgrouping": "4,8", "indentcase": "false", "trimwhitespace": "always", "decimalgrouping": "3,6", "exponentgrouping": "disabled", "patternlet": "hoist", "commas": "always", "wrapcollections": "preserve", "semicolons": "inline", "indent": "4", "exponentcase": "lowercase", "operatorfunc": "spaced", "symlinks": "ignore", "elseposition": "same-line", "empty": "void", "ranges": "spaced", "hexliteralcase": "uppercase", "linebreaks": "lf", "hexgrouping": "4,8", "comments": "indent", "ifdef": "indent", "closingparen": "balanced", "selfrequired": "", "trailingclosures": ""]
|
||||
let output = ["allman": "false", "wraparguments": "preserve", "stripunusedargs": "always", "self": "remove", "header": "ignore", "importgrouping": "alphabetized", "fractiongrouping": "disabled", "binarygrouping": "4,8", "octalgrouping": "4,8", "indentcase": "false", "trimwhitespace": "always", "decimalgrouping": "3,6", "exponentgrouping": "disabled", "patternlet": "hoist", "commas": "always", "wrapcollections": "preserve", "semicolons": "inline", "indent": "4", "exponentcase": "lowercase", "operatorfunc": "spaced", "symlinks": "ignore", "elseposition": "same-line", "empty": "void", "ranges": "spaced", "hexliteralcase": "uppercase", "linebreaks": "lf", "hexgrouping": "4,8", "ifdef": "indent", "closingparen": "balanced", "selfrequired": "", "trailingclosures": ""]
|
||||
XCTAssertEqual(argumentsFor(.default), output)
|
||||
}
|
||||
|
||||
|
||||
@@ -207,7 +207,9 @@ class OptionsDescriptorTests: XCTestCase {
|
||||
}
|
||||
|
||||
func testDeprecatedPropertyList() {
|
||||
let controlArgumentNames = Set(["insertlines", "removelines", "hexliterals", "wrapelements", "experimental"])
|
||||
let controlArgumentNames = Set([
|
||||
"comments", "insertlines", "removelines", "hexliterals", "wrapelements", "experimental",
|
||||
])
|
||||
let descriptorArgumentNames = Set(FormatOptions.Descriptor.all.compactMap {
|
||||
$0.isDeprecated ? $0.argumentName : nil
|
||||
})
|
||||
|
||||
+4
-22
@@ -2396,36 +2396,18 @@ class RulesTests: XCTestCase {
|
||||
XCTAssertEqual(try format(input + "\n", rules: FormatRules.all), output + "\n")
|
||||
}
|
||||
|
||||
func testCommentIndentingDisabled() {
|
||||
let input = " /**\n hello\n - world\n */"
|
||||
let output = " /**\n hello\n - world\n */"
|
||||
let options = FormatOptions(indentComments: false, fragment: true)
|
||||
XCTAssertEqual(try format(input, rules: [FormatRules.indent], options: options), output)
|
||||
XCTAssertEqual(try format(input + "\n", rules: FormatRules.all, options: options), output + "\n")
|
||||
}
|
||||
|
||||
func testCommentIndentingDisabledInSwitch() {
|
||||
let input = "func foo() {\n switch bar {\n /** bar */\n default: break\n }\n}"
|
||||
let output = "func foo() {\n switch bar {\n /** bar */\n default: break\n }\n}"
|
||||
let options = FormatOptions(indentComments: false)
|
||||
XCTAssertEqual(try format(input, rules: [FormatRules.indent], options: options), output)
|
||||
XCTAssertEqual(try format(input + "\n", rules: FormatRules.all, options: options), output + "\n")
|
||||
}
|
||||
|
||||
func testCommentedCodeBlocksNotIndented() {
|
||||
let input = "func foo() {\n// var foo: Int\n}"
|
||||
let output = "func foo() {\n// var foo: Int\n}"
|
||||
let options = FormatOptions(indentComments: false)
|
||||
XCTAssertEqual(try format(input, rules: [FormatRules.indent], options: options), output)
|
||||
XCTAssertEqual(try format(input + "\n", rules: FormatRules.all, options: options), output + "\n")
|
||||
XCTAssertEqual(try format(input, rules: [FormatRules.indent]), output)
|
||||
XCTAssertEqual(try format(input + "\n", rules: FormatRules.all), output + "\n")
|
||||
}
|
||||
|
||||
func testBlankCodeCommentBlockLinesNotIndented() {
|
||||
let input = "func foo() {\n//\n}"
|
||||
let output = "func foo() {\n//\n}"
|
||||
let options = FormatOptions(indentComments: false)
|
||||
XCTAssertEqual(try format(input, rules: [FormatRules.indent], options: options), output)
|
||||
XCTAssertEqual(try format(input + "\n", rules: FormatRules.all, options: options), output + "\n")
|
||||
XCTAssertEqual(try format(input, rules: [FormatRules.indent]), output)
|
||||
XCTAssertEqual(try format(input + "\n", rules: FormatRules.all), output + "\n")
|
||||
}
|
||||
|
||||
// indent multiline strings
|
||||
|
||||
@@ -371,8 +371,6 @@ extension RulesTests {
|
||||
("testCommaRemovedFromLastItem", testCommaRemovedFromLastItem),
|
||||
("testCommentedCodeBlocksNotIndented", testCommentedCodeBlocksNotIndented),
|
||||
("testCommentIndenting", testCommentIndenting),
|
||||
("testCommentIndentingDisabled", testCommentIndentingDisabled),
|
||||
("testCommentIndentingDisabledInSwitch", testCommentIndentingDisabledInSwitch),
|
||||
("testCommentIndentingWithTrailingClose", testCommentIndentingWithTrailingClose),
|
||||
("testCommentNotRemovedInsideBraces", testCommentNotRemovedInsideBraces),
|
||||
("testCommentsNotDiscardedByElseOnSameLineRule", testCommentsNotDiscardedByElseOnSameLineRule),
|
||||
|
||||
Reference in New Issue
Block a user