Skip to content

ESLint rule vue/html-closing-bracket-newline conflicts with @vue/prettier #3078

Open
@udyux

Description

@udyux

Version

3.2.1

Environment info

  System:
    OS: macOS 10.14.1
    CPU: (4) x64 Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
  Binaries:
    Node: 8.12.0 - /usr/local/bin/node
    Yarn: 1.12.1 - /usr/local/bin/yarn
    npm: 6.4.1 - /usr/local/bin/npm
  Browsers:
    Chrome: 70.0.3538.110
    Firefox: Not Found
    Safari: 12.0.1
  npmPackages:
    @vue/babel-preset-app:  3.2.0
    @vue/cli-overlay:  3.2.0
    @vue/cli-plugin-babel: ^3.2.0 => 3.2.0
    @vue/cli-plugin-eslint: ^3.2.0 => 3.2.1
    @vue/cli-service: ^3.2.0 => 3.2.0
    @vue/cli-shared-utils:  3.2.0
    @vue/component-compiler-utils:  2.3.0
    @vue/eslint-config-prettier: ^4.0.0 => 4.0.1
    @vue/preload-webpack-plugin:  1.1.0
    @vue/web-component-wrapper:  1.2.0
    babel-helper-vue-jsx-merge-props:  2.0.3
    babel-plugin-transform-vue-jsx:  4.0.1
    eslint-plugin-vue: ^5.0.0-0 => 5.0.0
    vue: ^2.5.17 => 2.5.17
    vue-eslint-parser:  4.0.2
    vue-hot-reload-api:  2.3.1
    vue-loader:  15.4.2
    vue-router: ^3.0.1 => 3.0.2
    vue-style-loader:  4.1.2
    vue-template-compiler: ^2.5.17 => 2.5.17
    vue-template-es2015-compiler:  1.6.0
    vuex: ^3.0.1 => 3.0.1
  npmGlobalPackages:
    @vue/cli: Not Found

Steps to reproduce

  • Use vue-cli to create a new project: vue create eslint-test-proj
  • Manually select features: Babel, Router, Vuex, CSS Pre-processors, Linter / Formatter (selected history mode for router, selected Sass/SCSS for preprocessor)
  • Pick linter / formatter config ESLint Prettier and select Lint on save
  • Choose to place configs In dedicated config files
  • Add the following rule to rules in .eslintrc.js: 'vue/html-closing-bracket-newline': ['warn', { singleline: 'never', multiline: 'never' }]
  • Add a .prettierrc file to the project root containing { "printWidth": 120, "jsxBracketSameLine": true, "htmlWhitespaceSensitivity": "ignore" }
  • Open src/components/HelloWorld.vue and save (to trigger formatting)

What is expected?

That, on every save, multiline tags' closing brackets be on the same line as the last prop/attribute. Eg:

<a
    href="https://vuejs.org/"
    target="_blank"
    rel="noopener">
    VueJS
</a>

What is actually happening?

The document is formatted differently every time it is saved, toggling between the correct output:

<a
    href="https://vuejs.org/"
    target="_blank"
    rel="noopener">
    VueJS
</a>

and an incorrect output:

<a
    href="https://vuejs.org/"
    target="_blank"
    rel="noopener"
>
    VueJS
</a>

It would seem that there is a conflict between the rule vue/html-closing-bracket-newline and extending @vue/prettier in the config.

If I remove @vue/prettier then the problem is not present but I lose formatting for many other things (such as allowing multiple attributes on the same line and wrapping once the max-length is reached).

I am using VSCode 1.29.1 with the following settings for extensions:

{
  "prettier.eslintIntegration": true,
  "vetur.validation.template": false,
  "vetur.format.defaultFormatter.html": "none",
  "javascript.format.enable": false,
  "editor.formatOnSave": true,
  "[javascript]": { "editor.formatOnSave": false },
  "eslint.enable": true,
  "eslint.autoFixOnSave": true,
  "eslint.alwaysShowStatus": true,
  "eslint.options": {
    "extensions": [".html", ".js", ".vue", ".jsx"]
  },
  "eslint.validate": [
    { "language": "html", "autoFix": true },
    { "language": "vue", "autoFix": true },
    { "language": "javascript", "autoFix": true },
    { "language": "javascriptreact", "autoFix": true }
  ]
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions