最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Allow using ?. syntax in eslint - Stack Overflow

programmeradmin2浏览0评论

I used the ?. syntax in my code, but when I configure eslint into my project, they marked such constructions as a parsing error (Unexpected token) const currentFiles = folder?.files

Here is my eslint configuration

{
    "extends": ["airbnb", "prettier"],
    "plugins": ["prettier"],
    "rules": {
      "prettier/prettier": ["error"],
      "react/react-in-jsx-scope": "off",
      "import/no-unresolved": "off",
      "react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }],
      "jsx-a11y/label-has-associated-control": ["error", {
        "required": {
          "some": ["nesting", "id"]
        }
      }],
      "jsx-a11y/label-has-for": ["error", {
        "required": {
          "some": ["nesting", "id"]
        }
      }]
    }
  }

Is there a way to configure linter somehow so it won't be any error anymore?

I used the ?. syntax in my code, but when I configure eslint into my project, they marked such constructions as a parsing error (Unexpected token) const currentFiles = folder?.files

Here is my eslint configuration

{
    "extends": ["airbnb", "prettier"],
    "plugins": ["prettier"],
    "rules": {
      "prettier/prettier": ["error"],
      "react/react-in-jsx-scope": "off",
      "import/no-unresolved": "off",
      "react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }],
      "jsx-a11y/label-has-associated-control": ["error", {
        "required": {
          "some": ["nesting", "id"]
        }
      }],
      "jsx-a11y/label-has-for": ["error", {
        "required": {
          "some": ["nesting", "id"]
        }
      }]
    }
  }

Is there a way to configure linter somehow so it won't be any error anymore?

Share Improve this question edited Jun 19, 2021 at 19:07 glinda93 8,4996 gold badges50 silver badges87 bronze badges asked Jun 19, 2021 at 19:02 Екатерина ЯцкивЕкатерина Яцкив 651 silver badge6 bronze badges 1
  • What react version? and how you created the project? CRA ? eslint version ? and code example ? – sathishk2030 Commented Jun 19, 2021 at 19:11
Add a ment  | 

1 Answer 1

Reset to default 8

Support of ?. operator (optional chaining) has been added to ESLint in version 7.5.0:

The default parser and built-in rules will support this syntax when you enable parserOptions.ecmaVersion: 2020 in your configuration:

{
    "parserOptions": {
        "ecmaVersion": 2020
    }
}
发布评论

评论列表(0)

  1. 暂无评论