【问题标题】:ESLint with Arbnb config and Facebook Flow togetherESLint 与 Arbnb 配置和 Facebook Flow 一起使用
【发布时间】:2016-07-15 11:16:41
【问题描述】:

我在一个项目中使用 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 任务中运行流?

【问题讨论】:

    标签: javascript facebook reactjs eslint flowtype


    【解决方案1】:

    对我来说,问题是通过将"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
      }
    }
    

    【讨论】:

      【解决方案2】:

      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 代替吗?

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-01-17
        • 1970-01-01
        • 2019-08-11
        • 2020-01-08
        • 2015-12-09
        • 2020-04-30
        • 2022-01-09
        • 1970-01-01
        相关资源
        最近更新 更多