63

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
  • 115,751
  • 26
  • 228
  • 437
Ricardo Moreira
  • 947
  • 1
  • 9
  • 20

6 Answers6

46

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
  • 40,416
  • 14
  • 65
  • 133
Mahamudul Hasan
  • 2,745
  • 2
  • 17
  • 26
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
  • 40,416
  • 14
  • 65
  • 133
Nilanshu Jaiswal
  • 1,583
  • 3
  • 23
  • 34
7

If anyone facing this issue when working with Cloud Functions try this. Find package.json file inside functions folder, replace

"lint": "eslint --ext .js,.ts .",

with

"lint": "eslint --ext .js,.ts . --fix",

Then run the command again:

firebase deploy --only functions

It should fix all issues which fixable. If any error left (sometimes 1 or 2 still left) find that one and edit manually and voila it works.

Elmar
  • 2,235
  • 24
  • 22
3

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
  • 40,416
  • 14
  • 65
  • 133
1

Ran into this error, potentionally fixable with the '--fix' option., unfortunately npm run lint -- --fix didn't do anything. Running npm run format fixed the errors.

  • lint is for flagging errors
  • format is for fixing errors
"scripts": {
    "lint": "eslint \"**/*.{js,mjs}\" && prettier --check --loglevel warn \"**/*.{js,mjs,json}\" && stylelint \"**/*.scss\"",
    "format": "eslint \"**/*.{js,mjs}\" --fix && prettier --write --loglevel warn \"**/*.{js,mjs,json}\" && stylelint \"**/*.scss\" --fix",
}
jpllosa
  • 2,066
  • 1
  • 28
  • 30
1

I am also face the same problem.

Then I got a solution

use this command :-> npm run lint:js -- --fix

Hope your problem will be solved

Meheraz
  • 41
  • 2