-
Notifications
You must be signed in to change notification settings - Fork 131
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
Rewrite attributes into methods #1936
base: main
Are you sure you want to change the base?
Conversation
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.
Yay, the changes look great. Just a small test improvement suggestion.
|
||
write!("lib/foo.rb", <<~RBI) | ||
class Foo | ||
attr_reader :i |
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.
Can we add the full set of attr_writer
, attr_reader
and attr_accessor
to this test please?
@@ -291,6 +291,16 @@ def merge_with_exported_rbi(gem, file) | |||
|
|||
tree = gem.exported_rbi_tree | |||
|
|||
begin | |||
tree.replace_attributes_with_methods! | |||
rescue RBI::UnexpectedMultipleSigsError => e |
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 don't know how I feel about this.
As implemented, this will leave the tree partially rewritten (up until the time when the multi-sigged attribute is found), and log this message.
Ideally, I'd just log the message from inside RBI and discard all but the first sig, but there's no existing logger API in RBI for this. Without that, I'd have to directly $stderr.puts ...
from within the RBI gem, but that feels very wrong.
Suggestions?
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.
We should discard the tree and return the original file as we do below in case of conflicts.
@@ -291,6 +291,16 @@ def merge_with_exported_rbi(gem, file) | |||
|
|||
tree = gem.exported_rbi_tree | |||
|
|||
begin | |||
tree.replace_attributes_with_methods! | |||
rescue RBI::UnexpectedMultipleSigsError => e |
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.
We should discard the tree and return the original file as we do below in case of conflicts.
$stderr.puts(<<~MSG) | ||
WARNING: Attributes cannot have more than one sig. | ||
|
||
#{e.node.string.chomp} | ||
MSG |
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.
$stderr.puts(<<~MSG) | |
WARNING: Attributes cannot have more than one sig. | |
#{e.node.string.chomp} | |
MSG | |
say_error("\n\n RBIs exported by `#{gem.name}` contain errors and can't be used:", :yellow) | |
say_error(" #{e.node.string.chomp}", :yellow) | |
return file |
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.
^ Since we have the node we should also give the location
Motivation
Closes #1918, depends on Shopify/rbi#308.
Implementation
Tests