Class: RuboCop::Cop::Obsession::MethodOrder
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Obsession::MethodOrder
- Extended by:
- AutoCorrector
- Includes:
- CommentsHelp, ConfigurableEnforcedStyle, Helpers, VisibilityHelp
- Defined in:
- lib/rubocop/cop/obsession/method_order.rb
Overview
This cop checks for private/protected methods that are not ordered correctly. It supports autocorrect.
Note 1: the order of public methods is not enforced. They can be defined in any order the developer wants, like by order of importance. This is because public methods are usually called outside of the class and often not called within the class at all. If possible though, developers should still try to order their public methods when it makes sense.
Note 2: for top to bottom styles, method order cannot be computed for methods called by ‘send`, metaprogramming, private methods called by superclasses or modules, etc. This cop’s suggestions and autocorrections may be slightly off for these cases.
Note 3: for simplicity, protected methods do not have to be ordered if there are both a protected section and a private section.
Defined Under Namespace
Classes: Node
Constant Summary collapse
- MSG =
'Method `%<after>s` should appear below `%<previous>s`.'
Instance Method Summary collapse
Methods included from Helpers
Instance Method Details
#on_class(class_node) ⇒ Object
189 190 191 192 193 194 195 196 197 198 |
# File 'lib/rubocop/cop/obsession/method_order.rb', line 189 def on_class(class_node) @class_node = class_node find_private_node || return build_methods || return build_ordered_private_methods build_private_methods verify_private_methods_order end |