user8710949
user8710949

Reputation: 17

Rubocop cyclomatic complexity of top-level code

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?

Upvotes: 0

Views: 125

Answers (1)

Marc-André Lafortune
Marc-André Lafortune

Reputation: 79592

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.

Upvotes: 0

Related Questions