How to start managing cyclomatic complexity for legacy code
I have a codebase with high cyclomatic complexity (mono repo with services and deployment scripts). I want to start managing its complexity.
The good option is to add # noqa: C901 for each function that has high complexity. This solves the problem that new functions will be written in a good way.
But the problems with the existing one are still there.
1) If your function has a bad complexity you can grow it further. If your script has a single function that means you don't control the complexity at all.
2) When the function is refactored it's a good chance that the suppression won't be removed. So it could grow back.
I am looking for a solution to these problems.
In general, it could look like the mapping between function name and current complexity. We check for exact matches and fix the function or mapping. So the complexity won't grow from one side, and suppression will always be actual.
The mapping could be implemented by adding a number to the suppression comment or via a config file.
If the solution for my problem doesn't exist yet, I could implement it myself. (code, tests, documentation, helper scripts, etc.)
Best regards, Andrey Solomatin