Implementing multi-file analysis for linters

submited by
Style Pass
2023-03-24 08:30:05

Recently I’ve been in a few discussions about adding support for multi-file analysis in several single-file linters. I believe that to be an amazing feature and that it is done quite well in elm-review, so I wanted to write down how it works to help other tools do the same. Hopefully it will be interesting for non-tooling authors as well!

Single-file analysis in a linter means that a rule looks at files in isolation, whereas multi-file analysis means a rule can analyze multiple files together — up to entire projects — and report issues based on what it found in the different files.

For a single-file linter, whenever a rule analyzes a file, it may discover some errors. It then goes on to the next file doing the same thing, completely forgetting about the contents of the previous file and whatever insights it discovered in there, only keeping the reported errors.

In elm-review, the original and first use-case was to prevent false reports by getting more information, mostly around how imports can hide certain necessary details.

Leave a Comment