javascriptnode.jseslintclass-fields

Eslint does not allow static class properties


I'm current developing an API on Node 12.14.1 and using Eslint to help me write the code. Unfortunately it does not allow me to set static class properties as shown below:

class AuthManager {
  static PROP = 'value'
}

The following error is given: Parsing error: Unexpected token =eslint

Static class properties are already supported on JS and on Node.
How can this rule be disable?

I also have the following .eslintrc.json file:

{
  "env": {
      "es6": true,
      "node": true
  },
  "extends": "eslint:recommended",
  "globals": {
      "Atomics": "readonly",
      "SharedArrayBuffer": "readonly"
  },
  "parserOptions": {
      "ecmaVersion": 2018,
      "sourceType": "module"
  }
}

Solution

  • ESLint v8 now supports static class properties natively: https://eslint.org/blog/2021/10/eslint-v8.0.0-released

    parserOptions ecmaVersion should be set to 13, 2022, or "latest" to enable the support.

    Add this to your .eslint.(cjs | json | js)

    {
      parserOptions: {
        ecmaVersion: 2022,
      }
    }