是否存在禁止使用name函数属性的 eslint 规则?
当您缩小代码时,它通常会破坏函数的名称。所以在开发中,myFunc.name会是这样'myFunc',但在生产中会是这样的'a'。这是一把开发枪,我想阻止这种情况发生。
eslint-plugin-ban仅适用于调用表达式,但我想要一些适用于访问属性(MemberExpression)的东西。
有一个有点不同的 eslint 插件https://runebook.dev/en/docs/eslint/rules/no-restricted-syntax
我用它来警告constructor.name具有以下 eslint 规则设置(yaml 语法)的用法:
"no-restricted-syntax":
- warn
- selector: MemberExpression[object.property.name='constructor'][property.name='name']
message: "'constructor.name' is not reliable (can become 'E', 'P' and etc.) after standard angular production build (JavaScriptOptimizer)."
Run Code Online (Sandbox Code Playgroud)
PS:有一个工具https://estools.github.io/esquery/用于调试 ES AST 查询,可用于no-restricted-syntax
更新: 还有更方便的工具来调试语法规则: https://typescript-eslint.io/play/#ts=4.7.2&sourceType=module&showAST=es
| 归档时间: |
|
| 查看次数: |
873 次 |
| 最近记录: |