Fix empty_enum_arguments false positive when called expression is an identifier (#4600)

This commit is contained in:
Steffen Matthischke 2022-11-28 23:20:34 +01:00 committed by GitHub
parent d8d5e5bb43
commit 97ba82d740
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View File

@ -14,7 +14,10 @@
#### Bug Fixes #### Bug Fixes
* None. * Fix false positives in `empty_enum_arguments` when the called expression
is an identifier or an init call.
[Steffen Matthischke](https://github.com/heeaad)
[#4597](https://github.com/realm/SwiftLint/issues/4597)
## 0.50.1: Artisanal Clothes Pegs Fixup Edition ## 0.50.1: Artisanal Clothes Pegs Fixup Edition

View File

@ -41,6 +41,8 @@ struct EmptyEnumArgumentsRule: SwiftSyntaxCorrectableRule, ConfigurationProvider
wrapInSwitch("case \"bar\".uppercased()"), wrapInSwitch("case \"bar\".uppercased()"),
wrapInSwitch(variable: "(foo, bar)", "case (_, _) where !something"), wrapInSwitch(variable: "(foo, bar)", "case (_, _) where !something"),
wrapInSwitch("case (let f as () -> String)?"), wrapInSwitch("case (let f as () -> String)?"),
wrapInSwitch("case .bar(Baz())"),
wrapInSwitch("case .bar(.init())"),
wrapInSwitch("default"), wrapInSwitch("default"),
Example("if case .bar = foo {\n}"), Example("if case .bar = foo {\n}"),
Example("guard case .bar = foo else {\n}"), Example("guard case .bar = foo else {\n}"),
@ -65,6 +67,8 @@ struct EmptyEnumArgumentsRule: SwiftSyntaxCorrectableRule, ConfigurationProvider
wrapInSwitch("case .bar↓()"), wrapInSwitch("case .bar↓()"),
wrapInSwitch("case .bar↓(_), .bar2↓(_)"), wrapInSwitch("case .bar↓(_), .bar2↓(_)"),
wrapInSwitch("case .bar↓() where method() > 2"), wrapInSwitch("case .bar↓() where method() > 2"),
wrapInSwitch("case .bar(.baz↓())"),
wrapInSwitch("case .bar(.baz↓(_))"),
wrapInFunc("case .bar↓(_)"), wrapInFunc("case .bar↓(_)"),
Example("if case .bar↓(_) = foo {\n}"), Example("if case .bar↓(_) = foo {\n}"),
Example("guard case .bar↓(_) = foo else {\n}"), Example("guard case .bar↓(_) = foo else {\n}"),
@ -89,6 +93,8 @@ struct EmptyEnumArgumentsRule: SwiftSyntaxCorrectableRule, ConfigurationProvider
wrapInSwitch("case .bar↓()"): wrapInSwitch("case .bar"), wrapInSwitch("case .bar↓()"): wrapInSwitch("case .bar"),
wrapInSwitch("case .bar↓(_), .bar2↓(_)"): wrapInSwitch("case .bar, .bar2"), wrapInSwitch("case .bar↓(_), .bar2↓(_)"): wrapInSwitch("case .bar, .bar2"),
wrapInSwitch("case .bar↓() where method() > 2"): wrapInSwitch("case .bar where method() > 2"), wrapInSwitch("case .bar↓() where method() > 2"): wrapInSwitch("case .bar where method() > 2"),
wrapInSwitch("case .bar(.baz↓())"): wrapInSwitch("case .bar(.baz)"),
wrapInSwitch("case .bar(.baz↓(_))"): wrapInSwitch("case .bar(.baz)"),
wrapInFunc("case .bar↓(_)"): wrapInFunc("case .bar"), wrapInFunc("case .bar↓(_)"): wrapInFunc("case .bar"),
Example("if case .bar↓(_) = foo {"): Example("if case .bar = foo {"), Example("if case .bar↓(_) = foo {"): Example("if case .bar = foo {"),
Example("guard case .bar↓(_) = foo else {"): Example("guard case .bar = foo else {"), Example("guard case .bar↓(_) = foo else {"): Example("guard case .bar = foo else {"),
@ -193,7 +199,9 @@ private extension PatternSyntax {
private extension FunctionCallExprSyntax { private extension FunctionCallExprSyntax {
var argumentsHasViolation: Bool { var argumentsHasViolation: Bool {
argumentList.allSatisfy(\.expression.isDiscardAssignmentOrFunction) !calledExpression.is(IdentifierExprSyntax.self) &&
calledExpression.as(MemberAccessExprSyntax.self)?.lastToken?.tokenKind != .initKeyword &&
argumentList.allSatisfy(\.expression.isDiscardAssignmentOrFunction)
} }
var innermostFunctionCall: FunctionCallExprSyntax { var innermostFunctionCall: FunctionCallExprSyntax {