class RuboCop::Cop::Style::AsciiComments
This cop checks for non-ascii (non-English) characters in comments.
Constants
- MSG
Public Instance Methods
investigate(processed_source)
click to toggle source
# File lib/rubocop/cop/style/ascii_comments.rb, line 11 def investigate(processed_source) processed_source.comments.each do |comment| unless comment.text.ascii_only? add_offense(comment, location: first_offense_range(comment)) end end end
Private Instance Methods
first_non_ascii_chars(string)
click to toggle source
# File lib/rubocop/cop/style/ascii_comments.rb, line 32 def first_non_ascii_chars(string) string.match(/[^[:ascii:]]+/).to_s end
first_offense_range(comment)
click to toggle source
# File lib/rubocop/cop/style/ascii_comments.rb, line 21 def first_offense_range(comment) expression = comment.loc.expression first_offense = first_non_ascii_chars(comment.text) start_position = expression.begin_pos + comment.text.index(first_offense) end_position = start_position + first_offense.length range_between(start_position, end_position) end