Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable eslint-prettier with vue on annoying vue's html formatting

<template>
    <div class="d-flex flex-grow-1" onclick="console.log('testing...');" style="display: block;">
        HOW CAN I LEAVE ME CODE LIKE THIS!!!!?
    </div>
</template>
<template>
    <div
        class="d-flex flex-grow-1"
        onclick="console.log('testing...');"
        style="display: block;"
    >
        eslint-prettier KEEPS CHANGING MY CODE LIKE THIS...    SOOOOOOOOO ANNOYING!!!
    </div>
</template>

.eslintrc.json

{
    "root": true,
    "env": {
        "node": true,
        "es6": true,
        "browser": true
    },
    "parser": "babel-eslint",
    "plugins": [],
    "extends": [
        "eslint:recommended"
    ],
    "overrides": [
        {
            "files": [
                "**/*.vue"
            ],
            "parser": "vue-eslint-parser",
            "parserOptions": {
                "parser": "@typescript-eslint/parser"
            },
            "plugins": [],
            "extends": [
                "plugin:@typescript-eslint/recommended",
                "prettier/@typescript-eslint",
                "plugin:vue/vue3-strongly-recommended",
                "prettier/vue",
                "plugin:prettier/recommended"
            ]
        }
    ]
}

package.json

  "devDependencies": {
    "babel-eslint": "^10.1.0",
    "eslint": "^6.8.0",
    "eslint-config-prettier": "^6.10.1",
    "eslint-plugin-prettier": "^3.1.3",
    "eslint-plugin-vue": "^7.0.0-alpha.0",
    "prettier": "^2.0.4",
  }

setting.json

{
  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": true
  },
  "eslint.validate": [
    "javascript",
    "vue"
  ]
}

I have vetur and eslint installed on VS Code. I am working fine with this set of configure. However, this line wrap setting is very annoying. Anyone can give me advice on how can I disable line wrapping for vue's html or even disable formatting for vue's html?

Thanks in advance.

like image 686
mannok Avatar asked Jun 15 '20 16:06

mannok


People also ask

How do I enable prettier ESLint in Vue?

The Config If you’re using a project created with vue-cli 3.0 beta, you’ll find the ESLint config inside package.json under the eslintConfig property. Go ahead and add "plugin:prettier/recommended", to the extends sub-property after "plugin:vue/essential",, to enable prettier support in ESLint with the default settings.

Can ESLint Lint Vue files?

Now, ESLint is configured to use the default recommended Prettier rules. If you don’t have eslint installed or set up for Vue yet, we have just the guide for you! This guide also shows how to configure VSCode and Atom to lint your Vue files in real time.

How do I install prettier in Vue?

First, you’ll want to install prettier globally from NPM, if you haven’t already. It can be installed on a per-project basis, but that’s not really recommended. Then, start a new Vue project using @vue/cli with default configurations: Next, navigate to the new project directory:

Why does Vue use prettyhtml instead of Es Lint?

So, when open a .vue file in VS Code and Format Document with Vetur, it uses Prettyhtml by default, which violates prettier ES Lint rules. When you open App.vue, you get this…notice the space after router-view and the space after router-link> …


2 Answers

"rules": {
  "max-len": ["error", 140, 2, {
     ignoreComments: false,
     ignoreRegExpLiterals: true,
     ignoreStrings: false,
     ignoreTemplateLiterals: false,
  }],
   "vue/max-attributes-per-line": "off"
}

Add this to your rules, in your .eslintrc file you can adjust the number 140 to your preference so that it doesn't wrap the files to 80 characters which is default.

like image 69
tHeSiD Avatar answered Oct 25 '22 03:10

tHeSiD


I see you are using Prettier as a code formatter: On the Prettier config: .prettierrc (create it if doesn't exist) put 120 or 180 for the printwidth. The default is 80.

{
  "printWidth": 120
}

You can override here other options too. See the documentation Prettier Options

like image 23
Dobai Livia Avatar answered Oct 25 '22 02:10

Dobai Livia