55

I am creating a app with nuxt.js but everytime I launch the app, gives me the error of eslint and saying "potentially fixable with the --fix option."

I did the command npm run lint -- --fix and it works but then If I do another change in any vue file it comes again the same error and I have to do it again

Any idea of how to fix that?

jonrsharpe
  • 107,083
  • 22
  • 201
  • 376
Ricardo Moreira
  • 843
  • 1
  • 7
  • 16

3 Answers3

44

Use the below configuration into nuxt config file:

build: {
  extend(config, ctx) {
    config.module.rules.push({
      enforce: 'pre',
      test: /\.(js|vue)$/,
      loader: 'eslint-loader',
      exclude: /(node_modules)/,
      options: {
        fix: true
      }
    })
  }
}

Important part is:

options: {
  fix: true
}
kissu
  • 24,311
  • 11
  • 36
  • 67
Mahamudul Hasan
  • 2,552
  • 2
  • 15
  • 23
9

Extend the build in the nuxt.config.js file

build: {
  extend(config, ctx) {
    config.module.rules.push({
      enforce: "pre",
      test: /\.(js|vue)$/,
      loader: "eslint-loader",
      exclude: /(node_modules)/,
      options: {
        fix: true
      }
    })
  }
}
kissu
  • 24,311
  • 11
  • 36
  • 67
Nilanshu Jaiswal
  • 1,495
  • 3
  • 19
  • 34
0

If you're using VScode, I recommend doing a full ESlint configuration in your project as I've explained here.

Having this ESlint extension and that in your settings.json (accessible via Command Palette)

{
  "editor.codeActionsOnSave": {
    "source.fixAll": true, // this one will fix it on save for you
  },
  "eslint.options": {
    "extensions": [
      ".html",
      ".js",
      ".vue",
      ".jsx",
    ]
  },
  "eslint.validate": [
    "javascript",
    "javascriptreact",
    "typescript",
    "typescriptreact",
    "html",
    "vue",
  ],
}

On top of a simple .eslintrc.js file like this

module.exports = {
  root: true,
  env: {
    browser: true,
    node: true,
  },
  parserOptions: {
    parser: '@babel/eslint-parser',
    requireConfigFile: false,
  },
  extends: ['@nuxtjs']
}

Followed by this in the settings UI, should give you a great DX.

enter image description here

kissu
  • 24,311
  • 11
  • 36
  • 67