问题描述
class A {
#field;
constructor() {
this.#field = 'foo';
}
publicmethod() {
this.#privateMethod();
}
#privateMethod() { // The problem string
this.#field = 'bar';
}
}
const a = new A();
a.publicmethod();
我的.eslintrc中也启用了"func-names"
规则。
代码本身可以正常运行,但是eslint检查由于某些原因而失败:
.../src/index.js
12:17 error Unexpected unnamed function func-names
有什么方法可以让eslint正确处理此案吗?
设置为:
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"
]
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)