Module: RuboCop::Cop::Isucon::Mixin::OffenceLocationMethods

Included in:
Mysql2XqueryMethods, Sqlite3ExecuteMethods
Defined in:
lib/rubocop/cop/isucon/mixin/offense_location_methods.rb

Overview

Calculate offense location from Ruby and SQL ASTs

Instance Method Summary collapse

Instance Method Details

#offense_location(type:, node:, gda_location:) ⇒ Parser::Source::Range?

Parameters:

Returns:

  • (Parser::Source::Range, nil)


13
14
15
16
17
18
19
20
21
# File 'lib/rubocop/cop/isucon/mixin/offense_location_methods.rb', line 13

def offense_location(type:, node:, gda_location:)
  return nil unless gda_location

  begin_pos = begin_position_from_gda_location(type: type, node: node, gda_location: gda_location)
  return nil unless begin_pos

  end_pos = begin_pos + gda_location.length
  Parser::Source::Range.new(node.loc.expression.source_buffer, begin_pos, end_pos)
end