class RuboCop::Cop::Naming::AsciiIdentifiers
This cop checks for non-ascii characters in identifier names.
Constants
- MSG
Public Instance Methods
investigate(processed_source)
click to toggle source
# File lib/rubocop/cop/naming/ascii_identifiers.rb, line 10 def investigate(processed_source) processed_source.tokens.each do |token| next unless token.type == :tIDENTIFIER && !token.text.ascii_only? add_offense(token, location: first_offense_range(token)) end end
Private Instance Methods
first_non_ascii_chars(string)
click to toggle source
# File lib/rubocop/cop/naming/ascii_identifiers.rb, line 30 def first_non_ascii_chars(string) string.match(/[^[:ascii:]]+/).to_s end
first_offense_range(identifier)
click to toggle source
# File lib/rubocop/cop/naming/ascii_identifiers.rb, line 19 def first_offense_range(identifier) expression = identifier.pos first_offense = first_non_ascii_chars(identifier.text) start_position = expression.begin_pos + identifier.text.index(first_offense) end_position = start_position + first_offense.length range_between(start_position, end_position) end