Shopify / rubocop-sorbet

A collection of RuboCop rules for Sorbet
MIT License
182 stars 27 forks source link

Suggestion: Cop for missing `require "sorbet-runtime"` #197

Closed JamieMagee closed 10 months ago

JamieMagee commented 10 months ago

This would be something like Sorbet/EnforceRuntimeChecks and would ensure static and runtime checks are enabled.

andyw8 commented 10 months ago

🤔 How would we determine which file to check?

JamieMagee commented 10 months ago

Anything with a valid sigil? Here's a grep command that I've been using to achieve the same thing

grep --files-without-match "require \"sorbet-runtime\"" $(grep --files-with-matches "# typed: " --include "*.rb" --recursive)
andyw8 commented 10 months ago

But it doesn't need to be added in every file with a sigil. In a gem you'd typically have it in the gem's entry point file:

https://github.com/Shopify/tapioca/blob/01d7796c7d1d819fc3f03ef655e0cdef1aa6c44e/lib/tapioca.rb#L4

and in a Rails app you'd usually have it in boot.rb.

JamieMagee commented 10 months ago

Interesting, the Sorbet docs don't mention this. Is this still true if you're gradually typing a codebase and want to partially opt-in to runtime checks?

andyw8 commented 10 months ago

Yes, e.g. with # typed: false.

I agree the Sorbet docs could be better for this.

andyw8 commented 10 months ago

Closing since there doesn't seem to be a valid case for this.