结合 Arbnb 配置和 Facebook Flow 的 ESLint

ESLint with Arbnb config and Facebook Flow together

我在项目中使用 ESLint 并且也想使用 Facebook 流,但是我从 ESLint 收到有关流类型注释的警告。

我在项目根目录中有 .flowconfig 和 .eslintrc。

.eslintrc:

// When you write javascript you should follow these soft rules and best practices
// https://github.com/airbnb/javascript

// This is a link to best practices and enforcer settings for eslint
// https://github.com/airbnb/javascript/tree/master/packages/eslint-config-airbnb

// Use this file as a starting point for your project's .eslintrc.
{
  "extends": "airbnb",

  "plugins": [
    "flow-vars"
  ],
  "rules": {
    "flow-vars/define-flow-type": 1,
    "flow-vars/use-flow-type": 1
  }
}

我应该怎么做才能让它发挥作用?有没有办法 运行 使用 webpack 一起流入 watch 任务?

对我来说,通过将 "parser": "babel-eslint" 添加到我的 .eslintrc 来解决问题。

(我不得不先 运行 npm install babel-eslint --save-dev)。

{
  "extends": "airbnb",
  "parser": "babel-eslint", // <--
  "plugins": [
    "flow-vars"
  ],
  "rules": {
    "flow-vars/define-flow-type": 1,
    "flow-vars/use-flow-type": 1
  }
}

flow-vars 已弃用!

这是当前获得 Flow 运行 Airbnb 的正确方法(eslint-plugin-flowtype):

假设您已经安装了 flow

npm install --save-dev eslint babel-eslint eslint-plugin-flowtype

.eslintrc

{
  "extends": [
    "airbnb",
    "plugin:flowtype/recommended"
  ],
  "parser": "babel-eslint",
  "plugins": [
    "flowtype"
  ]
}

想要 custom configuration 吗?