I have a code that uses private methods syntax in my index.js file:
class A {
#field;
constructor() {
this.#field = 'foo';
}
publicMethod() {
this.#privateMethod();
}
#privateMethod() { // The problem string
this.#field = 'bar';
}
}
const a = new A();
a.publicMethod();
I also have "func-names" rule enabled in my .eslintrc.
The code itself works perfectly, but eslint check fails for some reason:
.../src/index.js
12:17 error Unexpected unnamed function func-names
Is there any way to get eslint to process this case correctly?
The setup is:
package.json
...
"devDependencies": {
"@babel/core": "^7.12.3",
"@babel/eslint-parser": "^7.12.1",
"@babel/eslint-plugin": "^7.12.1",
"@babel/plugin-proposal-class-properties": "^7.12.1",
"@babel/plugin-proposal-private-methods": "^7.12.1",
"@babel/preset-env": "^7.12.1",
"babel-loader": "^8.1.0",
"eslint": "^7.5.0",
"webpack": "^5.2.0",
"webpack-cli": "^4.1.0"
},
...
.babelrc
{
"presets": [
["@babel/preset-env", { "targets": { "esmodules": true } } ]
],
"plugins": [
["@babel/plugin-proposal-class-properties", { "loose": true } ],
["@babel/plugin-proposal-private-methods", { "loose": true } ]
]
}
.eslintrc
{
"rules": {
"func-names": "error"
},
"parser": "@babel/eslint-parser",
"plugins": [
"@babel"
]
}