You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Rails/UniqueValidationWithoutIndex cop assumes any validates node has at least one argument. It starts its work by scanning the arguments to see if there is a uniqueness part to the directive. But if there are no arguments, it crashes.
(To be clear, validates requires arguments and its presence without arguments is invalid.)
Expected behavior
On a class with a validates directive that has no arguments, no rubocop-rails cop should crash.
(Bonus points if some rubocop-rails cop flags it as incorrect. Currently none does.)
Actual behavior
Rails/UniqueValidationWithoutIndex crashes with a NoMethodError:
# rubocop app/models/foo.rb
Inspecting 1 file
An error occurred while Rails/UniqueValidationWithoutIndex cop was inspecting /workspaces/cq/app/models/foo.rb:13:2.
To see the complete backtrace run rubocop -d.
.
1 file inspected, no offenses detected
1 error occurred:
An error occurred while Rails/UniqueValidationWithoutIndex cop was inspecting /workspaces/cq/app/models/foo.rb:13:2.
Errors are usually caused by RuboCop bugs.
Please, report your problems to RuboCop's issue tracker.
https://github.com/rubocop/rubocop/issues
Mention the following information in the issue report:
1.56.3 (using Parser 3.2.2.3, rubocop-ast 1.29.0, running on ruby 3.2.2) [aarch64-linux]
# rubocop app/models/foo.rb -d
...
Scanning /workspaces/cq/app/models/foo.rb
An error occurred while Rails/UniqueValidationWithoutIndex cop was inspecting /workspaces/cq/app/models/foo.rb:13:2.
undefined method `hash_type?' for nil:NilClass
/usr/local/bundle/gems/rubocop-rails-2.21.1/lib/rubocop/cop/rails/unique_validation_without_index.rb:128:in `uniqueness_part'
/usr/local/bundle/gems/rubocop-rails-2.21.1/lib/rubocop/cop/rails/unique_validation_without_index.rb:35:in `on_send'
/usr/local/bundle/gems/rubocop-1.56.3/lib/rubocop/cop/commissioner.rb:143:in `public_send'
/usr/local/bundle/gems/rubocop-1.56.3/lib/rubocop/cop/commissioner.rb:143:in `block (2 levels) in trigger_restricted_cops'
...
The
Rails/UniqueValidationWithoutIndex
cop assumes anyvalidates
node has at least one argument. It starts its work by scanning the arguments to see if there is auniqueness
part to the directive. But if there are no arguments, it crashes.(To be clear,
validates
requires arguments and its presence without arguments is invalid.)Expected behavior
On a class with a
validates
directive that has no arguments, norubocop-rails
cop should crash.(Bonus points if some
rubocop-rails
cop flags it as incorrect. Currently none does.)Actual behavior
Rails/UniqueValidationWithoutIndex
crashes with aNoMethodError
:Steps to reproduce the problem
Add the single line
to any
ApplicationRecord
class.RuboCop version
The text was updated successfully, but these errors were encountered: