Skip to content

Commit

Permalink
Rename strongSelfIds to disallowedIds
Browse files Browse the repository at this point in the history
  • Loading branch information
krunk4ever committed Jan 3, 2020
1 parent 68131f1 commit 5f6b8b2
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -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


<details>
Expand Down
6 changes: 3 additions & 3 deletions Sources/Options.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions Sources/OptionsDescriptor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ extension FormatOptions.Descriptor {
tabWidth,
maxWidth,
noSpaceOperators,
strongSelfIds,
disallowedIds,

// Deprecated
indentComments,
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions Sources/Rules.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions Tests/ArgumentsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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"])
}
}
2 changes: 1 addition & 1 deletion Tests/RulesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion Tests/XCTestManifests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ extension ArgumentsTests {
("testParseQuoteArguments", testParseQuoteArguments),
("testParseQuotedEscapedN", testParseQuotedEscapedN),
("testParseSimpleArguments", testParseSimpleArguments),
("testParseStrongSelfIds", testParseStrongSelfIds),
("testParseDisallowedIds", testParseDisallowedIds),
("testParseUnexcludedURLsFileOption", testParseUnexcludedURLsFileOption),
("testParseUppercaseIgnoreFileHeader", testParseUppercaseIgnoreFileHeader),
("testPreprocessArguments", testPreprocessArguments),
Expand Down

0 comments on commit 5f6b8b2

Please sign in to comment.