A repository for CSS and Sass linting rules that have been derived from best practices and the GoDaddy Styleguide.
The rules for our style linting are defined in index.js
. The rules are separated into error reporting rules, warning reporting rules and Sass specific rules. This was done to create a divide among the different types of rules and give a more visual way of distinguishing between them.
npm i --save-dev stylelint stylelint-config-godaddy
Create a .stylelintrc
file in the root of your project and extend the config file:
{
"extends": "stylelint-config-godaddy"
}
You can add your own rules beyond those that are defined here. You can find all the rules for stylelint
here. You can find all the rules for stylelint-scss
here. There are also many other plugins that can be used to extend stylelint
if you feel the need. To Add your own rules it would look like these examples:
{
"extends": "stylelint-config-godaddy",
"rules": {
"block-no-empty": true,
"number-no-trailing-zeros": [true, {
"severity": "warning"
}]
}
}
{
"extends": "stylelint-config-godaddy",
"plugins": [
"stylelint-plugin-here"
],
"rules": {
"block-no-empty": true,
"number-no-trailing-zeros": [true, {
"severity": "warning"
}],
"plugin/rule": ["always", {
"severity": "warning"
}]
}
}
To run the tests is very similar to other linting packages. Add a script to the scripts
area in your package.json
.
"test:styles": "stylelint '*.scss'"
"test:styles": "stylelint '**/*.scss'"
Sometimes there is code that should be ignored by the linter and that's totally cool as long as there is a good reason. There are two ways to do this and each way has a way to turn off only specific rules. Most of the time you wouldn't turn off all the rules for the file or the parts of the file you would turn off specific rules.
- Full file
stlyelint-disable
, not usually recommended by itself - Parts of a file using
stlyelint-disable
andstlyelint-enable
, also not usually recommended by itself - Specific rule disabling, highly recommended if needed. Rules are comma separated
As an example of a full file disable of certain rules you would add this to the top of the file:
// stylelint-disable selector-no-qualifying-type, color-no-hex
Disabling parts of a file need both the disabling and enabling parts so as to not hinder the linting of the rest of the file. As an example disabling parts of a file, it would look like this:
// stylelint-disable selector-no-qualifying-type
select[multiple].form-control {
height: auto;
min-height: $input-height;
overflow-y: scroll;
}
// stylelint-enable selector-no-qualifying-type