ESLintでクラス構文の static 変数 エラー警告を消す

JavaScript

クラス構文内でstatic変数を指定したら unexpected token 警告が出たので対処しました。
どうやらデフォルトのEspreeはstage4 まで行ったものじゃないとサポートしないらしいです。

Eslint’s default parser, Espree, does not support class fields because that syntax is currently stage 3, and that it is decided that only stage 4 proposals are to be supported in Espree.

Attention Required! | Cloudflare

解決方法はデフォルトのパーサーを切り替えます。
@babel/eslint-parser をインストールして、

npm install -D @babel/eslint-parser

eslintの設定ファイルにパーサーの指定を追加します。

# .eslintrc.json
{
    "parser": "@babel/eslint-parser",
    ...
}

コメント