Skip to content

Commit

Permalink
fix review points: Use more strict condition, use simpler example
Browse files Browse the repository at this point in the history
  • Loading branch information
Ueeek committed Jan 5, 2025
1 parent e69e152 commit c63fa72
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ struct EmptyCountRule: Rule {
Example("[Int]().↓count == 0b00"),
Example("[Int]().↓count == 0o00"),
Example("↓count == 0"),
Example("let predicate = #Predicate<SwiftDataModel> { $0.list.↓count == 0 }"),
Example("#ExampleMacro { $0.list.↓count == 0 }"),
],
corrections: [
Example("[].↓count == 0"):
Expand Down Expand Up @@ -64,8 +64,8 @@ struct EmptyCountRule: Rule {
Example("isEmpty && [Int]().isEmpty"),
Example("[Int]().count != 3 && [Int]().↓count != 0 || ↓count == 0 && [Int]().count > 2"):
Example("[Int]().count != 3 && ![Int]().isEmpty || isEmpty && [Int]().count > 2"),
Example("let predicate = #Predicate<SwiftDataModel> { $0.list.↓count == 0 }"):
Example("let predicate = #Predicate<SwiftDataModel> { $0.list.isEmpty }"),
Example("#ExampleMacro { $0.list.↓count == 0 }"):
Example("#ExampleMacro { $0.list.isEmpty }"),
]
)
}
Expand Down Expand Up @@ -116,7 +116,7 @@ private extension EmptyCountRule {

override func visit(_ node: MacroExpansionExprSyntax) -> ExprSyntax {
if node.isTipsRuleMacro {
ExprSyntax(Syntax(node).cast(MacroExpansionExprSyntax.self))
ExprSyntax(node)
} else {
super.visit(node)
}
Expand Down Expand Up @@ -155,9 +155,9 @@ private extension TokenSyntax {

private extension MacroExpansionExprSyntax {
var isTipsRuleMacro: Bool {
self.macroName.text == "Rule" &&
self.arguments.isNotEmpty &&
self.trailingClosure != nil
macroName.text == "Rule" &&
arguments.count == 1 &&
trailingClosure.map { $0.statements.onlyElement?.item.is(ReturnStmtSyntax.self) == false } ?? false
}
}

Expand Down
6 changes: 3 additions & 3 deletions Tests/SwiftLintFrameworkTests/EmptyCountRuleTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ final class EmptyCountRuleTests: SwiftLintTestCase {
Example("[Int]().↓count == 0x00_00\n"),
Example("[Int]().↓count == 0b00\n"),
Example("[Int]().↓count == 0o00\n"),
Example("let predicate = #Predicate<SwiftDataModel> { $0.list.↓count == 0 }"),
Example("#ExampleMacro { $0.list.↓count == 0 }"),
]

let corrections = [
Expand Down Expand Up @@ -56,8 +56,8 @@ final class EmptyCountRuleTests: SwiftLintTestCase {
Example("count == 0 && [Int]().isEmpty"),
Example("[Int]().count != 3 && [Int]().↓count != 0 || count == 0 && [Int]().count > 2"):
Example("[Int]().count != 3 && ![Int]().isEmpty || count == 0 && [Int]().count > 2"),
Example("let predicate = #Predicate<SwiftDataModel> { $0.list.↓count == 0 }"):
Example("let predicate = #Predicate<SwiftDataModel> { $0.list.isEmpty }"),
Example("#ExampleMacro { $0.list.↓count == 0 }"):
Example("#ExampleMacro { $0.list.isEmpty }"),
]

let description = EmptyCountRule.description
Expand Down

0 comments on commit c63fa72

Please sign in to comment.