class RuboCop::Cop::SketchupRequirements::GetExtensionLicense
Don't attempt to kill the Ruby interpreter by calling `exit` or `exit!`. SketchUp
will trap `exit` and prevent that, with a message in the console. But `exit!` is not trapped and with terminate SketchUp
without shutting down cleanly.
Use `return`, `next`, `break` or `raise` instead.
Constants
- EXTENSION_ID_PATTERN
rubocop:disable Layout/LineLength
- MSG_INVALID
- MSG_TRAILING_SPACE
- MSG_WRONG_TYPE
Public Instance Methods
on_send(node)
click to toggle source
rubocop:enable Layout/LineLength
# File lib/rubocop/sketchup/cop/requirements/get_extension_license.rb, line 35 def on_send(node) argument = get_extension_license(node) return unless argument if argument.lvar_type? variable_name = argument.children.first assignment_node = find_assignment(node, variable_name) argument = assignment_node.children.last if assignment_node end if argument.str_type? validate_extension_id(argument) else location = argument.loc.expression add_offense(node, location: location, message: MSG_WRONG_TYPE) end end
Private Instance Methods
find_assignment(node, variable_name)
click to toggle source
# File lib/rubocop/sketchup/cop/requirements/get_extension_license.rb, line 55 def find_assignment(node, variable_name) scope = node until scope.parent.nil? scope = scope.parent scope.each_child_node { |child| # next unless child.is_a?(RuboCop::AST::Node) next unless child.lvasgn_type? next unless child.children.first == variable_name return child } end nil end
validate_extension_id(node)
click to toggle source
# File lib/rubocop/sketchup/cop/requirements/get_extension_license.rb, line 70 def validate_extension_id(node) extension_id = node.str_content # Trailing spaces if extension_id.rstrip.size < extension_id.size end_pos = node.loc.end.begin_pos begin_pos = node.loc.begin.end_pos + extension_id.rstrip.size range = range_between(begin_pos, end_pos) add_offense(node, location: range, message: MSG_TRAILING_SPACE) return false end # Invalid format. unless EXTENSION_ID_PATTERN.match?(extension_id) range = string_contents_range(node) add_offense(node, location: range, message: MSG_INVALID) return false end true end