prettier/stylelint-prettier

Prettier's parser why not just "css"

yangmingshan opened this issue ยท 5 comments

Question

This plugin use prettier.getFileInfo to decide which parser to use. But this plugin is work with stylelint, so the parser maybe only need be css?

Problem

In China there is someting called miniProgram. It's style file use css syntax but use wxss as the extension. I want use this plugin in miniProgram, but Prettier don't know *.wxss file. If I told Prettier use css parser, it will work fine.

Or

If the parser can not just be css, maybe use css as default parser when inferredParser is null is a idea.


I'm happy to send a PR :)

I met this problem,too

Sorry for the long wait for a reply. I did not realize I was not watching my own repo. That has now been fixed.

Thank you both for your interest in stylelint-prettier.

Prettier and Stylelint both supports multiple css syntaxes - css, scss, sass, less. Each of these syntaxes have their own parser. If I were to tell prettier to always use the css parser then for example, it would never use the scss parser for scss files and thus scss-specific functionality such as formatting maps would not work.


You can teach Prettier to use a particular parser for a file extension it does not already know about by using configuration overrides.

Adding the following to your .prettierrc should tell it to use the css parer for .wxss files

{
  "overrides": [
    {
      "files": "*.wxss",
      "options": { "parser": "css" }
    }
  ]
}

Because stylelint-prettier reads prettier's config I would expect that these files would then be checked using the css parser within prettier.

I'll leave this issue open for now. Could you please let me know if specifying the overrides in your .prettierrc works for you?

I have just released v1.0.1 that works with configuration overrides. Please try it out with the above code and let me know if it solves your issue.

thanks!

Problem solved, thanks