Skip to content

Instantly share code, notes, and snippets.

@nunosilva800
Last active January 22, 2016 21:48
Show Gist options
  • Save nunosilva800/dfcfd98267041ebdff02 to your computer and use it in GitHub Desktop.
Save nunosilva800/dfcfd98267041ebdff02 to your computer and use it in GitHub Desktop.
RubyCritic's Rating and Score

Rating and Score

When RubyCritic runs, each analysed class or module gets assigned a rating - a letter from A to F, A being the best. This serves as a baseline to tell you how smelly the code is. Generally A's & B's are good enough, C's serve as a warning and D's & F's are the ones you should be fixing.

Similarly, a global score that ranges from 0 to 100 is calculated, where higher values are better - less code smells detected. This provides a quick insight about the overall code quality.

RubyCritic's rating system was inspired by Code Climate's, you can read more about how that works here. Note that the global score is fairly different from Code Climate's GPA, although it serves the same purpose.

How are ratings calculated?

As you know RubyCritic wraps around static analysis gems such as Reek, Flay and Flog to provide a quality report of your Ruby code.

Each of these gems are considered an Analyser that have a list of AnalysedModules, which have the notion of cost and rating.

Rating is simply a convertion from a number (cost) to a letter. So we need to understand what defines the cost of an AnalysedModule:

Cost

Each AnalysedModule basic goal is to catalog smells in the code analysed, assiging a number defined as cost. The definition of this cost varies from tool to tool, but it's always a non-negative number, with high values indicating more cost (worse smells).

How is the global score calculated?

This is basically an average of the cost of each AnalysedModule, scaled to the range [0..100]. There is a threshold to avoid very bad modules from having excessive impact.

@troessner
Copy link

3 points:

1.)

D's & F's

Should be

D's, E's and F's

shouldn't it?

Edit: Just realized we don't have "E" which I find highly confusing since it seems to be alphabetical when it's not :(

2.)

Rating is simply a convertion from a number (cost) to a letter.

"conversion"

3.) This just shows how confusing our rating system is. Look at this:

Each AnalysedModule basic goal is to catalog smells in the code analysed, assiging a number defined as cost. The definition of this cost varies from tool to tool, but it's always a non-negative number, with high values indicating more cost

Ok, the higher the value the more cost, the worse it is. Understood!
Now let's look at the next paragraph:

This is basically an average of the cost of each AnalysedModule, scaled to the range [0..100].

Ok, "average of cost". But above we say that "the higher the number of the score, the better".
So we have two completely orthogonal metrics. Costs == "the higher, the worse". And the "score" == "the higher, the better".

I know that we can't fix this right now since this would be a bigger pull request, but we should make the difference crystal clear in our docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment