I would expect the following to be valid (and require the use of parentheses due to the OR condition):
def only_double_splats?(parameters) = (parameters in [[:keyrest]] | [[:keyrest, *]])Actual behavior
I'll get the following:
lib/marameters/probe.rb:60:31: C: [Correctable] Style/RedundantParentheses: Don't use parentheses around a one-line pattern matching. def only_double_splats? = (parameters in [[:keyrest]] | [[:keyrest, *]]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
If I use auto-correct, the above will go way but then my specs will fail because the OR condition (i.e. [[:keyrest, *]]
) will not be respected.
Use the following code:
def only_double_splats?(parameters) = parameters in [[:keyrest]] | [[:keyrest, *]] parameters = Module.new { def test(**one) = super } .instance_method(:test) .parameters only_double_splats?(parameters) == true # false
The problem with the above is that this is returned instead:
...which is definitely not true
.
1.76.1 (using Parser 3.3.8.0, Prism 1.4.0, rubocop-ast 1.45.1, analyzing as Ruby 3.4, running on ruby 3.4.4) [arm64-darwin24.5.0]
- rubocop-capybara 2.22.1
- rubocop-disable_syntax 0.2.0
- rubocop-packaging 0.6.0
- rubocop-performance 1.25.0
- rubocop-thread_safety 0.7.2
- rubocop-rake 0.7.1
- rubocop-rspec 3.6.0
Notes
This is a follow up to Issue #14239 where I mentioned this was a syntax error but I was incorrect. This is a logic error, instead, which will cause your specs to fail if you drop the parentheses.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4