Skip to content

Instantly share code, notes, and snippets.

@KingScooty
Last active February 15, 2016 10:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KingScooty/21d6fc030174cd41b2e4 to your computer and use it in GitHub Desktop.
Save KingScooty/21d6fc030174cd41b2e4 to your computer and use it in GitHub Desktop.
Linting CSS stylesheets with Stylelint
/**
* 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