Skip to content

Allow commented multiline type alias - #1044

Merged
vinistock merged 2 commits into
mainfrom
vs_allow_commented_multiline_alias
Oct 29, 2026
Merged

vinistock merged 2 commits into
mainfrom
vs_allow_commented_multiline_alias

Conversation

@vinistock

@vinistock vinistock commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

We have a few cases of type aliases where the specific parts are documented. For example:

Alias = T.type_alias do
  T::Hash[
    String, # the name of the thing
    Integer, # the value of the thing
  ]
end

Translating these to RBS type checks properly, but Spoom incorrectly rewrites them from RBS to sig. We should fix this because not supporting these trailing comments make it quite weird to document specific parts of the aliases since there are no names to "attach" the comment to. For example:

# How do you document without repeating everything? It's a bit odd.
# For this case, it's relatively fine because the type is simple, but more complex
# types make this a mess.
#
#: type alias = Hash[
#|   String,
#|   Integer
#| ]

This PR fixes the rewriting to allow for commented multiline type aliases.

@vinistock vinistock self-assigned this Oct 28, 2026
@vinistock vinistock added the bugfix Fix a bug label Oct 28, 2026
@vinistock
vinistock requested a review from a team as a code owner October 28, 2026 14:44

@Morriar Morriar left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

From the PR description it sounded like the issue was translating Sorbet type alias with comments to RBS but the code shows the opposite?

#: type header = Hash[
#| String, # the name
#| String, # the value
#| ]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Don't we want the comments to survive after translation?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I was mostly concerned with the rewrite being valid, but your point is fair we should preserve the comments.

The latest commit preserves them, but there's one caveat: they are place above the type instead of as a trailing comment.

We can definitely do the more sophisticated version of this, but it requires more refactors because, at the moment, there's no easy way to associate each line's comment with part of a type (i.e.: the alias is a single Type that spans across multiple lines).

@vinistock
vinistock requested a review from KaanOzkan October 28, 2026 19:52
@vinistock
vinistock force-pushed the vs_allow_commented_multiline_alias branch from 9db232c to 26ea68c Compare October 28, 2026 20:16
@vinistock
vinistock merged commit 85f362d into main Oct 29, 2026
11 checks passed
@vinistock
vinistock deleted the vs_allow_commented_multiline_alias branch October 29, 2026 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Fix a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants