diff --git a/Rules.md b/Rules.md index 63425e88e..954ac44a4 100644 --- a/Rules.md +++ b/Rules.md @@ -1304,7 +1304,7 @@ Standardize on using self when strongifying self. Will also remove backticks aro Option | Description --- | --- -`--strongselfids` | Comma-delimited list of identifiers that should be replaced with self +`--disallowedids` | Comma-delimited list of disallowed identifiers that should be replaced with self
diff --git a/Sources/Options.swift b/Sources/Options.swift index 8932b4b17..efc825019 100644 --- a/Sources/Options.swift +++ b/Sources/Options.swift @@ -263,7 +263,7 @@ public struct FormatOptions: CustomStringConvertible { public var tabWidth: Int public var maxWidth: Int public var noSpaceOperators: [String] - public var strongSelfIds: [String] + public var disallowedIds: [String] // Deprecated public var indentComments: Bool @@ -315,7 +315,7 @@ public struct FormatOptions: CustomStringConvertible { tabWidth: Int = 0, maxWidth: Int = 0, noSpaceOperators: [String] = [], - strongSelfIds: [String] = [], + disallowedIds: [String] = [], // Doesn't really belong here, but hard to put elsewhere fragment: Bool = false, ignoreConflictMarkers: Bool = false, @@ -359,7 +359,7 @@ public struct FormatOptions: CustomStringConvertible { self.tabWidth = tabWidth self.maxWidth = maxWidth self.noSpaceOperators = noSpaceOperators - self.strongSelfIds = strongSelfIds + self.disallowedIds = disallowedIds // Doesn't really belong here, but hard to put elsewhere self.fragment = fragment self.ignoreConflictMarkers = ignoreConflictMarkers diff --git a/Sources/OptionsDescriptor.swift b/Sources/OptionsDescriptor.swift index da6138b65..2b516449c 100644 --- a/Sources/OptionsDescriptor.swift +++ b/Sources/OptionsDescriptor.swift @@ -252,7 +252,7 @@ extension FormatOptions.Descriptor { tabWidth, maxWidth, noSpaceOperators, - strongSelfIds, + disallowedIds, // Deprecated indentComments, @@ -578,12 +578,12 @@ extension FormatOptions.Descriptor { } } ) - static let strongSelfIds = FormatOptions.Descriptor( - argumentName: "strongselfids", - propertyName: "strongSelfIds", + static let disallowedIds = FormatOptions.Descriptor( + argumentName: "disallowedids", + propertyName: "disallowedIds", displayName: "Strongified Self Identifiers", help: "Comma-delimited list of identifiers that should be replaced with self", - keyPath: \FormatOptions.strongSelfIds + keyPath: \FormatOptions.disallowedIds ) // MARK: - Internal diff --git a/Sources/Rules.swift b/Sources/Rules.swift index 73c603927..16816998c 100644 --- a/Sources/Rules.swift +++ b/Sources/Rules.swift @@ -3761,13 +3761,13 @@ public struct _FormatRules { /// Standardize on using self when strongifying self. Will also remove backticks around `self` in Optional unwrap expressions. public let strongifiedSelf = FormatRule( help: "Standardize on using self when strongifying self. Will also remove backticks around `self` in Optional unwrap expressions.", - options: ["strongSelfIds"] + options: ["disallowedIds"] ) { formatter in guard formatter.options.swiftVersion >= "4.2" else { return } - let strongSelfIds = formatter.options.strongSelfIds + ["`self`"] - strongSelfIds.forEach { idName in + let disallowedIds = formatter.options.disallowedIds + ["`self`"] + disallowedIds.forEach { idName in formatter.forEach(.identifier(idName)) { i, _ in guard let equalIndex = formatter.index(of: .nonSpaceOrCommentOrLinebreak, after: i, if: { $0 == .operator("=", .infix) diff --git a/Tests/ArgumentsTests.swift b/Tests/ArgumentsTests.swift index b87cf1163..ac9602409 100644 --- a/Tests/ArgumentsTests.swift +++ b/Tests/ArgumentsTests.swift @@ -200,7 +200,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", "hexliteralcase": "uppercase", "linebreaks": "lf", "hexgrouping": "4,8", "ifdef": "indent", "closingparen": "balanced", "selfrequired": "", "trailingclosures": "", "xcodeindentation": "disabled", "fragment": "false", "conflictmarkers": "reject", "tabwidth": "unspecified", "maxwidth": "none", "nospaceoperators": "", "strongselfids": ""] + 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", "hexliteralcase": "uppercase", "linebreaks": "lf", "hexgrouping": "4,8", "ifdef": "indent", "closingparen": "balanced", "selfrequired": "", "trailingclosures": "", "xcodeindentation": "disabled", "fragment": "false", "conflictmarkers": "reject", "tabwidth": "unspecified", "maxwidth": "none", "nospaceoperators": "", "disallowedids": ""] XCTAssertEqual(argumentsFor(.default), output) } @@ -558,8 +558,8 @@ class ArgumentsTests: XCTestCase { XCTAssertEqual(options.formatOptions?.noSpaceOperators, ["...", "..<"]) } - func testParseStrongSelfIds() throws { - let options = try Options(["strongselfids": "ss,sSelf,strongSelf"], in: "") - XCTAssertEqual(options.formatOptions?.strongSelfIds, ["ss", "sSelf", "strongSelf"]) + func testParseDisallowedIds() throws { + let options = try Options(["disallowedids": "ss,sSelf,strongSelf"], in: "") + XCTAssertEqual(options.formatOptions?.disallowedIds, ["ss", "sSelf", "strongSelf"]) } } diff --git a/Tests/RulesTests.swift b/Tests/RulesTests.swift index bd076dbb0..a333dbc95 100644 --- a/Tests/RulesTests.swift +++ b/Tests/RulesTests.swift @@ -8461,7 +8461,7 @@ class RulesTests: XCTestCase { guard let self = self else { return } } """ - let options = FormatOptions(strongSelfIds: ["strongSelf"], swiftVersion: "4.2") + let options = FormatOptions(disallowedIds: ["strongSelf"], swiftVersion: "4.2") testFormatting(for: input, output, rule: FormatRules.strongifiedSelf, options: options) } diff --git a/Tests/XCTestManifests.swift b/Tests/XCTestManifests.swift index d1c4cb8b6..2e517528a 100644 --- a/Tests/XCTestManifests.swift +++ b/Tests/XCTestManifests.swift @@ -55,7 +55,7 @@ extension ArgumentsTests { ("testParseQuoteArguments", testParseQuoteArguments), ("testParseQuotedEscapedN", testParseQuotedEscapedN), ("testParseSimpleArguments", testParseSimpleArguments), - ("testParseStrongSelfIds", testParseStrongSelfIds), + ("testParseDisallowedIds", testParseDisallowedIds), ("testParseUnexcludedURLsFileOption", testParseUnexcludedURLsFileOption), ("testParseUppercaseIgnoreFileHeader", testParseUppercaseIgnoreFileHeader), ("testPreprocessArguments", testPreprocessArguments),