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

Inherits:
RuboCop::Cop
  • Object
show all
Defined in:
lib/rubocop/sketchup/suggestions/operation_name.rb

Constant Summary collapse

MSG =
'Operation name should be a short capitalized description.'.freeze

Instance Method Summary collapse

Instance Method Details

#acceptable_operation_name?(name) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
20
21
22
23
# File 'lib/rubocop/sketchup/suggestions/operation_name.rb', line 17

def acceptable_operation_name?(name)
  # Capitalization, no programmer name, no punctuation
  return false if name.size > 25 # TODO: Separate Cop?
  return false if name.end_with?('.')
  return false if titleize(name) != name
  true
end

#on_send(node) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/rubocop/sketchup/suggestions/operation_name.rb', line 9

def on_send(node)
  _, method_name, *args = *node
  return unless method_name == :start_operation
  operation_name = args.first.children.first
  return if acceptable_operation_name?(operation_name)
  add_offense(args.first, :expression)
end

#titleize(string) ⇒ Object

TODO(thomthom): Might need to ignore words like ‘and/or’



26
27
28
# File 'lib/rubocop/sketchup/suggestions/operation_name.rb', line 26

def titleize(string)
  string.split.map(&:capitalize).join(' ')
end