Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use ::Struct to avoid collisions with cop namespace
We were trying to add a custom cop called `Struct/RequiresTypedStructHelper`, but ran into a problem where we got an error like: ``` undefined method `new' for RuboCop::Cop::Struct:Module /Users/technicalpickles/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-rails-2.21.1/lib/rubocop/cop/mixin/index_method.rb:105:in `module:IndexMethod' /Users/technicalpickles/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-rails-2.21.1/lib/rubocop/cop/mixin/index_method.rb:6:in `module:Cop' /Users/technicalpickles/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-rails-2.21.1/lib/rubocop/cop/mixin/index_method.rb:4:in `module:RuboCop' /Users/technicalpickles/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-rails-2.21.1/lib/rubocop/cop/mixin/index_method.rb:3:in `top (required)' /Users/technicalpickles/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-rails-2.21.1/lib/rubocop/cop/rails_cops.rb:7:in `require_relative' /Users/technicalpickles/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-rails-2.21.1/lib/rubocop/cop/rails_cops.rb:7:in `top (required)' /Users/technicalpickles/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-rails-2.21.1/lib/rubocop-rails.rb:16:in `require_relative' ``` It turned out this module has method that were calling `Struct.new`, but Ruby constant lookup ended up using our `Rubocop::Cop::Struct`, instead of the actual `Struct` class. We were able to work around it by changing the constant name, but `Struct` is always going to be part of the stdlib so a possible name collision.
- Loading branch information