Class: RuboCop::Cop::SketchupSuggestions::OperationName

Inherits:
SketchUp::Cop
  • Object
show all
Includes:
RangeHelp
Defined in:
lib/rubocop/sketchup/cop/suggestions/operation_name.rb

Constant Summary collapse

MSG =
'Operation name should be a short capitalized description.'.freeze
MSG_MAX =
"Operation names should not be short and concise. [%d/%d]".freeze

Constants included from SketchUp::Config

SketchUp::Config::DEFAULT_CONFIGURATION

Instance Method Summary collapse

Methods inherited from SketchUp::Cop

inherited, #relevant_file?

Instance Method Details

#on_send(node) ⇒ Object


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rubocop/sketchup/cop/suggestions/operation_name.rb', line 13

def on_send(node)
  _, method_name, *args = *node
  return unless method_name == :start_operation
  return if args.empty? || !args.first.str_type?
  operation_name = args.first.str_content
  # We can only inspect string literals.
  return unless operation_name.is_a?(String)
  # Check the format of the operation name.
  unless acceptable_operation_name?(operation_name)
    msg = %[#{MSG} Expected: `"#{titleize(operation_name)}"`]
    add_offense(args.first, location: :expression, message: msg)
  end
  # Check the length of the operation name.
  unless operation_name.size <= max_operation_name_length
    message = format(MSG_MAX, operation_name.size, max_operation_name_length)
    add_offense(args.first,
      location: excess_range(args.first, operation_name),
      message: message)
  end
  # Ensure operation name is not empty.
  if operation_name.empty?
    msg = 'Operation names should not be empty.'
    add_offense(args.first, location: :expression, message: msg)
  end
end