Last active
February 15, 2016 10:50
-
-
Save KingScooty/21d6fc030174cd41b2e4 to your computer and use it in GitHub Desktop.
Linting CSS stylesheets with Stylelint
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Linting CSS stylesheets with Stylelint | |
* http://www.creativenightly.com/2016/02/How-to-lint-your-css-with-stylelint/ | |
*/ | |
var gulp = require('gulp'); | |
var postcss = require('gulp-postcss'); | |
var reporter = require('postcss-reporter'); | |
var stylelint = require('stylelint'); | |
gulp.task("css-lint", function() { | |
// Stylelint config rules | |
var stylelintConfig = { | |
"rules": { | |
"block-no-empty": true, | |
"color-no-invalid-hex": true, | |
"declaration-colon-space-after": "always", | |
"declaration-colon-space-before": "never", | |
"function-comma-space-after": "always", | |
"function-url-quotes": "double", | |
"media-feature-colon-space-after": "always", | |
"media-feature-colon-space-before": "never", | |
"media-feature-name-no-vendor-prefix": true, | |
"max-empty-lines": 5, | |
"number-leading-zero": "never", | |
"number-no-trailing-zeros": true, | |
"property-no-vendor-prefix": true, | |
"rule-no-duplicate-properties": true, | |
"declaration-block-no-single-line": true, | |
"rule-trailing-semicolon": "always", | |
"selector-list-comma-space-before": "never", | |
"selector-list-comma-newline-after": "always", | |
"selector-no-id": true, | |
"string-quotes": "double", | |
"value-no-vendor-prefix": true | |
} | |
} | |
var processors = [ | |
stylelint(stylelintConfig), | |
// Pretty reporting config | |
reporter({ | |
clearMessages: true, | |
throwError: true | |
}) | |
]; | |
return gulp.src( | |
// Stylesheet source: | |
['app/assets/css/**/*.css', | |
// Ignore linting vendor assets: | |
// (Useful if you have bower components) | |
'!app/assets/css/vendor/**/*.css'] | |
) | |
.pipe(postcss(processors)); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment