Skip to content

Designing a dead code detection rule that needs to analyze across files #2431

Closed
@elliottwilliams

Description

I'm looking into the whether it would be possible to create an analyzer rule to detect dead code in a project. It seems like this is totally doable with CursorInfo requests, but I'm at a loss for how a rule like this would integrate into SwiftLint.

For dead code detection to be useful, it has to work between files: it should build up a set of referenced declarations across a project, and then look at the declarations in a file to determine whether that declaration is ever referenced. This means that to lint any single file, the whole project (i.e. the other files given to SwiftLint) needs to be analyzed first.

Since SwiftLint rules are designed to run per-file, in isolation, I'm not sure how I would build this rule. Could it make a pass over every file to build a references set, and then run again on each file to perform actual linting? Should I write a separate script to build a references set, and pass it to SwiftLint via a command line argument? Are multi-file rules something SwiftLint wants to support in the future?

New Issue Checklist

Metadata

Assignees

No one assigned

    Labels

    rule-requestRequests for a new rules.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions