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

prettier: can not parse style in '.vue' #8489

Closed
zhimng opened this issue Jun 3, 2020 · 11 comments
Closed

prettier: can not parse style in '.vue' #8489

zhimng opened this issue Jun 3, 2020 · 11 comments
Labels
type:duplicate Issues that are a duplicate of a previous issue

Comments

@zhimng
Copy link

zhimng commented Jun 3, 2020

Sorry, I didn't find the settings I needed on https://prettier.io/playground.

I want to set the style support for vue files in prettier, but I always set it incorrectly. I can format less and css files, but always not for vue files.

Prettier 2.0.5
I can't provide that.

.pretterrc.js

module.exports = {
  endOfLine: 'auto',
  trailingComma: 'none',
  arrowParens: 'avoid',
  singleQuote: true,
  insertPragma: false,
  HTMLWhitespaceSensitivity: 'ignore',
  overrides: [
    {
      files: ['*.less', '*.css'],
      options: {
        singleQuote: false,
        insertPragma: false
      }
    }
  ]
};

Input:

<template>
  <div class="container"></div>
</template>
<style lang="less" scoped>
.container {
    content: "i want double quotes";
  }
</style>

Output:

...
error  Replace `"i want double quotes"` with `'i want double quotes'`  prettier/prettier
...

package.json

"eslint": "^6.8.0",
"eslint-config-prettier": "^6.11.0",
"eslint-loader": "^4.0.2",
"eslint-plugin-prettier": "^3.1.3",
"eslint-plugin-vue": "^7.0.0-alpha.5",
"prettier": "2.0.5",
"stylelint": "^13.5.0",
"stylelint-config-prettier": "^8.0.1",
"stylelint-config-standard": "^20.0.0",
"stylelint-prettier": "^1.1.2",
"stylelint-webpack-plugin": "^2.0.0",

Expected behavior:

can use double quotes in style tag

@zhimng zhimng closed this as completed Jun 3, 2020
@zhimng zhimng changed the title prettier: can not parse style in '.vue prettier: can not parse style in '.vue' Jun 3, 2020
@zhimng zhimng reopened this Jun 3, 2020
@zhimng
Copy link
Author

zhimng commented Jun 3, 2020

I tried setting parser to vue in overrides, but it didn't work. like that:

module.exports = {
  endOfLine: 'auto',
  trailingComma: 'none',
  arrowParens: 'avoid',
  singleQuote: true,
  insertPragma: false,
  HTMLWhitespaceSensitivity: 'ignore',
  overrides: [
    {
      files: ['*.less', '*.css'],
      options: {
        parser: 'vue',
        singleQuote: false,
        insertPragma: false
      }
    }
  ]
};

@fisker
Copy link
Member

fisker commented Jun 3, 2020

Prettier 2.0.5
Playground link

--parser vue
--single-quote

Input:

<template>
  <div class="container"></div>
</template>
<style lang="less" scoped>
.container {
    content: "i want double quotes";
  }
</style>

Output:

<template>
  <div class="container"></div>
</template>
<style lang="less" scoped>
.container {
  content: 'i want double quotes';
}
</style>

@fisker
Copy link
Member

fisker commented Jun 3, 2020

Settings should be

module.exports = {
  // ...
  overrides: [
    {
      files: ['*.vue'],
      options: {
        parser: 'vue',
        // ...
      }
    }
  ]
};

@fisker fisker added the status:awaiting response Issues that require answers to questions from maintainers before action can be taken label Jun 3, 2020
@zhimng
Copy link
Author

zhimng commented Jun 3, 2020

@fisker I have tried this configuration, but if set this way, then the JS in the VUE file will also be asked to use double quotes at the same time, I just want to set double quotes in the CSS and single quotes in the JS

@no-response no-response bot removed the status:awaiting response Issues that require answers to questions from maintainers before action can be taken label Jun 3, 2020
@fisker
Copy link
Member

fisker commented Jun 3, 2020

I understand your problem now, we can't do this now.

@fisker
Copy link
Member

fisker commented Jun 3, 2020

Work around for now, you can use

<style lang="less" scoped src="./style.less"></style>

@alexander-akait
Copy link
Member

@fisker Duplicate #5378?

@thorn0
Copy link
Member

thorn0 commented Jun 3, 2020

Duplicate of #5378

@thorn0 thorn0 marked this as a duplicate of #5378 Jun 3, 2020
@thorn0 thorn0 closed this as completed Jun 3, 2020
@thorn0 thorn0 added the type:duplicate Issues that are a duplicate of a previous issue label Jun 3, 2020
@zhimng
Copy link
Author

zhimng commented Jun 3, 2020

May I know if there are plans to mention this task, or not. Emm...... It's embarrassing. I have to give up use it in my project.

@thorn0
Copy link
Member

thorn0 commented Jun 3, 2020

There are no immediate plans to address this issue. It's pretty complex.

@InsightAdimn
Copy link

Hey thorn0,
I have had nothing but problems with prettier and vue. I have lost countless hours trying to configure prettier to be usable with vue (and others) I followed this article by Jon Gallant and it helped.

@prettier prettier locked as off-topic and limited conversation to collaborators Jul 1, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type:duplicate Issues that are a duplicate of a previous issue
Projects
None yet
Development

No branches or pull requests

5 participants