Search code examples
webpacksassstylelint

How to correctly lint .sass files using stylelint-webpack-plugin (with webpack 2)?


I'm actually trying to use a linter for my .sass files, in a Webpack 2 project. So I'm using "stylelint-webpack-plugin", but no matter how I configure it, I always get warnings/errors about semicolons (which are not relevant with .sass syntax). It seems that poscss-sass package doesn't do the job... Is there any solution for people using .sass (not .scss) syntax? Thx in advance!


Solution

  • The postcss-sass parser is very new and its compatibility with stylelint is still being evaluated. It is not yet bundled within stylelint, and is therefore not available via stylelint-webpack-plugin's syntax option.

    I always get warnings/errors about semicolons (which are not relevant with .sass syntax).

    This is because, in the absence of the postcss-sass parser, the standard PostCSS parser is attempting to parse your SASS code. It expects declarations within declaration blocks to be separated by semicolons.

    A custom-syntax option is provided by stylelint itself. Therefore, if you like, you can experiment with the postcss-sass parser by using the stylelint CLI:

    stylelint "**/*.sass" --custom-syntax postcss-sass
    

    This should resolve any syntax errors you're getting regarding semi-colons.

    If you're using stylelint-config-standard, you should also turn off any rules that check braces and semicolons.


    As an alternative to SASS, you could use SugarSS. It is an indent-based CSS syntax that is compatible with stylelint and available within stylelint-webpack-plugin.