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?
How to Lint SCSS files?
Hi,
take a look at SublimeLinter for general linting, and, for scss specific linting Iād suggest Stylelint.
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?
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:
- open your project in ST
- open your project folder in any terminal/command prompt you use
- run
npm init
- run
npm install postcss stylelint stylelint-config-standard
- create a file
.stylelintrc
in you project folder with following content
{
"extends": "stylelint-config-standard"
}
- optionally add your specific linting rules to tweak the output. (here you find all stylelint rules)
At this point you should have stylelint running.
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.
Any hints in the console? Exceptions or failing plugins?
Click on View > Show Console
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"
totrue
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.
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
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");
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
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.