diff --git a/Rules.md b/Rules.md index 8fef5851..09b2426a 100644 --- a/Rules.md +++ b/Rules.md @@ -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"
diff --git a/Sources/Inference.swift b/Sources/Inference.swift index de452da2..9b7d3117 100644 --- a/Sources/Inference.swift +++ b/Sources/Inference.swift @@ -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]() diff --git a/Sources/OptionsDescriptor.swift b/Sources/OptionsDescriptor.swift index 734f579c..eb86e4a1 100644 --- a/Sources/OptionsDescriptor.swift +++ b/Sources/OptionsDescriptor.swift @@ -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", diff --git a/Sources/Rules.swift b/Sources/Rules.swift index b52357ca..42336e1f 100644 --- a/Sources/Rules.swift +++ b/Sources/Rules.swift @@ -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) } diff --git a/Tests/ArgumentsTests.swift b/Tests/ArgumentsTests.swift index a3e741c5..e67ffa41 100644 --- a/Tests/ArgumentsTests.swift +++ b/Tests/ArgumentsTests.swift @@ -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) } diff --git a/Tests/OptionsDescriptorTests.swift b/Tests/OptionsDescriptorTests.swift index 53af99fa..fae552ef 100644 --- a/Tests/OptionsDescriptorTests.swift +++ b/Tests/OptionsDescriptorTests.swift @@ -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 }) diff --git a/Tests/RulesTests.swift b/Tests/RulesTests.swift index 0dd6a8d6..08a0e3bf 100644 --- a/Tests/RulesTests.swift +++ b/Tests/RulesTests.swift @@ -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 diff --git a/Tests/XCTestManifests.swift b/Tests/XCTestManifests.swift index ea19f8b3..d3d2e501 100644 --- a/Tests/XCTestManifests.swift +++ b/Tests/XCTestManifests.swift @@ -371,8 +371,6 @@ extension RulesTests { ("testCommaRemovedFromLastItem", testCommaRemovedFromLastItem), ("testCommentedCodeBlocksNotIndented", testCommentedCodeBlocksNotIndented), ("testCommentIndenting", testCommentIndenting), - ("testCommentIndentingDisabled", testCommentIndentingDisabled), - ("testCommentIndentingDisabledInSwitch", testCommentIndentingDisabledInSwitch), ("testCommentIndentingWithTrailingClose", testCommentIndentingWithTrailingClose), ("testCommentNotRemovedInsideBraces", testCommentNotRemovedInsideBraces), ("testCommentsNotDiscardedByElseOnSameLineRule", testCommentsNotDiscardedByElseOnSameLineRule),