• Stars
    star
    101
  • Rank 338,166 (Top 7 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 5 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

CSS complexity linter

constyble

A CSS complexity linter, based on css-analyzer. Don't let your CSS grow beyond the thresholds that you provide.

NPM Version Build Status Known Vulnerabilities XO code style Dependencies Status Dependencies Status Project: Wallace

Installation

npm install constyble
# or
yarn add constyble

Usage

We need a config with thresholds and CSS to compare it to.

# Default usage (assuming a .constyblerc file in the current directory)
$ constyble style.css

# Read from StdIn (assuming a .constyblerc file in the current directory)
$ cat style.css | constyble

# Custom config
$ constyble style.css --config my-config.json

The result will look like something like this:

TAP version 13
# Subtest: selectors.id.total
    ok 1 - selectors.id.total should not be larger than 0 (actual: 0)
    1..1
ok 1 - selectors.id.total # time=6.024ms

1..1
# time=15.076ms

Note that this example uses only 1 test (total ID selectors).

Config file

constyble will try to fetch a .constyblerc file in your current directory. You can also specify a different JSON config file with the --config option (see usage). The config JSON should look similar to this:

{
	// Do not exceed 4095, otherwise IE9 will drop any subsequent rules
	"selectors.total": 4095,
	"selectors.id.total": 0,
	"values.colors.totalUnique": 2,
	"values.colors.unique": ["#fff", "#000"]
}

All the possible options for the config file can be found at @projectwallace/css-analyzer. JSON comments are allowed.

Custom reporter

By default, constyble will report in the TAP format, but you can pipe the output into something you may find prettier, like tap-nyan, tap-dot or any other TAP-reporter.

tap-nyan

$ constyble style.css | tap-nyan

 1   -_,------,
 0   -_|   /\_/\
 0   -^|__( ^ .^)
     -  ""  ""
  Pass!

Usage in CI

If any test fails, constyble will exit with a non-zero exit code. When you run constyble in your CI builds, this may cause the build to fail. This is exactly what constyble was designed to do.

Example usage with package.json:

{
	"name": "my-package",
	"version": "0.1.0",
	"scripts": {
		"test": "constyble compiled-styles.css"
	},
	"devDependencies": {
		"constyble": "*"
	}
}

The name

constyble is a mix of the words Style and Constable. This package is like a police officer (constable) for your styles. Previously this package was called Gromit, but that was dropped because it's too closely related to the main 'Wallace' project that this package is part of.

Related projects

License

MIT © Bart Veneman

More Repositories

1

wallace-cli

Pretty CSS analytics on the CLI
JavaScript
519
star
2

css-analyzer

Analytics for CSS
CSS
300
star
3

color-sorter

Sort CSS colors by hue, then by saturation
JavaScript
65
star
4

css-code-quality

Calculate the Code Quality score of your CSS based on a range of different quality guards.
JavaScript
61
star
5

css-diff-action

Project Wallace GitHub Action to report CSS diffs to PR's
JavaScript
38
star
6

extract-css-core

Extract all CSS from a given url, both server side and client side rendered.
JavaScript
36
star
7

extract-css

Extract all CSS from a webpage, packaged as a Now V2 Lambda
JavaScript
27
star
8

format-css

Fast, small, zero-config library to format CSS using basic rules.
JavaScript
8
star
9

css-value-browser-h4cks-analyzer

A list of tests to determine whether a CSS value is considered a browser hack
JavaScript
4
star
10

push-css-action

Project Wallace GitHub Action to push new CSS to projectwallace.com automatically
JavaScript
3
star
11

og-image

Generate OpenGraph images for Project Wallace.
JavaScript
3
star
12

css-media-query-browser-h4cks-analyzer

A list of tests to determine whether an at-rule is considered a browser hack
JavaScript
3
star
13

css-time-sort

Sort an array of CSS <time> values.
JavaScript
2
star
14

api

JavaScript
2
star
15

has-css-accessibility-selector

A test to determine wether a selector contains an accessibility-related selector
JavaScript
1
star
16

browser-extension

A Browser Extension to fetch all CSS on a page and analyze it
1
star
17

minify-css

A small, fast, zero-config CSS minifier. No structural changes; only minifying.
JavaScript
1
star
18

css-property-browser-h4cks-analyzer

A list of tests to determine whether a CSS property is considered a browser hack
JavaScript
1
star
19

css-at-supports-browser-h4cks-analyzer

A list of tests to determine whether an `@supports` rule is considered a browser hack
JavaScript
1
star
20

has-css-universal-selector

A test to determine wether a selector contains a universal selector
JavaScript
1
star
21

constyble-continuous-integration-example

This repository demonstrates how to use Constyble in a project
CSS
1
star
22

css-selector-browser-h4cks-analyzer

A list of tests to determine whether a selector is considered a browser hack
JavaScript
1
star
23

css-selector-complexity

Calculate the Cyclomatic Complexity of a CSS selector
JavaScript
1
star
24

has-css-id-selector

A test to determine wether a selector contains an ID selector
JavaScript
1
star
25

has-css-js-selector

A test to determine wether a selector contains a JavaScript selector
JavaScript
1
star
26

stylelint-plugin

JavaScript
1
star
27

specificity

JavaScript
1
star