Maintainability Metrics and Ratings

Request early access

This page describes features that are in private beta. Request early access to get them sooner.

Qlty provides detailed code quality metrics and ratings to help you understand and improve the maintainability of your codebase. Here’s a rundown of all of them.

Metrics

Lines of Code

Out of the total lines in a file, Qlty differentiates between blank lines, comment lines and lines of code. Our lines of code metric represents executable lines in a file, without counting comments and blank lines.

Issues

Issues are findings from analysis that Qlty runs on your codebase. They can range from complexity and duplication issues, to lint results from supported plugins like ESLint, Semgrep, and Clippy.

Code Smells

Code smells are indicators of maintainability problems in the code that may not be bugs but could lead to issues in the future. Qlty’s analysis finds code smells as issues in the Duplication and Structure categories.

When using the CLI, you can run the qlty smells command to analyze your codebase for smells. The output will be a list of duplication and/or structure issues.

Vulnerabilities

Vulnerabilities are security-related issues.

Issue Levels

Qlty issues come with a Level which represents severity. We use a simple level system of high, medium, and low. You can use the level attribute to assess priorities when fixing issues in your codebase.

Effort

This metric is an estimate of the time in minutes that a developer may invest to remediate a code smell. Qlty calculates this number for duplication and structure issues. This number is used to help compute your codebase’s technical debt.

Complexity

Code complexity is a measure of the difficulty to understand, test and maintain code. The higher the complexity, the more difficult it will be to achieve clean, readable and maintainable code.

Complexity

In Qlty, we use the term Complexity to refer to cognitive complexity. Cognitive complexity measures how difficult it is for a human to understand a piece of code. It takes into account the structural elements that affect readability and understandability, unlike cyclomatic complexity, which only counts the number of branches.

For example, deeply nested code, complex conditionals, and the use of recursion can increase cognitive complexity.

Cyclomatic Complexity

Cyclomatic complexity, sometimes referred to as McCabe’s complexity, is a count of the linearly independent paths through source code. You can also think of this more simply as “the number of decisions a given block of code needs to make”. As the code branches out into different paths using constructs like if-else statements and loops, the cyclomatic complexity increases.

For example, a simple function with no branching (if-else statements, loops) has a cyclomatic complexity of 1. Each additional branch increases the complexity by 1.

Duplication

Code duplication measures the amount of code that is repeated in a similar or identical form within the project. Reducing duplication helps in maintaining DRY (Don’t Repeat Yourself) principles, making the code easier to maintain and less error-prone.

Duplication is calculated as the percentage of lines that are duplicated in your code. For example, if a file has 100 lines and 10 of those lines are duplicated, the duplication percentage is 10%.

Technical Debt

Technical Debt sums the total effort (or remediation time) of the maintainability issues (structure and duplication) within a unit of code. This estimates how long it would take to improve the code to a high level of maintainability.

Technical Debt Ratio

The Technical Debt Ratio is obtained by dividing the Technical Debt to fix all the code smells by the estimated effort to rewrite the code from scratch. The higher the ratio, the more challenging a project will be to maintain and iterate over time.

Qlty uses the Basic Constructive Cost Model (COCOMO) to estimate the time in person-months required to develop a software project.

For example, if resolving all code smells in a project is estimated to take 3 weeks, and we estimate the project required 30 weeks to develop, the technical debt ratio would be 10%.

Ratings

There are a number of ratings that are computed using your project’s metrics. Ratings helpe make code quality information easy to understand at a glance. They can be observed at a project level, as well as directory and file level.

Size

This rating represents the total lines of code, counting comments and blank lines.

  • At a project level, you can see a T-shirt size rating that estimates the size of your project with the following definition:
Lines of codeSize
less than 1kXS
less than 10kS
less than 100kM
500k or lessL
more than 500kXL
  • At a directory level, you can see the sum of the lines in each file under that folder.
  • At a file level, you can see the line count in the file.

Maintainability

The maintainability rating is a letter grade that is given depending on your technical debt or effort metrics.

  • At a project level, the letter grades are defined based on your technical debt ratio, like this:
Technical Debt RatioRating
less than 5%A
5% to 10%B
10% to 20%C
20% to 50%D
50% or moreF
  • At a file and directory level, the grades are calculated using a logorithmic function based on the total Technical Debt.

Duplication

This is the percentage of the lines that are duplicated in your code. You can see this metric at project, directory, and file level as the division between the count of duplicated lines over the total lines of code.

Coverage

Code coverage refers to the percentage of lines of code which are executed by automated unit tests. You can see this as a letter grade in your project, directory, and file views.

At all levels, the coverage rating is calculated as the division between the count of covered lines over the relevant lines of code. Lines that are considered irrelevant to the supported coverage tools are not counted in the total.

The grade is then defined as follows:

Coverage %Grade
90% or moreA
80% to 90%B
70% to 80%C
60% to 70%D
less than 60%F