简体   繁体   English

禁用 eslint Vue.js

[英]Disable eslint Vue.js

I'm trying to complete a tutorial .我正在尝试完成一个教程

I'm stuck with an error that is caused by ESLint:我遇到了由 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.我想知道如何禁用 eslint。

This is my project structure:这是我的项目结构:

在此处输入图片说明

I searched on the internet, but I couldn't understand how to disable it.我在互联网上搜索,但我不明白如何禁用它。

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.解决问题的正确方法是实际跟踪 linter 错误并从代码中删除未使用的变量,或者暂时将它们注释掉或完全删除该行。 Disabling the linter is a temporary workaround, but should not be a long-term solution.禁用 linter 是一种临时解决方法,但不应是长期解决方案。

But, for the purposes of your question, it is possible to disable the linter (ESLint).但是,就您的问题而言,可以禁用 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.创建标准 Vue 应用程序目录时,您可以选择启用 ESLint 并将 ESLint 配置存储在package.json或单独的.eslintrc.js文件中。 From your screenshot, it seems you added the ESLint configuration in your package.json , like this:从您的屏幕截图来看,您似乎在package.json 中添加了 ESLint 配置,如下所示:

在此处输入图片说明

See that eslintConfig block?看到那个eslintConfig块了吗?

  "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.您可以在rules块中启用/禁用特定的ESLint 规则
For example, for no-unused-vars :例如,对于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 ).然后对src文件进行更改并保存(默认的 Vue 配置是在 save 上运行 linter )。

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.如果 ESLint 规则在单独的.eslintrc.js文件中,则过程相同,只是在rules块下打开/关闭特定规则。

Or, if you want to disable ESLint entirely, create a vue.config.js file with the lintOnSave setting set to false :或者,如果您想完全禁用 ESLint,请创建一个vue.config.js文件,并将lintOnSave设置设置为false

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

Now, running the app ( npm run serve ) won't anymore trigger the linter.现在,运行应用程序 ( npm run serve ) 将不再触发 linter。

Additionally, if you are using VS Code, it supports ESLint integration .此外,如果您使用 VS Code,它支持ESLint 集成 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.我不确定您的教程的其余部分是否也会讨论使用 VS Code 进行 linting,但它可以/也可能会在“问题”选项卡中报告一些错误/警告。

You can disable them from your User/Workspace settings:您可以从您的用户/工作区设置中禁用它们:

"eslint.enable": false,

several ways to do this:有几种方法可以做到这一点:

  • create a .eslintignore file at the root of your project, and input **/* .在项目的根目录创建一个.eslintignore文件,然后输入**/* this will ignore all files in your project这将忽略您项目中的所有文件

OR或者

  • create a .eslintrc.json file at the root of your project.在项目的根目录创建一个.eslintrc.json文件。 and input和输入
{
  "rules":{
  "no-unused-vars": "off"
 }
}

this will suppress the specific error you are getting.这将抑制您遇到的特定错误。

The simplest solution is to set the lintOnSave: false in your vue.config.js file.最简单的解决方案是在 vue.config.js 文件中设置lintOnSave: false

This simply stops the eslint-loader running when the file is compiled.这只是在编译文件时停止 eslint-loader 运行。

// 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.更好的解决方案是设置lineOnSave: 'warning'以确保将 eslint 错误作为警告发出,因此错误不会被抑制,但它们也不会阻止编译。

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

See documentation here: https://cli.vuejs.org/config/#lintonsave请参阅此处的文档: https : //cli.vuejs.org/config/#lintonsave

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM