Replacement/improvement of `func-name-matching` eslint rule
还没有人认领这个 Issue。
- 主要语言
- JavaScript
- 星标
- 122k
- 派生
- 37.3k
- 平均合并
- 4 天 2 小时
- 30 天内合并 PR
- 283
描述
There are quite a few places where a property is defined like this:
ObjectDefineProperty(someObject, 'someFunction', {
__proto__: null,
value: function() {
/* `someObject.someFunction`'s body */
},
});
As result, we end up with quite a few functions named value:
someObject.someFunction.name === 'value'
There is a func-name-matching rule in eslint that enforces function names to match the property names. However, in these cases, this rule rejects correct code and insists that these functions must be named value, to the point that in some places we have them explicitly named like this: https://github.com/nodejs/node/blob/cb5f671a34da32e3c2d70d7f3e7f869cda6b806b/lib/test/reporters.js#L56
I think, it would be nice to have a custom linter rule that:
- works the same way as
func-name-matchingeverywhere outside ofObjectDefineProperty,ObjectDefineProperties, andReflectDefineProperty - in the descriptors in these functions, the rule should be reversed: it should not allow the function to end up with a name
value - (ideally) if property name(s) is defined as plain string, the function name must match this string
I'm not familiar with eslint rules definitions but the original func-name-matching rule seems to be defined here: https://github.com/eslint/eslint/blob/e8f8d57bd6c0d95f9f25db8c5b3ff72de42488b7/lib/rules/func-name-matching.js.
The rule already has considerPropertyDescriptor option, but it's not applicable here because:
- it recognizes the normal form of these functions (
Object.defineProperty) but not primordials (ObjectDefineProperty) - it still allows both implicitly inherited name (
value: function() {) and concise notation (value() {) - it also disables the rule inside of
Object.create()
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
先阅读 ESLint 链接的 func-name-matching 规则和 Node.js 链接的 reporters.js 示例,然后比较 ObjectDefineProperty、ObjectDefineProperties 和 ReflectDefineProperty 的 descriptor 是如何表示的。完成的标准是:自定义规则在其他位置保留正常的匹配行为,拒绝会变成 named value 的 descriptor 函数,并按指定方式处理普通字符串属性名。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- eslint, javascript
- 领域
- tooling
- Issue 类型
- 功能
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 活跃
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100