Class: RuboCop::Cop::Asjer::RailsClassOrder
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Asjer::RailsClassOrder
- Extended by:
- AutoCorrector
- Includes:
- RangeHelp, RailsClassOrderCorrector
- Defined in:
- lib/rubocop/cop/asjer/rails_class_order.rb
Overview
Enforces consistent ordering of declarative methods in Rails models.
Constant Summary collapse
- MSG =
'Declarative methods should be sorted by type: scopes, attributes, enums, ' \ 'associations, validations, callbacks, then others.'
- TYPE_ORDER =
{ scope: 0, attribute: 1, enum: 2, association: 3, validation: 4, callback: 5, other: 6 }.freeze
- CATEGORY_CONFIG =
{ scope: { key: 'Scopes', const: :SCOPES }, attribute: { key: 'Attributes', const: :ATTRIBUTES }, enum: { key: 'Enums', const: :ENUMS }, association: { key: 'Associations', const: :ASSOCIATIONS }, validation: { key: 'Validations', const: :VALIDATIONS }, callback: { key: 'Callbacks', const: :CALLBACKS }, other: { key: 'Others', const: :OTHERS } }.freeze
Instance Method Summary collapse
Methods included from RailsClassOrderCorrector
#autocorrect, #build_sorted_source, #collect_adjacent_comments, #comments_before_node, #correction_range_for, #format_grouped_source, #full_method_range, #normalize_interstitial_chunk, #ordered_target_nodes, #preceding_comments, #preserved_interstitial_source, #range_with_comments, #rebuilt_source, #skip_trailing_blank_lines, #source_with_comments, #trailing_blank_line?, #trailing_sibling?, #trim_trailing_newlines
Instance Method Details
#on_class(node) ⇒ Object
258 259 260 261 262 263 |
# File 'lib/rubocop/cop/asjer/rails_class_order.rb', line 258 def on_class(node) _name, _superclass, body = *node return unless body&.begin_type? check_order(body) end |