0

The following is valid CSS in my opinion as per W3 schools and other websites:

:root {
  --primary-bg-color: green; /* global scope */
}

However most linters like https://prettier.io/ gives a error when parsing my example:

SyntaxError: Unexpected token (1:1)
> 1 | :root {
    | ^
  2 |   --primary-bg-color: green; /* global scope */
  3 | }

I'm not really experienced with CSS so the linter behavior raises questions for me:

  • Am I mistaken for thinking that this is valid CSS?
  • Why is the linters complaining?
  • How do I format it so that a linter would be happy with my syntax.
4
  • 2
    Can't reproduce on the Prettier playground. Have you selected the correct parser for CSS files…? Commented Nov 12 at 18:38
  • check if you don't have any "hidden" space at the start or verify the charset of the file Commented Nov 12 at 18:39
  • --parser must be set to css ... I assume it was trying to parse the content as something else. Commented Nov 12 at 18:45
  • the prettier.io/playground parser defaults to babel Commented Nov 12 at 19:04

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.