This repository contains the defacto-standard stylelint configuration used on all Netsells projects, both internally and client.
Add the config to your project dependencies:
yarn add @netsells/stylelint-config
Now extend the config in your project. For example, a .stylelintrc
file in your project root:
{
"extends": "@netsells/stylelint-config"
}
Add the stylelint-webpack-plugin
to your project:
yarn add stylelint-webpack-plugin
Add the plugin to your webpack config:
const StyleLintPlugin = require('stylelint-webpack-plugin');
...
{
plugins: [
new StyleLintPlugin({
configFile: './.stylelintrc',
files: './resources/assets/**/*',
}),
],
},
This command will create a blank rule template for you.
npm run create-rule core/brand-new-rule
Disallow empty blocks.
a {
}
@media print {
a {
}
}
a {
color: #ffffff;
}
@media print {
a {
color: #ffffff;
}
}
Sets the case of hex values to lowercase.
a {
color: #FFF;
}
a {
color: #FF0000;
}
a {
color: #ffffff;
}
a {
color: #ff0000;
}
Forces the length of hex codes used in styles to be long notation rather than short.
a {
color: #fff;
}
a {
color: #fffa;
}
a {
color: #ffffff;
}
a {
color: #ffffaa;
}
Colors must never be named.
a {
color: black;
}
a {
color: white;
}
a {
color: #000000;
}
a {
color: $blue;
}
Disallow invalid hex colors.
a {
color: #00;
}
a {
color: #fff1az;
}
a {
color: #12345aa;
}
a {
color: #000000;
}
a {
color: #fff1a0;
}
a {
color: #123450aa;
}
Disallow duplicate properties within declaration blocks. This rule ignores variables ($sass, @less, --custom-property).
a {
color: #FFFFFF;
color: #000000;
}
a {
color: #FFFFFF;
background: #000000;
color: #000000;
}
a {
color: #ffffff;
}
a {
color: #ffffff;
background: #000000;
}
Prevents shorthand properties overriding longhand ones.
a {
padding-left: 10px;
padding: 20px;
}
a {
transition-property: opacity;
transition: opacity 1s linear;
}
a {
-webkit-transition-property: opacity;
-webkit-transition: opacity 1s linear;
}
a {
border-top-width: 1px;
top: 0;
bottom: 3px;
border: 2px solid blue;
}
a {
padding: 10px;
padding-left: 20px;
}
a {
transition-property: opacity;
-webkit-transition: opacity 1s linear;
}
/* the following examples are to be viewed as a single instance*/
a {
transition-property: opacity;
}
a {
transition: opacity 1s linear;
}
Disallow !important within declarations.
a {
color: #FFFFFF !important;
}
a {
color: #FFFFFF!important;
}
a {
color: #FFFFFF ! important;
}
a {
color: #ffffff;
}
Always indent at-rules, rules, comments, declarations, inside parentheses and multi-line values by 4 spaces.
@media print {
a {
color: #000000;
}
@media print {
a,
b {
color: #000000;
}
}
a {
/* blergh */
color: #000000;
}
a {
color: rgb(
255,
255,
255
);
top: 0;
}
@media print {
a {
color: #000000;
}
}
@media print {
a,
b {
color: #000000;
}
}
a {
/* blergh */
color: #000000;
}
a {
color: rgb(
255,
255,
255
);
top: 0;
}
Zero lengths should not have units.
.my-element {
top: 0px;
left: 0px;
}
.my-element {
top: 0;
left: 0;
}
Limit the number of adjacent empty lines.
h1 {
}
p {
}
span {
}
h1 {
}
p {
}
span {
}
Require a single space after the colon in media features.
@media (max-width:600px) {
}
@media (max-width :600px) {
}
@media (max-width: 600px) {
}
@media (max-width : 600px) {
}
Disallow extra semicolons.
a {
color: #000000;;
}
a {
;color: #ffffff;
}
a {
color: #ffffff;
;
}
a {
color: #ffffff;
}
Requires a leading zero on fractional values that are less than one.
a {
line-height: .5px;
}
a {
transform: translate(2px, .4px);
}
a {
line-height: 0.5px;
}
a {
transform: translate(2px, 0.4px);
}
Specify lowercase for properties.
a {
Width: 1px
}
a {
WIDTH: 1px
}
a {
border-Radius: 5px;
}
a {
-WEBKIT-animation-duration: 3s;
}
@media screen and (orientation: landscape) {
WiDtH: 500px;
}
a {
width: 1px
}
a {
border-radius: 5px;
}
a {
-webkit-animation-duration: 3s;
}
@media screen and (orientation: landscape) {
width: 500px;
}
Prevents unknown properties being used.
a {
colr: blue;
}
a {
my-property: 1;
}
Disallow redundant values in shorthand properties.
a {
margin: 1px 1px;
}
a {
margin: 1px 1px 1px 1px;
}
a {
padding: 1px 2px 1px;
}
a {
border-radius: 1px 2px 1px 2px;
}
a {
margin: 1px;
}
a {
margin: 1px 1px 1px 2px;
}
a {
padding: 1px 1em 1pt 1pc;
}
a {
border-radius: 10px / 5px;
}
Prevents unknown units being used.
.my-element {
width: 90xp;
}
.other-element {
border-radius: 40pixels;
}