Eslint fails to parse and red-highlights optional chaining (?.) and nullish coalescing (??) operators

后端 未结 4 757
离开以前
离开以前 2021-02-05 05:26

I am looking for the relevant eslint rules for

  • @babel/plugin-proposal-optional-chaining
  • @babel/plugin-proposal-nullish-coalescing-operator

相关标签:
4条回答
  • 2021-02-05 06:03

    add the following config to your eslint:

    "parser": "babel-eslint"
    
    0 讨论(0)
  • 2021-02-05 06:05

    Nullish coalescing operator is natively supported starting from eslint>=7.5.0.

    The easiest is set ES2020 in your package.json:

    {
      "eslintConfig":
      {
        "parserOptions":
        {
          "ecmaVersion": 2020
        }
      }
    }
    
    0 讨论(0)
  • 2021-02-05 06:05

    Have you tried setting the parser on your eslint config to "babel-eslint"? https://www.npmjs.com/package/babel-eslint It's the recommended parser when using experimental features not supported in eslint yet.

    0 讨论(0)
  • 2021-02-05 06:17

    You have to use this plugin: https://github.com/babel/eslint-plugin-babel

    You can then disable the original eslint-rule and enable the babel version of it, which will then show no false errors. Your eslint-config could then look like this:

    {
      parser: "babel-eslint",
      rules: {
        "no-unused-expressions": 0,
        "babel/no-unused-expressions": 1
      },
      plugins: ["babel"]
    }
    
    0 讨论(0)
提交回复
热议问题