Rômulo Sorato
Rômulo Sorato

Reputation: 1651

Disable eslint Vue.js

I'm trying to complete a tutorial.

I'm stuck with an error that is caused by ESLint:

> Failed to compile.

./src/App.vue
Module Error (from ./node_modules/eslint-loader/index.js):

C:\Users\romul\Vue Projects\produto-client\src\App.vue
  110:36  error  'resposta' is defined but never used  no-unused-vars

✖ 1 problem (1 error, 0 warnings)

I want to know how to disable eslint.

This is my project structure:

enter image description here

I searched on the internet, but I couldn't understand how to disable it.

Upvotes: 5

Views: 17479

Answers (3)

StudioLE
StudioLE

Reputation: 743

The simplest solution is to set the lintOnSave: false in your vue.config.js file.

This simply stops the eslint-loader running when the file is compiled.

// vue.config.js
module.exports = {
  lintOnSave: false
}

The better solution is to set lineOnSave: 'warning' which ensures that eslint errors are emitted as warnings therefore the errors aren't surpressed but they also don't prevent the compiling.

// vue.config.js
module.exports = {
  lintOnSave: 'warning'
}

See documentation here: https://cli.vuejs.org/config/#lintonsave

Upvotes: 0

Gino Mempin
Gino Mempin

Reputation: 29679

The correct solution to your problem is to actually follow the linter error and remove the unused variables from your code, either temporarily comment them out or delete the line entirely. Disabling the linter is a temporary workaround, but should not be a long-term solution.

But, for the purposes of your question, it is possible to disable the linter (ESLint).

When creating the standard Vue app directory, you have the option of enabling ESLint and storing the ESLint configuration in either the package.json or in a separate .eslintrc.js file. From your screenshot, it seems you added the ESLint configuration in your package.json, like this:

enter image description here

See that eslintConfig block?

  "eslintConfig": {
    "root": true,
    "env": {
      "node": true
    },
    "extends": [
      "plugin:vue/essential",
      "@vue/standard"
    ],
    "parserOptions": {
      "parser": "babel-eslint"
    },
    "rules": {}
  },

You can enable/disable specific ESLint rules in the rules block.
For example, for no-unused-vars:

    "rules": {
        "no-unused-vars": "off"
    }

Then make changes to the src files and save (the default Vue configuration is to run the linter on save).

If the ESLint rules are in a separate .eslintrc.js file, the procedure is the same, just on/off specific rules under the rules block.

Or, if you want to disable ESLint entirely, create a vue.config.js file with the lintOnSave setting set to false:

// vue.config.js
module.exports = {
    lintOnSave: false
}

Now, running the app (npm run serve) won't anymore trigger the linter.

Additionally, if you are using VS Code, it supports ESLint integration. I'm not sure if the rest of your tutorial will also discuss linting with VS Code, but it can/might also report some errors/warnings in the Problems tab.

You can disable them from your User/Workspace settings:

"eslint.enable": false,

Upvotes: 6

Hank X
Hank X

Reputation: 2054

several ways to do this:

  • create a .eslintignore file at the root of your project, and input **/*. this will ignore all files in your project

OR

  • create a .eslintrc.json file at the root of your project. and input
{
  "rules":{
  "no-unused-vars": "off"
 }
}

this will suppress the specific error you are getting.

Upvotes: 0

Related Questions