Sublime Forum

How to Lint SCSS files?

#1

I have found various tutorials around the web for how to lint SCSS files. None of them are working for me. I am unable to get an error notification when I e.g. remove a closing bracket. Do you know of any good tutorials for this?

0 Likes

#2

Hi,
take a look at SublimeLinter for general linting, and, for scss specific linting Iā€™d suggest Stylelint.

0 Likes

#3

Iā€™ve looked through the docs and tried various tutorials, but still canā€™t get linting to work. Do you know of any tutorials I should read?

0 Likes

#4

The only tutorial I followed was the styelint getting started.
Iā€™ll try to summarize the passages Iā€™ve done to make it work.

Prerequisites:

  • node.js & npm installed and running on your machine

Steps:

  1. open your project in ST
  2. open your project folder in any terminal/command prompt you use
  3. run npm init
  4. run npm install postcss stylelint stylelint-config-standard
  5. create a file .stylelintrc in you project folder with following content
    {
       "extends": "stylelint-config-standard"
    }
  1. optionally add your specific linting rules to tweak the output. (here you find all stylelint rules)

At this point you should have stylelint running.

0 Likes

#5

The NPM packages installed without error. I changed my .sass-lint.yml file to .stylelintrc and added extends: 'stylelint-config-standard'. Opened a .scss file and removed a bracket. I closed Sublime and reopened. No linting errors.

0 Likes

#6

Any hints in the console? Exceptions or failing plugins?

Click on View > Show Console

0 Likes

#7

Ah, yes, there are errors in there.

[2020-11-03 08:20:13,292 - WARNING - SublimeLinter.lint.linter] sass cannot locate ā€˜sass-lintā€™
Please refer to the readme of this plugin and our troubleshooting guide: http://www.sublimelinter.com/en/stable/troubleshooting.html

I went to the troubleshooting guide linked in the error and read this:

To enable this mode, set "debug" to true in your SublimeLinter settings.

I turned on debug mode, made some edits in a SCSS file, and got this:

[2020-11-03 08:26:53,794 - INFO - SublimeLinter.lint.linter] sass: Checking lint mode ā€˜backgroundā€™ vs lint reason ā€˜on_modifiedā€™. Ok.
SublimeLinter: #7 linter.py:1105 sass: linting ā€˜_breadcrumbs.scssā€™
[2020-11-03 08:26:53,816 - INFO - SublimeLinter.lint.linter] sass: linting ā€˜_breadcrumbs.scssā€™
SublimeLinter: #7 node_linter.py:85 Searching executable for ā€˜sass-lintā€™ starting at ā€˜/_sass/componentsā€™.
[2020-11-03 08:26:53,818 - INFO - SublimeLinter.lint.base_linter.node_linter] Searching executable for ā€˜sass-lintā€™ starting at ā€˜/_sass/componentsā€™.

There is also a note in the docs to ā€œrun the program from the command line,ā€ but no instructions on how to do this.

0 Likes

#8

Sometimes you have to dive into the code a bit. That warning message about sass-lint is here: https://github.com/SublimeLinter/SublimeLinter/blob/75559cc057b90cfea80a3dc00cfd80fe37ed016f/lint/linter.py#L834

The SublimeLinter-stylelint package doesnā€™t seem to use that executable though: https://github.com/SublimeLinter/SublimeLinter-stylelint/blob/master/linter.py#L11

Are you sure you have SublimeLinter-stylelint installed?

Make sure your executables can be found in your $PATH. http://www.sublimelinter.com/en/stable/troubleshooting.html#debugging-path-problems

0 Likes

#9

To check whether your path is setup correctly you can run the following from the ST console:

import os; os.environ["PATH"]

To check whether an executable can be found by e.g. SublimeLinter or other plugins run the following:

import shutil; shutil.which("stylelint");
0 Likes

#10

More info about setting up your $PATH correctly can be found here: https://lsp.readthedocs.io/en/latest/troubleshooting/#2-lsp-cannot-find-my-language-server-no-such-file-or-directory-xyz

0 Likes

#11

The issue of linting SCSS is now solved. Thank you Raoul. The issue was that I did not have SublimeLinter-stylelint installed. I never saw instructions saying I need that.

For posterity, it might be good to include instructions for how to find the Sublime Text console. I searched the googles and could not find instructions.

1 Like