class RuboCop::Cop::Lint::EmptyClass
end
# TODO: implement later
class << obj
end
end
# TODO: implement later
class << self
class Bar
end
# TODO: implement later
class Foo
# good
@example AllowComments: true
end
# TODO: implement later
class << obj
end
end
# TODO: implement later
class << self
class Bar
end
# TODO: implement later
class Foo
# bad
@example AllowComments: false (default)
end
attr_reader :bar
class << obj
end
end
attr_reader :bar
class << self
class Bar
end
end
# … code
def do_something
class Foo
# good
end
class << obj
end
end
class << self
class Bar
end
class Foo
# bad
@example
to be clearer what we’re aiming for.
Such empty classes and metaclasses are typically an oversight or we should provide a comment
This cop checks for classes and metaclasses without a body.
def body_or_allowed_comment_lines?(node)
def body_or_allowed_comment_lines?(node) node.body || (cop_config['AllowComments'] && comment_lines?(node)) end
def on_class(node)
def on_class(node) add_offense(node, message: CLASS_MSG) unless body_or_allowed_comment_lines?(node) || node.parent_class end
def on_sclass(node)
def on_sclass(node) add_offense(node, message: METACLASS_MSG) unless body_or_allowed_comment_lines?(node) end