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.'
- MSG_MAX =
'Operation names should not be short and concise. [%d/%d]'
Constants inherited from SketchUp::Cop
SketchUp::Cop::SKETCHUP_DEPARTMENT_SEVERITY
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
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/rubocop/sketchup/cop/suggestions/operation_name.rb', line 54 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 |