Class: RuboCop::Cop::Elegant::OneClassPerFile
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Elegant::OneClassPerFile
- Defined in:
- lib/rubocop/cop/elegant/one_class_per_file.rb
Overview
Enforces one top-level class per file, treating empty class bodies as namespace scaffolding rather than real classes. An empty top-level class Foo::Bar; end resolves a parent namespace so that the actual class in the same file can use the compact-namespaced form required by Elegant/NoClassInModule without a circular require; it is not a class definition in its own right. Only when two or more top-level class bodies are non-empty does the cop register an offense, on every such class after the first.
Constant Summary collapse
- MSG =
'Only one non-empty class per file is allowed; %<name>s is the extra one'
Instance Method Summary collapse
Instance Method Details
#on_new_investigation ⇒ Object
18 19 20 21 22 23 |
# File 'lib/rubocop/cop/elegant/one_class_per_file.rb', line 18 def on_new_investigation real = tops.reject { |node| node.body.nil? } real.drop(1).each do |node| add_offense(node, message: format(MSG, name: label(node))) end end |