Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use eslint autofix in .vue?

Tags:

eslint

vue.js

I want to use autofix in .vue file, but Eslint only show the errors, no autofix.

How do I configure the .eslintrc to make it work?

like image 776
philo Avatar asked Nov 10 '16 07:11

philo


People also ask

How do I run ESLint autofix?

Set up ESLint to autofix files To enable running eslint --fix on save for the current project, go to Preferences / Settings | Languages and Frameworks | JavaScript | Code Quality Tools | ESLint and tick the Run eslint --fix on save checkbox. By default, WebStorm will run ESLint to autofix . js, .

How do you use ESLint Vue?

Running ESLint from the command line If you want to run eslint from the command line, make sure you include the . vue extension using the --ext option or a glob pattern, because ESLint targets only . js files by default. If you installed @vue/cli-plugin-eslint , you should have the lint script added to your package.

Where does your code run ESLint Vue?

If you're using a project created with @vue/cli , you'll find the ESLint config inside package. json under the eslintConfig property.

What is ESLint Vue?

ESLint editor integrations are useful to check your code in real-time. Status of Vue.js 3.x supports. This plugin supports the basic syntax of Vue. js 3.2, <script setup> , and CSS variable injection, but the ref sugar, an experimental feature of Vue. js 3.2, is not yet supported.


2 Answers

Try to use it with specifying files extensions

eslint --fix --ext .js,.vue src
like image 115
Oleg Abrazhaev Avatar answered Sep 16 '22 18:09

Oleg Abrazhaev


vue 3 -> vue.config.js

module.exports = defineConfig({
  chainWebpack: config => {
    config
    .plugin('eslint')
    .tap(args => {
      args[0].fix = true
      return args
    })
  }
})
like image 26
Abraao Bueno Avatar answered Sep 19 '22 18:09

Abraao Bueno