rubocop-rails icon indicating copy to clipboard operation
rubocop-rails copied to clipboard

Cop idea: check for code outside of named class or module

Open DeedleFake opened this issue 2 years ago • 0 comments

Is your feature request related to a problem? Please describe.

A very rare but non-zero number of times, code has been accidentally placed outside of the class or module corresponding to the file that it's in, i.e.

# app/services/example_service.rb
class ExampleService
  ...
end

puts 'Whoops. This shouldn't be here.'

Describe the solution you'd like

Check for code in files with classes or modules named after them, so ignore things like config initializers, that isn't in said class or module and report it.

Describe alternatives you've considered

Convoluted regular expressions that would probably miss stuff. For example, something like grep -r '^[A-Z]' app lib.

DeedleFake avatar Sep 13 '23 18:09 DeedleFake