-
Notifications
You must be signed in to change notification settings - Fork 26
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
Proof of concept: Create a cop to validate gem version annotations in RBI files #199
base: main
Are you sure you want to change the base?
Conversation
While adding gem version annotations to RBI files would allow developers to write more comprehensive RBIs for their gems, it has has the potential to create RBI files that are cluttered, disorganized, or incorrect. This would be the first of a few cops meant to keep versioned RBIs clean and accurate. This cop checks that every version included in a "@Version" annotation fits the format specified by the RBI library.
029c92d
to
436eddc
Compare
return false unless VALID_OPERATORS.include?(operator) | ||
|
||
begin | ||
Gem::Version.new(version) |
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.
Wdyt of using the underlying method instead? https://github.com/rubygems/rubygems/blob/40784bb244f7471fa938a421e2773ec2c7a45405/lib/rubygems/version.rb#L173C12-L177.
It won't rely on exception throwing but it might be more brittle to future changes. Although I doubt the interface will go through frequent changes.
|
||
See the rubygems.org documentation for more information on how to format gem | ||
versions: https://guides.rubygems.org/patterns/#pessimistic-version-constraint | ||
Enabled: 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.
I'm not sure it safe to enable by default since shims or generated gem RBIs may have surprising comments.
Don't we intend Tapioca to strip the version tagging when pulling annotations? I think we also talked about the possibility to merge annotations directly into the generated gem RBIs right?
RUBY | ||
end | ||
|
||
it "registers an offense when gem version is not formatted correctly" do |
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.
Let's add a test for an empty @version
without an operator and one for @version foo
.
This PR has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This PR has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This PR has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Created as part of hackdays, along with Shopify/rbi#180 and Shopify/tapioca#1585
While adding gem version annotations to RBI files would allow developers to write more comprehensive RBIs for their gems, it has has the potential to create RBI files that are cluttered, disorganized, or incorrect.
This would be the first of a few cops meant to keep versioned RBIs clean and accurate.
This cop checks that every version included in a "@Version" annotation fits the format specified by the RBI library.