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.

Formatting self closing slash incorrectly in .vue files

See original GitHub issue

vscode: 1.29.1

vscode plugins

Prettier - Code formatter: 1.7.2 Eslint: 1.7.0

package.json

Prettier: 1.15.2 eslint-config-prettier: 3.3.0 eslint-plugin-prettier: 3.0.0 eslint: 5.9.0

.eslintrc.js

module.exports = {
  env: {
    browser: true,
    es6: true,
    jest: true,
    node: true
  },
  extends: ['plugin:vue/essential', 'standard', 'prettier'],
  globals: {},
  parserOptions: {
    parser: 'babel-eslint',
    ecmaVersion: 2017,
    sourceType: 'module'
  },
  plugins: ['vue', 'standard', 'prettier'],
  root: true,
  rules: {
    'prettier/prettier': 'error'
  }
}

.prettierrc

{
  "bracketSpacing": true,
  "semi": false,
  "singleQuote": true,
  "trailingComma": "none"
}

Description

I’m setting up eslint, prettier and vscode for a vue js project. In visual studio code I have enabled format on save.

If I use vue js cli to create a starter project and edit and save .js files they are correctly formatted. When I save and lint .vue files they clash with respect to the spacing before a self closing tag.

For example if I have:

<template>
  <div class="VueToNuxtLogo">
    <div class="Triangle Triangle--two" />
    <div class="Triangle Triangle--one" />
    <div class="Triangle Triangle--three" />
    <div class="Triangle Triangle--four" />
  </div>
</template>

When I save the file it transforms the self closing tags to:

<div class="Triangle Triangle--two"/>

This causes eslint to highlight that there is an error that violates the prettier/prettier rule in my eslint.rc file.

If I run prettier from the command line it correctly formats the tag again as:

<div class="Triangle Triangle--two" />

I even edited my settings.json file with:

"eslint.validate": [
    {
      "language": "vue",
      "autoFix": true
    },
    {
      "language": "html",
      "autoFix": true
    },
    {
      "language": "javascript",
      "autoFix": true
    }
  ]

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:5
  • Comments:13 (1 by maintainers)

github_iconTop GitHub Comments

23reactions
jvikcommented, Mar 28, 2019

@Applicafroguy Not sure if you have the same problem as me, but Vetur in vscode was set to using incorrect formatter. Changing HTML formatter to prettier in vetur settings solved it for me.

11reactions
mutefiRecommented, Mar 28, 2019

@Applicafroguy Not sure if you have the same problem as me, but Vetur in vscode was set to using incorrect formatter. Changing HTML formatter to prettier in vetur settings solved it for me.

that solved it for me, thank you 👍

Changed it to "vetur.format.defaultFormatter.html": "prettier" and "vetur.format.defaultFormatter.js": "prettier-eslint" According to their documentation, the default for html is prettyhtml and for js it is prettier, instead of prettier-eslint

Read more comments on GitHub >

github_iconTop Results From Across the Web

VSCode prettier/vue formatting settings don't work properly
The issue I had was that my html in the .vue file was malformed (Specifically I had a closing tag which shouldn't have...
Read more >
vue/html-self-closing
Rule Details #. This rule aims to enforce the self-closing sign as the configured style. In Vue.js template, we can use either two...
Read more >
Vue.js: self-closing tags are allowed for vue components ...
Vue.js: self-closing tags are allowed for vue components, should not be marked by inspection ... in the Vue single file components (not in...
Read more >
vue-tsc | Yarn - Package Manager
Changelog. 1.0.17 (2022/12/26). feat: support syntax highlighting for lang="json5" (#2244); feat: support for generating virtual file from multiple sources ...
Read more >
typescript variable with dollar sign
For any particular tagged template literal expression, the tag function will ... fix: self closing tag syntax highlight incorrect (, fix: re-fix vue...
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