Skip to content

Instantly share code, notes, and snippets.

@KingScooty
Last active July 29, 2022 13:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KingScooty/fa4aab7852dd30feb573 to your computer and use it in GitHub Desktop.
Save KingScooty/fa4aab7852dd30feb573 to your computer and use it in GitHub Desktop.
Linting Sass stylesheets with Stylelint
/**
* Linting Sass 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 syntax_scss = require('postcss-scss');
var stylelint = require('stylelint');
gulp.task("scss-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),
reporter({
clearMessages: true,
throwError: true
})
];
return gulp.src(
['app/assets/css/**/*.scss',
// Ignore linting vendor assets
// Useful if you have bower components
'!app/assets/css/vendor/**/*.scss']
)
.pipe(postcss(processors, {syntax: syntax_scss}));
});
@deepfriedmind
Copy link

Line 56 should be .pipe(postcss(processors, {syntax: syntax_scss}));

@KingScooty
Copy link
Author

Well spotted. Patched up!

@Klemart3D
Copy link

Klemart3D commented Jul 29, 2022

http://www.creativenightly.com/2016/02/How-to-lint-your-css-with-stylelint/ page is unavailable

And function-url-quotes rule accepts only "always" or "never" options, not "double", see: https://stylelint.io/user-guide/rules/list/function-url-quotes/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment