Class: RuboCop::Cop::SketchupSuggestions::OperationName
- Inherits:
-
SketchUp::Cop
- Object
- SketchUp::WorkaroundCop
- SketchUp::Cop
- RuboCop::Cop::SketchupSuggestions::OperationName
- Includes:
- RangeHelp
- Defined in:
- lib/rubocop/sketchup/cop/suggestions/operation_name.rb
Overview
Operation name should be a short capitalized description. It will be visible to the user in the Edit > Undo menu. Make sure to give it a short human readable name, similar to SketchUp’s own operation names.
This cop make some very naive assumptions and will have more false positives than most of the other cops. It’s purpose is mainly to enable awareness.
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
Instance Method Details
#on_send(node) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/rubocop/sketchup/cop/suggestions/operation_name.rb', line 20 def on_send(node) _, method_name, *args = *node return unless method_name == :start_operation return if args.empty? || !args.first.str_type? # Ignore transparent operations. return if args.size == 4 && args.last.true_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 = format(MSG_MAX, operation_name.size, max_operation_name_length) add_offense(args.first, location: excess_range(args.first, operation_name), 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 |