-
Notifications
You must be signed in to change notification settings - Fork 653
feat(rome_js_analyze): noDuplicateClassMembers
#4137
Conversation
✅ Deploy Preview for docs-rometools ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site settings. |
It could be nice to have an action for removing the overwritten member (Similarly to |
Thank for your suggestion. I think the action for removing the overwritten member is not needed. This is because it is not enough to delete the last overwritten member about duplicated members . In some cases, users want to delete the member defined firstly. This is not up to us. ESLint and other rules(like |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might want to look at https://github.com/rome/tools/pull/4130/files , maybe some logic can be joined
crates/rome_js_analyze/src/analyzers/nursery/no_duplicate_class_members.rs
Outdated
Show resolved
Hide resolved
JsMethodModifierList(JsMethodModifierList), | ||
} | ||
|
||
fn get_static_type(modifier_list: AnyModifierList) -> StaticType { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can avoid the enum AnyModifierList
by accepting a JsSyntaxList
instead. From a typed list - for example, JsPropertyModifierList
- you can retrieve a generic list using syntax_list
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I refactored get_static_type
to is_static_member
which accepts JsSyntaxList
.
crates/rome_js_analyze/src/analyzers/nursery/no_duplicate_class_members.rs
Outdated
Show resolved
Hide resolved
crates/rome_js_analyze/src/analyzers/nursery/no_duplicate_class_members.rs
Outdated
Show resolved
Hide resolved
crates/rome_js_analyze/src/analyzers/nursery/no_duplicate_class_members.rs
Outdated
Show resolved
Hide resolved
let static_type = member_def.static_type(); | ||
let member_type = member_def.member_type(); | ||
defined_members | ||
.entry((member_name, static_type, access_type)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the point of saving static_type
, access_type
and member_name
if they are all computed from member_def
? I think it's better to save member_def
at this point and implement Eq
, PartialEq
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I try to implement PartialEq and Eq for AnyClassMemberDefinition, but I couldn't because declare_node_union macro have already implemented PartialEq and Eq.
tools/crates/rome_rowan/src/macros.rs
Line 69 in 44a0933
#[derive(Clone, PartialEq, Eq, Hash)] |
How do I resolve this error?
error[E0119]: conflicting implementations of trait `std::cmp::PartialEq` for type `analyzers::nursery::no_duplicate_class_members::AnyClassMemberDefinition`
--> crates/rome_js_analyze/src/analyzers/nursery/no_duplicate_class_members.rs:144:1
|
144 | / declare_node_union! {
145 | | pub(crate) AnyClassMemberDefinition = JsGetterClassMember | JsMethodClassMember | JsPropertyClassMember | JsSetterClassMember
146 | | }
| |_^ conflicting implementation for `analyzers::nursery::no_duplicate_class_members::AnyClassMemberDefinition`
...
174 | impl PartialEq for AnyClassMemberDefinition {
| ------------------------------------------- first implementation here
|
= note: this error originates in the derive macro `PartialEq` which comes from the expansion of the macro `declare_node_union` (in Nightly builds, run with -Z macro-backtrace for more info)
For more information about this error, try `rustc --explain E0119`.
error: could not compile `rome_js_analyze` due to previous error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh sorry, then there's no need to manually implement it :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the point of saving static_type, access_type and member_name if they are all computed from member_def?
These values are necessary for an unique key about judging whether the class member has already defined or not. I seem AnyClassMemberDefinition
is not able to used as a key. If you think AnyClassMemberDefinition
could be used as a key of HashMap, can you show more details?
…s_members.rs Co-authored-by: Emanuele Stoppa <my.burning@gmail.com>
a365b19
to
1bcf95a
Compare
Thank you for your reviews! I refactored this PR based on your comments. I would appreciate if you could review again. |
I see #4143 (comment) and updated again. This PR is ready for review. |
987d96f
to
732ec84
Compare
This PR is stale because it has been open 14 days with no activity. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once rebased, we can merge it!
I resolved conflicts. This PR is ready to merge 🚀 |
Summary
Fix #3963
Test Plan
I made the same test cases as in ESLint. In this PR, this rule doesn't support computed and numerical properties.
I refer to the following comments.
tools/crates/rome_js_analyze/tests/specs/nursery/noDuplicateObjectKeys.js
Lines 27 to 29 in b6e7a39
Documentation