Conversation
96b3025 to
edca009
Compare
e48fed9 to
8e980f5
Compare
54496e6 to
a0e470d
Compare
Shipping the RBI file with the gem like this means downstream users of
pdf-reader who also use sorbet will know the types pdf-reader expects
for its public API.
Storing the sigs outside the source files also means there's no need to
add sorbet-runtime as a dependency of the gem, and downstream users of
pdf-reader who do not use sorbet will see no change.
I generated the RBI file with parlour:
bundle exec parlour
I assume I'll have to regenerate it over time as the methods on each
class evolve. That sounds like a huge hassle, but this is an experiment
so lets see how it goes.
The parlour config file ignore lib/pdf/reader/parser.rb because I get a
NoMethodError if I leave it in.
Recent versions of sorbet require this. The rbi file was automatically
updated to meet this requirement with:
bundle update sorbet
bundle exec srb tc -a
Newer versions of sorbet introduce changes that will break type checks and require some intervention. This forces a fixed version so all developers and the CI environment will get consistent behaviour, and we can update intentionally when we're ready.
srb rbi gems changed these sigils for me 🤷♂️
sorbet doesn't work with ruby < 2.3, but that's OK. We don't really need it to. We mainly need sorbet in two places: * the dev environment * a single CI step with a version of ruby that sorbet supports, to run the type checking
This was referenced Jan 11, 2022
yob
added a commit
that referenced
this pull request
Jan 17, 2022
This was originally skipped in #361 because I was getting an unreachable code error. I found it was possible to avoid that by providing a type annotation for the `mode` variable of the state machine instead of hard coding it to `:none`. Sadly, I can't do the type annotation with `T.let()` because sorbet isn't a runtime dependency of pdf-reader, but I can hack it in via a sig in the RBI file if I make the initial state part of the method params.
yob
added a commit
that referenced
this pull request
Jan 17, 2022
This was originally skipped in #361 because I was getting an unreachable code error. I found it was possible to avoid that by providing a type annotation for the `mode` variable of the state machine instead of hard coding it to `:none`. Sadly, I can't do the type annotation with `T.let()` because sorbet isn't a runtime dependency of pdf-reader, but I can hack it in via a sig in the RBI file if I make the initial state part of the method params.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add a sorbet type check step to CI, and distribute rbi files with the gem for downstream users who use sorbet.
I'm not sure if I'll keep this long term, but I'm interested in playing with sorbet and this gem is a good playground.
A few features of this change:
sorbet/directory was built withbundle exec srb init, as described in sorbet docsrbi/pdf-reader.rbifile was built withbundle exec parlour. I assume I'll need to re-run this command anytime methods or classes are added/removed/changed. Maybe changes will need to be carefully added to git with-pas well? We'll seeNoMethodErrorwhen parsinglib/pdf/reader/parser.rb. I haven't worked out why yet, so for now that file is excluded from the auto rbi generationlib/totypes: true, and a handful totyped: strictsig { params(T.untyped).returns(T.untyped) }