Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incompatible with stylelint-prettier #210

Closed
JounQin opened this issue Feb 22, 2021 · 4 comments
Closed

Incompatible with stylelint-prettier #210

JounQin opened this issue Feb 22, 2021 · 4 comments

Comments

@JounQin
Copy link

JounQin commented Feb 22, 2021

<!-- test.svelte -->
<style>
  .test {
    border: transparent;
  }
</style>
// .stylelintrc
{
  "plugins": [
    "stylelint-prettier"
  ],
  "rules": {
    "prettier/prettier": true
  }
}

command stylelint test.svelte fails with:

$ /Users/JounQin/Workspaces/Local/test/node_modules/.bin/stylelint test.svelte
ParseError: Expected }
  1 | .test {
> 2 |     border: transparent;
    |          ^
  3 |   }
    at error (/Users/JounQin/Workspaces/Local/test/node_modules/svelte/compiler.js:16748:20)
    at Parser$1.error (/Users/JounQin/Workspaces/Local/test/node_modules/svelte/compiler.js:16824:10)
    at Parser$1.eat (/Users/JounQin/Workspaces/Local/test/node_modules/svelte/compiler.js:16838:19)
    at mustache (/Users/JounQin/Workspaces/Local/test/node_modules/svelte/compiler.js:16641:17)
    at new Parser$1 (/Users/JounQin/Workspaces/Local/test/node_modules/svelte/compiler.js:16783:22)
    at Object.parse$3 [as parse] (/Users/JounQin/Workspaces/Local/test/node_modules/svelte/compiler.js:16915:21)
    at Object.parse (/Users/JounQin/Workspaces/Local/test/node_modules/prettier-plugin-svelte/plugin.js:1672:83)
    at Object.parse (/Users/JounQin/Workspaces/Local/test/node_modules/prettier/index.js:13625:19)
    at coreFormat (/Users/JounQin/Workspaces/Local/test/node_modules/prettier/index.js:14899:14)
    at format (/Users/JounQin/Workspaces/Local/test/node_modules/prettier/index.js:15131:14)
@dummdidumm
Copy link
Member

I'm not sure how to proceed here. The problem is that stylelint extracts the CSS part from the Svelte file, which in turn is then handed to prettier-plugin-svelte. So in your example the plugin gets

  .test {
    border: transparent;
  }

Which is obviously invalid Svelte code. To me this sounds like you need to somehow tell Prettier to route this code to its CSS formatter and not to the Svelte plugin.

@JounQin
Copy link
Author

JounQin commented Feb 22, 2021

Hmm, .html and .vue files are similar but works fine, maybe prettier handles html and vue specially?

@dummdidumm
Copy link
Member

Vue and HTML support are built-in to prettier core. Maybe their source code can reveal how they deal with that in this situation.

@JounQin
Copy link
Author

JounQin commented Feb 22, 2021

It seems to be related to https://github.com/prettier/stylelint-prettier/blob/master/stylelint-prettier.js#L90-L97, I'll raise a PR there instead.

Thanks for your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants