Allow using ?. syntax in eslint

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?

Upvotes: 5

Views: 2839

Answers (1)

raina77ow
raina77ow

Reputation: 106395

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
    }
}

Upvotes: 8

Related Questions