Skip to content

Commit

Permalink
Fix syntactic_sugar
Browse files Browse the repository at this point in the history
  • Loading branch information
jpsim committed Sep 30, 2022
1 parent 1186c21 commit 4542647
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
24 changes: 6 additions & 18 deletions Source/SwiftLintFramework/Rules/Idiomatic/SyntacticSugarRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -137,24 +137,6 @@ private final class SyntacticSugarRuleVisitor: SyntaxVisitor {
}
}

override func visitPost(_ node: AsExprSyntax) {
// json["recommendations"] as? ↓Array<[String: Any]>
if let violation = violation(in: node.typeName) {
violations.append(violation)
}
}

override func visitPost(_ node: UnresolvedAsExprSyntax) {
// json["recommendations"] as? ↓Array<[String: Any]>
if
let parent = node.parent,
let typeName = parent.children(viewMode: .sourceAccurate).last?.as(TypeExprSyntax.self),
let violation = violation(in: typeName.type)
{
violations.append(violation)
}
}

override func visitPost(_ node: TypeInitializerClauseSyntax) {
// typealias Document = ↓Dictionary<String, AnyBSON?>
if let violation = violation(in: node.value) {
Expand Down Expand Up @@ -205,6 +187,12 @@ private final class SyntacticSugarRuleVisitor: SyntaxVisitor {
.map { violations.append($0) }
}

override func visitPost(_ node: TypeExprSyntax) {
if let violation = violation(in: node.type) {
violations.append(violation)
}
}

private func violation(in typeSyntax: TypeSyntax?) -> SyntacticSugarRuleViolation? {
if let optionalType = typeSyntax?.as(OptionalTypeSyntax.self) {
return violation(in: optionalType.wrappedType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ internal enum SyntacticSugarRuleExamples {
Example("""
@_specialize(where S == ↓Array<Character>)
public init<S: Sequence>(_ elements: S)
"""),

Example("""
let dict: [String: Any] = [:]
_ = dict["key"] as? ↓Optional<String?> ?? Optional<String?>.none
""")
]

Expand Down

0 comments on commit 4542647

Please sign in to comment.