Class: RuboCop::Cop::Rails::MigrationClassName
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Rails::MigrationClassName
- Extended by:
- AutoCorrector
- Includes:
- MigrationsHelper
- Defined in:
- lib/rubocop/cop/rails/migration_class_name.rb
Overview
This cop makes sure that each migration file defines a migration class whose name matches the file name. (e.g. `20220224111111_create_users.rb` should define `CreateUsers` class.)
Constant Summary collapse
- MSG =
'Replace with `%<corrected_class_name>s` that matches the file name.'
Instance Method Summary collapse
Methods included from MigrationsHelper
Instance Method Details
#on_class(node) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/rubocop/cop/rails/migration_class_name.rb', line 27 def on_class(node) return if in_migration?(node) snake_class_name = to_snakecase(node.identifier.source) basename = return if snake_class_name == basename corrected_class_name = to_camelcase(basename) = format(MSG, corrected_class_name: corrected_class_name) add_offense(node.identifier, message: ) do |corrector| corrector.replace(node.identifier, corrected_class_name) end end |