-
Notifications
You must be signed in to change notification settings - Fork 23
Translate T.cast
and T.must
into RBS comments
#714
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
Conversation
5e801ba
to
23a9d85
Compare
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 happens to constructs like:
foo = T.cast(T.must(T.must(bar).baz).quux, String)
If we are not handling them then it might be good to make that explicit in the option messages and with tests.
lib/spoom/cli/srb/assertions.rb
Outdated
@@ -11,6 +11,9 @@ class Assertions < Thor | |||
desc "translate", "Translate type assertions from/to RBI and RBS" | |||
option :from, type: :string, aliases: :f, desc: "From format", enum: ["rbi"], default: "rbi" | |||
option :to, type: :string, aliases: :t, desc: "To format", enum: ["rbs"], default: "rbs" | |||
option :let, type: :boolean, desc: "Translate `T.let` to `nil #: String?`", default: true |
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.
The inclusion of nil
here looks out of place to me:
option :let, type: :boolean, desc: "Translate `T.let` to `nil #: String?`", default: true | |
option :let, type: :boolean, desc: "Translate `T.let` to `#: String`", default: true |
I think a better message would be:
option :let, type: :boolean, desc: "Translate `T.let` to `nil #: String?`", default: true | |
option :let, type: :boolean, desc: "Translate `T.let(x, String)` to `x #: String?`", default: true |
lib/spoom/cli/srb/assertions.rb
Outdated
option :cast, type: :boolean, desc: "Translate `T.cast` to `# as String`", default: true | ||
option :must, type: :boolean, desc: "Translate `T.must` to `# as not nil`", default: true |
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.
If my suggestion above is accepted, then better messages would be:
option :cast, type: :boolean, desc: "Translate `T.cast` to `# as String`", default: true | |
option :must, type: :boolean, desc: "Translate `T.must` to `# as not nil`", default: true | |
option :cast, type: :boolean, desc: "Translate `T.cast(x, String)` to `x # as String`", default: true | |
option :must, type: :boolean, desc: "Translate `T.must(x)` to `x # as !nil`", default: true |
lib/spoom/cli/srb/assertions.rb
Outdated
option :cast, type: :boolean, desc: "Translate `T.cast` to `# as String`", default: true | ||
option :must, type: :boolean, desc: "Translate `T.must` to `# as not nil`", default: true |
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.
option :cast, type: :boolean, desc: "Translate `T.cast` to `# as String`", default: true | |
option :must, type: :boolean, desc: "Translate `T.must` to `# as not nil`", default: true | |
option :cast, type: :boolean, desc: "Translate `T.cast` to `# as String`", default: true | |
option :must, type: :boolean, desc: "Translate `T.must` to `# as !nil`", default: true |
lib/spoom/sorbet/assertions.rb
Outdated
@annotation_methods << :let if let | ||
@annotation_methods << :cast if cast | ||
@annotation_methods << :must if must | ||
|
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.
It might be a good idea to do:
@annotation_methods.freeze |
here.
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
23a9d85
to
176a625
Compare
Major rewrite on top of #734. |
176a625
to
b66e878
Compare
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
b66e878
to
8d9b887
Compare
This will now allow to translate
T.must
into RBS comments so this:becomes this:
And
T.must
so this:becomes this: