`RuboCop::Cop::Airbnb::ModuleMethodInWrongFile` returns incorrect error message when defining a method inside singleton class
- Dominant language
- Ruby
- Stars
- 3.9k
- Forks
- 756
- PR merge metrics
- No merged PRs in 30d
Description
When developing PR #189, tests were changed to use new `rspec-rubocop` syntax which also checks that the message generated is correct. After doing this, [the spec that checks that an error is returned when using "<<" static methods and a non-matching name](https://github.com/airbnb/ruby/blob/dfdc84b89284d537043b7eb4aa3ccc607940303f/rubocop-airbnb/spec/rubocop/cop/airbnb/module_method_in_wrong_file_spec.rb#L96) failed with an incorrect message:
`Method baz should be defined in foo/foo.rb`
When the expected message was:
`Method baz should be defined in foo.rb`
After digging a little about it to understand what was happening, we realized that this incorrect message is also present on `master` – but there are no assertions respecting the offense's text, thus the test succeeds.
The issue seems to be caused by the method `normalize_module_name(node.parent_module_name)` (on [module_method_in_wrong_file.rb#L88](https://github.com/airbnb/ruby/blob/dfdc84b89284d537043b7eb4aa3ccc607940303f/rubocop-airbnb/lib/rubocop/cop/airbnb/module_method_in_wrong_file.rb#L88)) which returns `Foo::Foo` instead of just `Foo`.
Contributor guide
Research direction
Start with rubocop-airbnb/lib/rubocop/cop/airbnb/module_method_in_wrong_file.rb around line 88 and the spec at rubocop-airbnb/spec/rubocop/cop/airbnb/module_method_in_wrong_file_spec.rb around line 96. Run that spec and inspect normalize_module_name(node.parent_module_name). Done means the singleton-class case reports “Method baz should be defined in foo.rb” and the spec checks the offense text.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100