The ratchet technique - how to prevent new shit code from joining your code
There's a common problem that happens when new linters are added to an existing codebase.
Let's say we have 50K rows of exeisting code and we want to add a new shiny linter that makes sure all module names are Harry Potter characters.
We run the new linter for the first time and it finds 1337 linting violations. We want to prevent new code from violating these rules but we don't have the time to fix the old code at the moment.
This is where the "Ratchet technique" comes in!
We start by adding a CI merge gate workflow that counts the number of violations (1337) and ensures the number never increases.
- If someone commits new code that doesn't adhere to the new standard, the PR checks will fail.
- Old non-compliant code can stay bad until we have the time to fix it.
This method halts code degredation without any major refactoring.
Funny new behavior that was observed in the wild - developers will fix an old linter errors so they can add their new linter errors in place and keep the violations counter the same. (IMO that's a small win for everyone) ¯\_(ツ)_/¯