Skip to content

Redundant type casting in generated visit methods of SyntaxRewriter #2102

Closed
@Matejkob

Description

@Matejkob

Description

In the SyntaxRewriter implementation, I noticed that many visit methods are written in the following format:

open func visit(_ node: AttributeListSyntax) -> AttributeListSyntax {
    return Syntax(visitChildren(node)).cast(AttributeListSyntax.self)
}

Since the node argument is already of type AttributeListSyntax, and the visitChildren(node) method returns the same type, the type casting using .cast(AttributeListSyntax.self) appears to be redundant and unnecessary.

Suggested Improvement:

Consider refactoring the generated visit methods to remove this redundant type casting and Syntax wrapping. The improved version would look like:

open func visit(_ node: AttributeListSyntax) -> AttributeListSyntax {
    return visitChildren(node)
}

This simplification would make the codebase cleaner, more readable, and reduce potential points of failure.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions