Replacement/improvement of `func-name-matching` eslint rule
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- JavaScript
- Star
- 122k
- Fork
- 37.4k
- Merge trung bình
- 4 ngày 3 giờ
- Pull request đã merge (30 ngày)
- 272
Mô tả
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()
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu bằng cách đọc rule func-name-matching được liên kết của ESLint và ví dụ reporters.js được liên kết của Node.js, sau đó so sánh cách các descriptor của ObjectDefineProperty, ObjectDefineProperties và ReflectDefineProperty được biểu diễn. Được xem là hoàn thành khi một rule tùy chỉnh duy trì matching thông thường ở những nơi khác, từ chối các hàm descriptor trở thành named value và xử lý tên thuộc tính là chuỗi thuần theo như đặc tả.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- eslint, javascript
- Lĩnh vực
- tooling
- Loại issue
- Tính năng
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức độ hoạt động
- Sôi nổi
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 35/100