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.

Multiple attributes not being fixed correctly with line breaks - vue/max-attributes-per-line not working right

See original GitHub issue

It seems I can’t get vue/max-attributes-per-line to auto-fix correctly.

For example, with vue/max-attributes-per-line set to ‘off’, and I try to add line breaks manually it corrects it to always have every element on no more than one line, no matter if it is 81, 120, 200, or more characters wide. How can I figure out what is forcing my markup elements onto exactly one line?

I am using ESLint version 5.1.0 and Visual Studio Code (without the Prettier Extension), with Prettier 1.14.2.

Here’s the example in a .vue file-- I cannot make this go on multiple lines no matter what I do, when 'vue/max-attributes-per-line': 'off'. Every time I save, it forces the long line of markup to be all on one line.

<template>
  <font-awesome-icon v-if="statusOptions.icon" :icon="statusOptions.icon" :spin="statusOptions.isIconSpin" :class="['saving-indicator', 'pl-1', 'pt-1', statusOptions.iconClasses]" />
</template>

If I set 'vue/max-attributes-per-line': 2, it formats like so (which is quite wrong as well).

      <font-awesome-icon v-if="statusOptions.icon" 
:icon="statusOptions.icon" :spin="statusOptions.isIconSpin" :class="['saving-indicator', 'pl-1', 'pt-1', statusOptions.iconClasses]" />

If I try to reformat it manually, it just reverts to the above when I save.

Additionally, it seems to reformat twice when I hit Ctrl+S: first it reformats to put it all on one line, then a half-second later the formatting above results. Any ideas? What is causing this weirdness–are there multiple reformatters running? How do I figure out what the first one is to disable it?

.eslintrc.js:

module.exports = {
  parserOptions: {
    parser: 'babel-eslint'
  },
  env: {
    browser: true,
    node: true,
    jest: true
  },
  globals: {
    expect: true
  },
  extends: [
    'prettier',
    'plugin:vue/recommended',        // /base, /essential, /strongly-recommended, /recommended
    'plugin:prettier/recommended',   // turns off all ESLINT rules that are unnecessary due to Prettier or might conflict with Prettier. 
    'eslint:recommended'
  ],
  plugins: ['vue', 'prettier'],
  rules: {
    'vue/max-attributes-per-line': 'off',
    'prettier/prettier': [            // customizing prettier rules (not many of them are customizable)
      'error',
      {
        singleQuote: true,
        semi: false,
        tabWidth: 2
      },
    ],
    'no-console': 'off'
  }
}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:8
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

12reactions
szalapskicommented, Oct 5, 2018

Short answer: I needed: “editor.formatOnSave”: false, “javascript.format.enable”: false.

I finally found the magical combination of settings, thanks to this thread from Wes Bos on Twitter. I was right in my suspicion that there seem to be multiple conflicting formatters. Though I’m not sure what they actually are, I was able to turn off all but eslint as follows:

In the VS Code settings, I need:


  "editor.formatOnSave": false,
  "javascript.format.enable": false,
  "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 }
  ]

In .eslintrc.js, then I can use the settings in my original post and then also change ‘vue/max-attributes-per-line’ as desired. Then VS Code’s ESLint plugin will format code one step at a time on every save, much as kenjiru wrote. One last snag: HMR won’t pick up these changes, so rebuild from scratch.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't get correct autoformat on save in Visual Studio Code ...
I was right in my suspicion that there seem to be multiple ... With 'vue/max-attributes-per-line': 1 VSCode fixes only one error per save....
Read more >
vue/max-attributes-per-line
An attribute is considered to be in a new line when there is a line break between two attributes. There is a configurable...
Read more >
URL navigation: line breaks for multi line texts not working?
Hi,. I tried giving the line breaks for a 'description' below field using the line break / carriage return = , but it...
Read more >
Static analysis (Part 1): Code style tools - tpetersdorf.dev
Trying to explain the issue of code style to a non-programmer usually results in blank stares and raised eyebrows.
Read more >
Just checking - multi-line text not supported in Inkscape
Text which has been moved onto the same line can be fixed by editing on the canvas and putting in newlines. One peculiar...
Read more >

github_iconTop Related Medium Post

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