Is there a way to make cane ignore log messages?
For example, we have log messages that look like this:
logger.debug { "something happened that you should know about" }
This adds complexity to a method, but it’s necessary complexity so I don’t want it counted in the ABC complexity measurement.
Removing the block around the debug statement will reduce the complexity, but it also slows down the code since the strings must be evaluated as the method runs. We need the speed gains.
There isn’t a way to do this out of the box, but you could customize the
AbcCheckto add exceptions for certain AST nodes: https://github.com/square/cane/blob/master/lib/cane/abc_check.rb#L51In practice, I have found that if the logging in a method added so much complexity as to be a problem it usually made sense to break up that method. If not, remember that lower isn’t always better. The goal of cane is to prevent you from accidentally committing complex methods, not to reward you for having the lowest score.
There is also now functionality to exclude certain files, which doesn’t address your question directly, but may be helpful. See “Defining Exclusions” section of the README.