-
Notifications
You must be signed in to change notification settings - Fork 60
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
RuboCop gives false positive Lint/Syntax errors for valid Ruby 3.1 syntax in slim files #154
Comments
We have the same issue, is there any news on this? |
I have heard no further news about this and didn't investigate further. In the end we ended up with disabling the Lint/Syntax RuboCop for Slim-Lint completely, so we can start using the new syntax (in all cases) without having to add extra parentheses or come up with other hacks. This does lead us to potentially missing Ruby syntax errors in Slim files, but we think (hope) our test suite and/or manual testing will detect that anyway. To disable the Cop completely, add the following to your .slim-lint.yml config:
Maybe we should just add the parentheses though, since without it in Ruby itself it could lead to problems or syntax errors as well. There are several issues about it for RuboCop too (although not exactly the same problem I think):
|
Ruby 3.1 includes new syntax to leave the hash value if it is a variable called the same as the hash key: https://bugs.ruby-lang.org/issues/14579. However there sometimes are cases this new syntax can be applied (as also suggested by RuboCop) in Slim files while doing so results in false positive RuboCop Lint/Syntax errors afterwards. For example the following code:
Results in the following error:
While this code is actually valid, parses and runs. I therefore would expect slim-lint/RuboCop not to produce an error for it though. Interestingly, similar code in Ruby also gives a RuboCop Lint/Syntax error for it, but in that case the code is actually invalid (Ruby itself gives a syntax error for it as well) and doesn't run. While in slim-lint the code is valid (and does run) and the error is a false positive.
It can be fixed by using parentheses around the render call:
Or by including the omitted hash value f:
Interestingly the (false) syntax error is only produced when the omitted hash value was last and is followed immediately by some other Ruby code with a block on the same indenting level. The following examples all work correctly (no error is produced):
The text was updated successfully, but these errors were encountered: