diff --git a/Gemfile b/Gemfile index afd515e5..c5fbcb2c 100644 --- a/Gemfile +++ b/Gemfile @@ -28,5 +28,4 @@ gem "rubocop-rspec" gem "rubocop-sorbet" gem "rubocop-shopify" gem "rubocop-graphql" -gem "minitest" gem 'rubocop-thread_safety', require: false diff --git a/Gemfile.lock b/Gemfile.lock index 9269fd55..3f2ec732 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -98,7 +98,7 @@ GEM rubocop-factory_bot (~> 2.22) rubocop-shopify (2.14.0) rubocop (~> 1.51) - rubocop-sorbet (0.7.6) + rubocop-sorbet (0.7.7) rubocop (>= 0.90.0) rubocop-thread_safety (0.5.1) rubocop (>= 0.90.0) @@ -133,7 +133,6 @@ DEPENDENCIES bigdecimal dark_finger graphql - minitest parser prettier pry diff --git a/docs/description/Sorbet_SignatureBuildOrder.md b/docs/description/Sorbet_SignatureBuildOrder.md index 7a4e79f8..b202cd16 100644 --- a/docs/description/Sorbet_SignatureBuildOrder.md +++ b/docs/description/Sorbet_SignatureBuildOrder.md @@ -6,12 +6,6 @@ Checks for the correct order of sig builder methods: - returns, or void - soft, checked, or on_failure - # bad - sig { returns(Integer).params(x: Integer) } - - # good - sig { params(x: Integer).returns(Integer) } - # Examples ```ruby @@ -20,6 +14,12 @@ sig { void.abstract } # good sig { abstract.void } + +# bad +sig { returns(Integer).params(x: Integer) } + +# good +sig { params(x: Integer).returns(Integer) } ``` [Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Sorbet/SignatureBuildOrder) \ No newline at end of file diff --git a/docs/description/Sorbet_VoidCheckedTests.md b/docs/description/Sorbet_VoidCheckedTests.md new file mode 100644 index 00000000..80a6ba4b --- /dev/null +++ b/docs/description/Sorbet_VoidCheckedTests.md @@ -0,0 +1,31 @@ + +Disallows the usage of `.void.checked(:tests)`. + +Using `.void` changes the value returned from the method, but only if +runtime type checking is enabled for the method. Methods marked `.void` +will return different values in tests compared with non-test +environments. This is particularly troublesome if branching on the +result of a `.void` method, because the returned value in test code +will be the truthy `VOID` value, while the non-test return value may be +falsy depending on the method's implementation. + +- Use `.returns(T.anything).checked(:tests)` to keep the runtime type + checking for the rest of the parameters. +- Use `.void.checked(:never)` if you are on an older version of Sorbet + which does not have `T.anything` (meaning versions 0.5.10781 or + earlier. Versions released after 2023-04-14 include `T.anything`.) + +# Examples + +```ruby + +# bad +sig { void.checked(:tests) } + +# good +sig { void } +sig { returns(T.anything).checked(:tests) } +sig { void.checked(:never) } +``` + +[Source](http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Sorbet/VoidCheckedTests) \ No newline at end of file diff --git a/docs/description/description.json b/docs/description/description.json index b0573c7a..501c2152 100644 --- a/docs/description/description.json +++ b/docs/description/description.json @@ -8949,6 +8949,12 @@ "description": "Disallows the usage of `checked(true)` in signatures.", "timeToFix": 5 }, + { + "patternId": "Sorbet_VoidCheckedTests", + "title": "Forbid `.void.checked(:tests)`", + "description": "Forbid `.void.checked(:tests)`", + "timeToFix": 5 + }, { "patternId": "Sorbet_KeywordArgumentOrdering", "title": "Enforces a compatible keyword arguments with Sorbet.\nAll keyword arguments must be at the end of the parameters list, and all keyword arguments with a default value must be after those without default values.", diff --git a/docs/patterns.json b/docs/patterns.json index 393a0067..c2dc6ac0 100644 --- a/docs/patterns.json +++ b/docs/patterns.json @@ -10114,6 +10114,12 @@ "category": "CodeStyle", "enabled": false }, + { + "patternId": "Sorbet_VoidCheckedTests", + "level": "Info", + "category": "CodeStyle", + "enabled": false + }, { "patternId": "Sorbet_KeywordArgumentOrdering", "level": "Info",