Is there a reason why rubocop excludes top-level code when evaluating cyclomatic complexity? It only returns complexity for code independent paths through a method. Is there a way to include top-level code in this analysis?
Asked
Active
Viewed 102 times
1 Answers
0
Most complexity measures use def
as a scope.
It is assumed that code at top-level is meant to run only when the app/library is loaded and that all the actual code is within method definitions.
A file that does 30 require_relative
would bust most metrics, but it is not considered an issue.
Consider moving the actual code you are running in a method and calling it from the top level directly as first improvement.

Marc-André Lafortune
- 78,216
- 16
- 166
- 166