CSS Code Quality calculator

March 21, 2026 ยท View on GitHub

Analyzer logo
version downloads install size
Calculate the Code Quality score of your CSS based on a range of different quality guards.

This package analyzes your CSS on a high level and comes up with a score, divided into three areas:

  • Maintainability: how difficult is it for someone looking at the CSS from a high level to find the exact spot to fix a bug?
  • Complexity: how difficult is it for someone to make a change and be confident that they can make that change without side effects?
  • Performance: How likely is the CSS to have a negative impact on performance, based on high-level metrics? (Not including using hardware accelerated transforms and the like, because other tools are more suited for that.)

Installation

npm install @projectwallace/css-code-quality

Usage

import { calculate } from '@projectwallace/css-code-quality'

let css = `my_css { /* ... */ }`
let result = calculate(css)

/*
The result shape looks something like this:

{
  "violations": [ ],
  "passes": [ ],
  "performance": {
    "score": 90,
    "violations": [ ],
    "passes": [ ]
  },
  "maintainability": {
    "score": 100,
    "violations": [ ],
    "passes": [ ]
  },
  "complexity": {
    "score": 97,
    "violations": [ ],
    "passes": [ ]
  }
}

Each `passes` or `violations` array contains an object that looks like this:

{
  "id": "EmptyRules",
  "score": 0,
  "value": 0
},
{
  "id": "AverageSelectorsPerRule",
  "score": 0,
  "value": 1.5,
  "actuals": [
    2,
    1
  ]
}

etc. etc.

*/

Metrics

Performance

MetricWhat is testedPoints deducted
ImportsNumber of @import rules10 per @import
EmptyRulesNumber of empty rules1 per empty rule
SelectorDuplicationsRatio of duplicate selectorsUp to 10 (when uniqueness ratio < 66%)
DeclarationDuplicationsRatio of duplicate declarationsUp to 10 (when uniqueness ratio < 66%)
CssSizeTotal CSS file size5 if size exceeds 200,000 bytes
TooMuchCommentsTotal size of comments1 per 250 bytes of comments, max 10
TooMuchEmbeddedContentTotal size of embedded content (e.g. base64)1 per 250 bytes of embedded content, max 20

Maintainability

MetricWhat is testedPoints deducted
SourceLinesOfCodeTotal source lines of code1 per 1,000 lines over 10,000, max 15
AverageSelectorsPerRuleAverage number of selectors per rule5 per selector over 2 (average), max 15
AverageDeclarationsPerRuleAverage number of declarations per rule5 per declaration over 5 (average), max 15
MaxSelectorsPerRuleMaximum number of selectors in a single rule0.5 per selector over 10, max 15
MaxDeclarationsPerRuleMaximum number of declarations in a single rule0.5 per declaration over 10, max 15
MoreThanMostCommonSelectorsPerRuleRules that have more selectors than the most common count0.01 per rule, max 15 (when > 10% of rules exceed the mode)
MoreThanMostCommonDeclarationsPerRuleRules that have more declarations than the most common count0.01 per rule, max 15 (when > 10% of rules exceed the mode)

Complexity

MetricWhat is testedPoints deducted
MoreThanMostCommonSelectorComplexitySelectors more complex than the most common complexity0.01 per selector, max 10 (when > 10% of selectors exceed the mode)
MoreThanMostCommonSelectorSpecificitySelectors with higher specificity than the most common specificity0.01 per selector, max 10 (when > 10% of selectors exceed the mode)
MaxSelectorComplexityMaximum complexity of a single selector0.5 per complexity unit over 5, max 5
AverageSelectorComplexityAverage selector complexity2 per complexity unit over 2 (average), max 10
IdSelectorRatioRatio of ID selectorsUp to 5 (when ID selector ratio exceeds 1%)
ImportantRatioRatio of !important declarationsUp to 5 (when !important ratio exceeds 1%)
  • CSS Analyzer - A CSS Analyzer that goes through your CSS to find all kinds of relevant statistics.
  • Wallace CLI - CLI tool for @projectwallace/css-analyzer
  • Constyble - CSS Complexity linter
  • Color Sorter - Sort CSS colors by hue, saturation, lightness and opacity