Class: RuboCop::Cop::Sevencop::RailsSpecificActionName

Inherits:
Base
  • Object
show all
Includes:
VisibilityHelp
Defined in:
lib/rubocop/cop/sevencop/rails_specific_action_name.rb

Overview

Use only specific action names.

It is good practice to separate controller classes rather than adding more actions as needed. By default, the 7 CRUD action names are specified that are generated by the Rails scaffold.

Examples:

# bad
class UsersController < ApplicationController
  def articles
  end
end

# good
class UserArticlesController < ApplicationController
  def index
  end
end

Constant Summary collapse

MSG =
'Use only specific action names.'

Instance Method Summary collapse

Instance Method Details

#on_def(node) ⇒ void

This method returns an undefined value.

Parameters:

  • node (RuboCop::AST::DefNode)


30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rubocop/cop/sevencop/rails_specific_action_name.rb', line 30

def on_def(node)
  return unless bad?(node)

  add_offense(
    node.location.name,
    message: format(
      'Use only specific action names (%<action_names>s).',
      action_names: configured_action_names.join(', ')
    )
  )
end