0

I have a file called foo.scss with contents:

.foo {
    font: {
        family: arial;
        weight: 600;
    }
}

Linting with stylelint 8.4.0 on the command line results in this output:

foo.scss 2:5 ✖ Cannot parse selector parseError

However, I expected this sass syntax to work since it's described in the sass documentation at https://sass-lang.com/documentation/file.SASS_REFERENCE.html#nested_properties

AlexMA
  • 9,842
  • 7
  • 42
  • 64

2 Answers2

1

You are missing the : after font so sass is treating font as a selector, and family and weight as properties. You need to add the : after font to achieve the desired result:

.foo {
    font: {
        family: arial;
        weight: 600;
    }
}

Seems that stylelint can't handle some of the special scss syntax. I think the best option will be to lint the css output (thru postcss) instead of the scss itself.

Please refer to Parsing non-standard syntax to properly lint scss or sass files.

muecas
  • 4,265
  • 1
  • 8
  • 18
  • Thanks for the response - you are correct. I reproduced the original problem incorrectly and missed the fact that the error changed. I will update my question to show this. The error after adding the missing colon is ` 2:5 ✖ Cannot parse selector parseError` – AlexMA May 21 '18 at 20:26
  • @AlexMA and what's in `2:5`? What is your css output? Can you post it? – muecas May 21 '18 at 20:33
  • 2:5 is the `font: {` bit. css output is `.foo { font-family: Arial, Helvetica, sans-serif; font-weight: 600; } ` – AlexMA May 21 '18 at 20:35
  • @AlexMA but StyleLint is a linter for CSS and not SASS; why are you applying the linter to a SASS (or scss) file? – muecas May 21 '18 at 20:36
  • According to the docs stylelint is supposed to do sass. I have been using it for months for sass work. https://stylelint.io/user-guide/faq/#how-do-i-lint-scss-less-or-other-non-standard-syntax – AlexMA May 21 '18 at 20:38
  • @AlexMA and you are using `postcss` to lint your css output? – muecas May 21 '18 at 20:39
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/171490/discussion-between-alexma-and-muecas). – AlexMA May 21 '18 at 20:40
0

Upgrading to stylelint 9.4 (from 8.4) fixed my issue.

AlexMA
  • 9,842
  • 7
  • 42
  • 64