简体   繁体   English

如何在 VS Code 中设置 Airbnb ESLint?

[英]How to set up Airbnb ESLint in VS Code?

I've tried for hours to set up ESLint using the Airbnb linter in Visual Studio Code.我已经尝试了几个小时来使用 Visual Studio Code 中的 Airbnb linter 设置 ESLint。 I ran the commands found here: https://www.npmjs.com/package/eslint-config-airbnb and set the peer dependencies to the correct versions, but still no luck.我运行了在这里找到的命令: https : //www.npmjs.com/package/eslint-config-airbnb并将对等依赖项设置为正确的版本,但仍然没有运气。 I always get this error:我总是收到这个错误:

Unexpected top-level property "“extends”".意外的顶级属性“扩展”。 . . Please see the 'ESLint' output channel for details.有关详细信息,请参阅“ESLint”输出通道。

Does anyone know of a fix for this?有谁知道解决这个问题? I've read so many blogs and threads to no avail and am at the point where it seems like it's just more hassle than it's worth, though everyone says the Airbnb style guide is best for React.我已经阅读了很多博客和主题,但都无济于事,现在看起来似乎比它的价值更麻烦,尽管每个人都说 Airbnb 风格指南最适合 React。

  1. Install the ESLint extension for VS Code . 为 VS Code安装ESLint 扩展 This will cause lint errors to show up inline, directly in the code editor (as opposed to just showing in the terminal when you use the command line).这将导致直接在代码编辑器中内联显示 lint 错误(而不是在使用命令行时仅在终端中显示)。
  2. Install eslint-config-airbnb and all of the dependencies (follow the instructions in the documentation).安装eslint-config-airbnb和所有依赖项(按照文档中的说明进行操作)。 If you're using npm 5+, simply run this command in your terminal while inside of the project directory: npx install-peerdeps --dev eslint-config-airbnb .如果您使用的是 npm 5+,只需在项目目录中的终端中运行此命令: npx install-peerdeps --dev eslint-config-airbnb
  3. Setup your ESLint configuration .设置您的ESLint 配置 You can add a basic config in your package.json file under the eslintConfig property, like so: "eslintConfig": { "extends": "airbnb" }您可以在eslintConfig属性下的package.json文件中添加基本配置,如下所示: "eslintConfig": { "extends": "airbnb" }

If you've done all of the above steps and are still getting the error you mentioned, see this thread , where a number of potential solutions are mentioned in the comments.如果您已完成上述所有步骤但仍然遇到您提到的错误,请参阅此线程,其中评论中提到了许多潜在的解决方案。

Specifically, in your case it sounds like your configuration is not getting read properly, for whatever reason.具体来说,在您的情况下,无论出于何种原因,您的配置听起来都没有正确读取。 I would try adding it to your package.json as mentioned above to see if that solves it.我会尝试如上所述将其添加到您的package.json中,看看是否能解决它。

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

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