Lint only changed files in a git PR

Nice guide to lint only changed files (git)

Typically, code linters will lint the entire project and report back any violations across any file. This very safely accomplishes catching any error in a compliant project, but makes gradual adoption very hard. It’s 100% buy-in and you can’t get the rewards until you’ve finished the process.

What if instead we state “all new code should adopt these rules”. For each pull request, lint only the files that contain changes. Don’t bother linting files that this PR has left alone, because it’s not a regression and PRs need to have discipline in the tasks they complete. Over time, however, we might expect to see much of the codebase transformed, with maybe a little task at the end to clean up odds and ends. We can transform a big-upfront cost into a much more manageable process and de-risk the project significantly by gradually adopting a styleguide instead of Big Refactor Upfront™.