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
Style/IdenticalConditionalBranches
cop error
#12300
Labels
Comments
The provided example code results in the following syntax error. Can you provide a valid syntax repro code? $ cat example.rb
if object.object_preload.string.present? &&
object.object_preload.current_item_information != 'DATA ERROR'
object_packet[:current_items] = {}
parsed_current_cat_information = JSON.parse(object.object_preload.current_item_information)
parsed_current_cat_information.each_pair do |key,value|
object_packet[:current_items][key] = {}
object_packet[:current_items][key][:other_property] = {}
object_packet[:current_items][key] = {:property => value['property']}
object_packet[:current_items][key][:other_property] = [{:other_property => value['other_property']}]
]
end
else
object_packet[:current_items] = {}
end
$ ruby -c example.rb
example.rb:14: syntax error, unexpected ']', expecting `end'
... ]
example.rb:18: syntax error, unexpected tLAMBEG
...ject_packet[:current_items] = {} |
8 tasks
I was able to reproduce the issue, so I opened #12304. |
koic
added a commit
to koic/rubocop
that referenced
this issue
Oct 23, 2023
Fixes rubocop#12300. This PR fixes an error for `Style/IdenticalConditionalBranches` when `if`...`else` with identical leading lines and using index assign. In RuboCop, the `send` node is used instead of the `indexasgn` node, so `name` cannot be used. https://github.com/rubocop/rubocop-ast/blob/v1.29.0/lib/rubocop/ast/node/indexasgn_node.rb
@koic sorry for not getting back you with corrected syntax for that code example. Thanks for fixing it! |
@Brenntron Never mind. Thank you for your feedback! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Style/IdenticalConditionalBranches
cop encountersundefined method 'name'
while running over a file.Expected behavior
The IndenticalConditionalBranches cop should lint the conditional without erroring.
Actual behavior
rubocop -d my_file outputs 1 error after detecting other offenses correctly.
Offenses print to screen without issue.
Steps to reproduce the problem
Install rubocop 1.51.1
Install rubocop-rails 2.21.2
require rubocop-rails in whichever rubocop config file you use, in my case it is a global config in
./config/rubocop/config.yml
.Run rubocop on a file with a branch similar to the below
RuboCop version
The text was updated successfully, but these errors were encountered: