简体   繁体   English

如何在Atom中正确设置Airbnb的javascript linter?

[英]How to properly setup the Airbnb's javascript linter in Atom?

Surprisingly, there is not any good guide on this. 令人惊讶的是,没有任何好的指南。 I cannot make the linter work. 我无法使棉绒工作。 I have set the .eslintrc that extends airbnb on the directory where I save all my projects. 我已经设置了.eslintrc,它将airbnb扩展到我保存所有项目的目录中。 I do not know if it is the right directory. 我不知道它是否是正确的目录。 I also did this . 我也这样做 Nothing is being lint in Atom (the file does have linting errors), so I guess there are some missing steps. 在Atom中没有任何东西是lint(文件确实有linting错误),所以我猜有一些缺失的步骤。

Found this guide. 找到了这个指南。 It works fine now. 它现在工作正常。

Relevant info from the link: 链接中的相关信息:

Configuring ESLint in your project 在项目中配置ESLint

The first thing we need to do is configure ESLint in our project. 我们需要做的第一件事是在我们的项目中配置ESLint。 Remember we are going to use the AirBnB style guide so we need no install the required package and make our ESLint configuration extend from the AirBnB ESLint configuration. 请记住,我们将使用AirBnB样式指南,因此我们无需安装所需的软件包,并使我们的ESLint配置从AirBnB ESLint配置扩展。

Install ESLint locally to your project: > npm install eslint --save-dev . 在本地安装ESLint到您的项目: > npm install eslint --save-dev Install the AirBnB ESLint configuration. 安装AirBnB ESLint配置。 Following package instructions we need to execute next sentences to install the right package versions and dependencies: 按照包说明,我们需要执行下面的句子来安装正确的包版本和依赖项:

> export PKG=eslint-config-airbnb;
> npm info "$PKG" peerDependencies --json | command sed 's/[\{\},]//g ; s/: /@/g' | xargs npm install --save-dev "$PKG"

Create a .eslintrc file in the root of our project. 在项目的根目录中创建.eslintrc文件。 We must be sure to include the property "extends": "airbnb" as part of the configuration. 我们必须确保将属性"extends": "airbnb"作为配置的一部分。 Next is a sample configuration file. 接下来是一个示例配置文件。 Note we inherited configuration from AirBnB. 注意我们从AirBnB继承了配置。 In addition, we have added the eslint rules valid-jsdoc and require-jsdoc to forces us to write some JSDoc for functions, methods and classes. 另外,我们添加了eslint规则valid-jsdocrequire-jsdoc来强制我们为函数,方法和类编写一些JSDoc。

{
  "extends": "airbnb",
  "parser": "babel-eslint",
  "env": {
    "browser": true,
    "node": true,
    "es6": true,
    "mocha": true
  },
  "rules": {
    "valid-jsdoc": ["error", {
      "requireReturn": true,
      "requireReturnType": true,
      "requireParamDescription": true,
      "requireReturnDescription": true
    }],
    "require-jsdoc": ["error", {
        "require": {
            "FunctionDeclaration": true,
            "MethodDefinition": true,
            "ClassDeclaration": true
        }
    }]
  }
}

Right now our project is configured with ESLint and the base set of rules from AirBnB, but it requires we execute ESLint manually or automatize in some way (in the build process). 现在我们的项目配置了ESLint和AirBnB的基本规则集,但它要求我们手动执行ESLint或以某种方式自动化(在构建过程中)。

Installing Atom plugins 安装Atom插件

Let's go to configure Atom to automatically lint files and show us messages while coding. 让我们将Atom配置为自动lint文件并在编码时向我们显示消息。

Be sure you have completed successfully the previous sections. 确保您已成功完成前面的部分。

Install the Atom plugin linter-eslint . 安装Atom插件linter-eslint You are finished :) The plugin will detect automatically the .eslintrc file in your project and will start linting on the fly the source code showing all the errors and warning. 你完成了:)插件会自动检测项目中的.eslintrc文件,并会立即开始显示所有错误和警告的源代码。

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

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