Replacement/improvement of `func-name-matching` eslint rule
まだ誰も着手していません。
- 主要言語
- JavaScript
- スター
- 122k
- フォーク
- 37.3k
- 平均マージ
- 4日 2時間
- マージ済み PR(30日)
- 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 にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、ESLint のリンクされた func-name-matching ルールと、Node.js のリンクされた reporters.js の例を読み、次に ObjectDefineProperty、ObjectDefineProperties、ReflectDefineProperty の descriptor がどのように表現されているかを比較します。カスタムルールが他の箇所で通常のマッチングを維持し、named value になる descriptor 関数を拒否し、指定どおりに単純な文字列のプロパティ名を処理できれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- eslint, javascript
- 領域
- tooling
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 活発
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100