question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Suppressing CssSyntaxError for inline styles in svelte files

See original GitHub issue

What is the problem you’re trying to solve?

Hello, I am currently trying to implement stylelint in a project that uses svelte and several postcss plugins. The problem occurs in the parsing of inline styles in the svelte file.

We sometimes use the style tag of an html element to define a dynamic custom property as in the following case:

<nav
  class="Menu"
  slot="sticky"
  style="
    --nbMenuItems: { displayedItems.length };
    { getStyleUrlVars({ arrowRight }) }"
>

The output in this case is

<nav class="Menu svelte-1q3olh0" slot="sticky" style="--nbMenuItems: 3;--arrowRight: url('/client/assets/icon_arrow-2_right-7f4ce63b.svg');">

Here I get an error

src/components/AnchorMenu/AnchorMenu.svelte
 40:7  ✖  Unknown word   CssSyntaxError

I would like to turn off the parsing for inline style tags. Is this possible?

this is also the case with "defaultSeverity": "warning", as discussed here

Thanks in advance and for all the hard work that goes into stylelint!

What solution would you like to see?

I would like to have an option that allows for parsing only content between <style> tags but otherwise the possibility of doing something like this

<nav
   class="Menu"
   slot="sticky"
  style="
    --nbMenuItems: { displayedItems.length };
    /* stylelint-disable-line */
    { getStyleUrlVars({ arrowRight }) }
    /* stylelint-enable-line */
    "
 >

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
kelvindecostacommented, Jan 2, 2022

Hey everyone!

The following fix worked for me:

  • Install these dependencies:

    npm i -D postcss-html stylelint-config-html
    
  • Add stylelint-config-html/svelte to extends

Hope this helps!

3reactions
ota-meshicommented, Nov 2, 2021

If you are using a js file for your config, changing it to use postcss-safe-parser for CSS parsing with postcss-html will make the parser accept some syntax errors. So it may work for you.

{
// ...
overrides: [
  {
    files: ['*.svelte', '**/*.svelte'],
    customSyntax: require('postcss-html')({ css: 'postcss-safe-parser' }),
  }
]
}

You may need to explicitly install postcss-safe-parser.

https://github.com/ota-meshi/postcss-html#advanced-use-cases https://github.com/postcss/postcss-safe-parser

Read more comments on GitHub >

github_iconTop Results From Across the Web

Advanced styling / Inline styles • Svelte Tutorial
Great, now you can style the paragraph using variables that change based on your input without having to make a class for every...
Read more >
Ignoring code - Stylelint
Ignoring code. You can ignore: within files; files entirely. Within files​. You can temporarily turn off rules using special comments in your CSS....
Read more >
“Syntax Error: Error: PostCSS plugin postcss-import requires ...
src/index.css Syntax Error: Error: PostCSS plugin tailwindcss requires PostCSS ... It is required that your private key files are NOT accessible by others....
Read more >
esbuild-linux-arm64: Versions - Openbase
Source maps are JSON files that map from compiled code back to the original code. ... esbuild example.css --log-override:css-syntax-error=error.
Read more >
Symfony: How To Enable Validation Errors From A Subform ...
Navigate to Tools Debug File Validation from the left sidebar menu of the book dashboard; Click Choose File and ... CSS syntax error...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found