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 T::Enum handler #44

Merged
merged 4 commits into from
May 25, 2021
Merged

Add T::Enum handler #44

merged 4 commits into from
May 25, 2021

Conversation

dduugg
Copy link
Owner

@dduugg dduugg commented May 24, 2021

Resolves #43

Adds a simple T::Enum handler, which registers each enum as a constant. I don't love the formatting, but the content is clear enough:
image

The collapsed view is decent though:
image

@dduugg dduugg marked this pull request as draft May 24, 2021 04:32
@dduugg dduugg self-assigned this May 24, 2021
@dduugg dduugg marked this pull request as ready for review May 24, 2021 04:34
@dduugg dduugg closed this May 24, 2021
@dduugg dduugg reopened this May 24, 2021
@codecov
Copy link

codecov bot commented May 24, 2021

Codecov Report

Merging #44 (3e6fa76) into master (0e0dfd3) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master       #44   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            2         3    +1     
  Lines          266       287   +21     
=========================================
+ Hits           266       287   +21     
Impacted Files Coverage Δ
spec/yard_sorbet/enums_handler_spec.rb 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0e0dfd3...3e6fa76. Read the comment docs.

@dduugg dduugg changed the title WIP Enums handler Add T::Enum handler May 24, 2021
@dduugg dduugg requested a review from KaanOzkan May 24, 2021 20:47
@dduugg dduugg assigned KaanOzkan and unassigned dduugg May 24, 2021
@dduugg dduugg force-pushed the enums-handler branch 4 times, most recently from 6ac7bb4 to 1b93459 Compare May 25, 2021 00:13
Copy link
Contributor

@KaanOzkan KaanOzkan left a comment

Choose a reason for hiding this comment

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

This will display local variable assignments inside enums block as a constant in the yard output but I guess that's wrong usage of enums block and therefore we are okay with it?

@dduugg
Copy link
Owner Author

dduugg commented May 25, 2021

@KaanOzkan great catch! I think i fixed it in the latest commit, check it out. (I also checked non-enum constant assignments, e.g. Foo = 1, in an enums block, and sorbet raises a RuntimeError, so we don't have to contemplate that.)

Hearts = new
Clubs = new('Clubs')
diamonds_serialized_value = 'Diamonds'
Diamonds = new(diamonds_serialized_value)
Copy link
Owner Author

Choose a reason for hiding this comment

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

This will appear as new(diamonds_serialized_value) in the documentation, with no other reference to diamonds_serialized_value for clarity. I don't love that, but I can live with it. LMK if you have any thoughts.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm okay with it either way, I don't think this case is that important since people shouldn't be adding extra logic such as local variable assignments to enums blocks.

Copy link
Owner Author

Choose a reason for hiding this comment

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

This turns out to be consistent with YARD, if you write something pathological like:

class A
  b = 1
  C = b
end

so I think this is 🆗

@dduugg dduugg merged commit 9791ece into master May 25, 2021
@dduugg dduugg deleted the enums-handler branch May 25, 2021 21:07
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.

Add T::Enum support
2 participants