racodond / sonar-css-plugin

SonarQube CSS / SCSS / Less Analyzer
GNU Lesser General Public License v3.0
48 stars 27 forks source link
code-quality css guidelines less linter scss sonarqube sonarqube-plugin static-analysis static-analyzer styleguide stylelint

Release Build Status Build status

Quality Gate status Lines of Code Coverage

SonarQube CSS / SCSS / Less Analyzer

Disclaimer

I don't want to keep maintaining this plugin. Feel free to ping me if you want to take over.

Description

This SonarQube plugin analyzes:

and:

Usage

Installation Guide

  1. Download and install SonarQube
  2. Install the CSS / SCSS / Less plugin by a direct download. The latest version is compatible with SonarQube 6.7+.
  3. Install your favorite scanner (SonarQube Scanner, Maven, Ant, etc.)
  4. Analyze your code

Analyzing CSS code embedded in HTML/XHTML files

The plugin analyzes CSS code embedded in <style type="text/css">...</style> tags in HTML/XHTML files. To do so, as a prerequisite, SonarQube has to import those files. Either:

The list of files containing embedded CSS to analyze can be customized through the sonar.css.embedded.file.suffixes property.

stylelint / SonarQube Rule Mapping

If you are already using stylelint, adding SonarQube to your stack will help you bring code quality to another level. The stylelint / SonarQube rule mapping may be of great help to define your SonarQube quality profile.

Custom Checks

You're thinking of new valuable checks? Version 2.1 or greater provides an API to write your own custom checks. A sample plugin with detailed explanations is available here. If your custom checks may benefit the community, feel free to create a pull request in order to make the check available in the CSS / SCSS / Less analyzer.

You're thinking of new checks that may benefit the community but don't have the time or the skills to write them? Feel free to create an issue for your checks to be taken under consideration.

Metrics

Functions

Number of rules.

Complexity

The following elements increment the complexity by one:

Complexity/function

It computes the complexity/rule, meaning the average number of selectors per rule. It gives a measurement on how specific the selectors are.

Available Rules

Common to CSS and SCSS and Less

Specific to CSS

Specific to CSS embedded in HTML/XHTML

Specific to SCSS

Specific to Less