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.

Prettier not picking up eslintintegration settings working on vue files

See original GitHub issue
  • [x ] I have searched through existing issues
  • [x ] I have read through docs
  • [x ] I have read FAQ

Info

  • Platform: Windows 10
  • Vetur version: 0.11.5
  • VS Code version: 1,19.1

Problem

I have a Nuxt project - basically this one without backpack but created with nuxt. Plus my workspace settings are

{
  "prettier.eslintIntegration": true,
  "editor.formatOnSave": true
}

While .js files are correctly formatted on save, without ;. The .vue files are not. ; are added and the indenting of the template section is not adjusted.

Reproducible Case

package.json

  "scripts": {
    "dev": "cross-env NODE_ENV=development nodemon server/index.js --watch server",
    "build": "nuxt build",
    "start": "cross-env NODE_ENV=production node server/index.js",
    "generate": "nuxt generate",
    "lint": "eslint --ext .js,.vue --ignore-path .gitignore .",
    "precommit": "npm run lint",
    "ds": "npm run build && npm run deploy && now alias staging-alwaysinmind",
    "dp": "npm run build && npm run deploy && now alias alwaysinmind"
  },
  "dependencies": {
    "nuxt": "^1.0.0-rc11",
    "express": "^4.16.2",
    "@nuxtjs/axios": "^4.5.0"
  },
  "devDependencies": {
    "autoprefixer": "^7.2.3",
    "cross-env": "^5.1.3",
    "babel-eslint": "^8.0.3",
    "eslint": "^4.13.1",
    "eslint-config-standard": "^10.2.1",
    "eslint-plugin-html": "^4.0.1",
    "eslint-plugin-import": "^2.8.0",
    "eslint-plugin-node": "^5.2.1",
    "eslint-plugin-promise": "^3.6.0",
    "eslint-plugin-standard": "^3.0.1",
    "now": "^9.0.1",
    "tailwindcss": "^0.4.0",
    "nodemon": "^1.14.2"
  }
}

.eslintrc.js

module.exports = {
  root: true,
  parser: 'babel-eslint',
  env: {
    browser: true,
    node: true
  },
  extends: 'standard',
  // required to lint *.vue files
  plugins: [
    'html'
  ],
  // add your custom rules here
  rules: {
    'space-before-function-paren': [
      2,
      {
        anonymous: 'always',
        named: 'never'
      }
    ],
  },
  globals: {}
}

.editorconfig

# editorconfig.org
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false

I also have the prettier and ES extensions installed and enabled

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:5
  • Comments:18 (10 by maintainers)

github_iconTop GitHub Comments

7reactions
octrefcommented, Apr 6, 2018

@Justineo I took a look at your fork. You cannot remove plugin:vue/recommended from the extends setup (you can use a lesser version such as vue/base). Otherwise ESLint cannot process the scripts correctly since the scripts live in a vue file. You can refer to this setup: https://github.com/chrisvfritz/vue-enterprise-boilerplate/blob/master/.eslintrc.js

Specifically, eslint-plugin-vue’s base config includes this

  parser: require.resolve('vue-eslint-parser'),

which is needed for linting and formatting js in vue files.

Do not use https://github.com/BenoitZugmeyer/eslint-plugin-html also. eslint-plugin-vue will be the officially maintained project.

Meanwhile I’m working on #523 and it’ll be published on the next version.

1reaction
initial-wucommented, Mar 29, 2018

@octref 所以 vetur 没有在 vue script 中支持 prettier.eslintIntegration 的计划吗?文档里把 prettier.eslintIntegration 写在这里容易让人误以为 vetur 支持 eslintrc 配置。 image

同时维护两份格式化的配置 prettierrc 和 eslintrc 确实是一个不好的实践。 我想 prettier 支持 .editorconfig 和 .eslintrc 的出发点应该就是避免维护多份格式化配置。 和 @SteveALee 一样,我们的项目也选择以 eslintrc 作为主要的格式化配置。对 js 文件来说,prettier 自然的使用 eslintrc 作为格式化依据,对于 vue 文件中的 script,也希望能有同样的效果。

Read more comments on GitHub >

github_iconTop Results From Across the Web

VSCode prettier/vue formatting settings don't work properly
Only advice I can give is stop using Prettier. Trying to make it work with ESlint and Vetur was always pain. Then I...
Read more >
Options - Prettier
If you change any options, it's recommended to do it via a configuration file. This way the Prettier CLI, editor integrations and other...
Read more >
Having a tough time setting up EsLint/Prettier to work with Volar
I use ESLint with typescript, Vue 3, and volar though. I can provide you with my ESLint config file if you wish. Inb4...
Read more >
ESLint | WebStorm Documentation - JetBrains
If no .eslintrc.* is found in the current file folder, WebStorm will look for one in its parent folders up to the project...
Read more >
Integrating Prettier and ESLint With VS Code - Enlear Academy
Getting Prettier, ESLint, and VS Code to work together ... If you are having trouble finding the settings.json file, follow these steps: File...
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