What is stylelint-config-standard?
The stylelint-config-standard package is an extensible shared configuration for Stylelint, which is a mighty, modern linter that helps you avoid errors and enforce conventions in your styles. It is considered the standard configuration for Stylelint, providing a sensible default configuration that enforces common stylistic conventions for CSS.
What are stylelint-config-standard's main functionalities?
Extensible Configuration
This package provides a base set of rules for Stylelint, which can be extended in a project's .stylelintrc configuration file. By extending stylelint-config-standard, you inherit a standard set of rules that can be customized further.
{
"extends": "stylelint-config-standard"
}
Enforce Stylistic Conventions
The package enforces stylistic conventions such as lowercase hex colors, indentation levels, and leading zeros in numbers. These rules help maintain consistency across your project's stylesheets.
{
"rules": {
"color-hex-case": "lower",
"indentation": 2,
"number-leading-zero": "always"
}
}
Customizable Rules
While it provides a standard set of rules, it also allows for customization. Developers can override or extend the rules to fit their project's specific needs, such as allowing certain at-rules that are not part of CSS specifications but are used by preprocessors.
{
"extends": "stylelint-config-standard",
"rules": {
"at-rule-no-unknown": [ true, {
"ignoreAtRules": ["extends", "ignores"]
}]
}
}
Other packages similar to stylelint-config-standard
stylelint-config-recommended
This package is a lighter version of the standard configuration, focusing on possible error rules rather than stylistic rules. It's a good starting point for projects that want to enforce error checking without imposing stylistic choices.
stylelint-config-sass-guidelines
This package extends stylelint-config-standard and adds rules specific to Sass, such as those for nesting depth, name formats, and other conventions. It's tailored for projects that use Sass and want to adhere to common guidelines.
stylelint-prettier
This package integrates Stylelint with Prettier, an opinionated code formatter. It disables all rules that might conflict with Prettier, allowing developers to use Stylelint for linting and Prettier for formatting.
stylelint-config-standard
The standard shareable config for stylelint.
Use it as is or as a foundation for your own config.
It is derived from the common rules found within a handful of CSS styleguides, including: The Idiomatic CSS Principles,
Github's PrimerCSS Guidelines,
Google's CSS Style Guide, Airbnb's Styleguide, and @mdo's Code Guide.
It favours flexibility over strictness for things like multi-line lists and single-line rulesets, and tries to avoid potentially divisive rules.
Example
.selector-1,
.selector-2,
.selector-3[type="text"] {
background: linear-gradient(#fff, rgba(0, 0, 0, 0.8));
box-sizing: border-box;
display: block;
color: #333;
}
.selector-a,
.selector-b {
padding: 10px !important;
top: calc(calc(1em * 2) / 3);
}
.selector-x { width: 10%; }
.selector-y { width: 20%; }
.selector-z { width: 30%; }
@media (min-width >= 60em) {
.selector {
transform: translate(1, 1) scale(3);
}
}
@media (min-orientation: portrait), projection and (color) {
.selector-i + .selector-ii {
background: color(rgb(0, 0, 0) lightness(50%));
font-family: helvetica, arial, sans-serif;
}
}
@media screen and (min-device-pixel-ratio: 2),
screen and (min-resolution: 192dpi),
screen and (min-resolution: 2dppx) {
.selector {
background-image:
repeating-linear-gradient(
-45deg,
transparent,
#fff 25px,
rgba(255, 255, 255, 1) 50px
);
margin: 10px;
margin-bottom: 5px;
box-shadow:
0 1px 1px #000,
0 1px 0 #fff,
2px 2px 1px 1px #ccc inset;
height: 10rem;
}
.selector::after {
content: "→";
background-image: url("x.svg");
}
}
Note: the config is tested against this example, as such the example contains plenty of CSS syntax, formatting and features.
Installation
$ npm install stylelint-config-standard
Usage
Set your stylelint config to:
{
"extends": "stylelint-config-standard"
}
Extending the config
Simply add a "rules"
key to your config and add your overrides there.
For example, to change the indentation
to tabs and turn off the number-leading-zero
rule:
{
"extends": "stylelint-config-standard",
"rules": {
"indentation": "tab",
"number-leading-zero": null
}
}