Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add VarNode class for lvar, ivar, cvar and gvar node types #204

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dvandersluis
Copy link
Member

Adds node classes for variables, to have symmetry with the assignment nodes. eg. a lvasgn and lvar for the same variable should have the same value for the #name method.

@@ -19,6 +19,7 @@ def namespace
def name
node_parts[1]
end
alias short_name name
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CasgnNode and Const should have a symmetrical interface so that they can be compared (eg. in Lint/SelfAssignment).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, but maybe the best would be to simply move all the implementation of Const to a module and include this here too?

@dvandersluis
Copy link
Member Author

@marcandre
Copy link
Contributor

marcandre commented Aug 13, 2021

Any ideas?

Sorry, that's my code 😅 .
It could be adapted so that it creates the right type of node, base on the existence of VarNode or not...?
Or change the test to compare [type, name] instead of the nodes directly.

@dvandersluis
Copy link
Member Author

dvandersluis commented Aug 17, 2021

Is there a way we can update s to return the right class instead of Node for all node types? That probably would be the "best" solution IMO.

It could be adapted so that it creates the right type of node, base on the existence of VarNode or not...?

Do you mean something like:

if defined?(RuboCop::AST::VarNode) ? RuboCop::AST::VarNode.new(...) : s(...)

Or change the test to compare [type, name] instead of the nodes directly.

I don't think we can do this because I think the issue is this fetch: https://github.com/rubocop/rubocop/blob/2fe4b1a6faca23adff13e1bbff6ecf5b66c6447b/lib/rubocop/cop/metrics/utils/repeated_attribute_discount.rb#L114

I've had a little trouble tracing what's happening in that class though so I may be offbase.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants