lib/i18n/tasks/scanners/pattern_scanner.rb in i18n-tasks-0.9.33 vs lib/i18n/tasks/scanners/pattern_scanner.rb in i18n-tasks-0.9.34

- old
+ new

@@ -10,11 +10,11 @@ class PatternScanner < FileScanner include RelativeKeys include OccurrenceFromPosition include RubyKeyLiterals - TRANSLATE_CALL_RE = /(?<=^|[^\w'\-.]|[^\w'\-]I18n\.|I18n\.)t(?:!|ranslate!?)?/ + TRANSLATE_CALL_RE = /(?<=^|[^\w'\-.]|[^\w'\-]I18n\.|I18n\.)t(?:!|ranslate!?)?/.freeze IGNORE_LINES = { 'coffee' => /^\s*#(?!\si18n-tasks-use)/, 'erb' => /^\s*<%\s*#(?!\si18n-tasks-use)/, 'es6' => %r{^\s*//(?!\si18n-tasks-use)}, 'haml' => /^\s*-\s*#(?!\si18n-tasks-use)/, @@ -41,14 +41,17 @@ text = read_file(path) text.scan(@pattern) do |match| src_pos = Regexp.last_match.offset(0).first location = occurrence_from_position(path, text, src_pos, raw_key: strip_literal(match[0])) next if exclude_line?(location.line, path) + key = match_to_key(match, path, location) next unless key + key += ':' if key.end_with?('.') next unless valid_key?(key) + keys << [key, location] end keys rescue Exception => e # rubocop:disable Lint/RescueException raise ::I18n::Tasks::CommandError.new(e, "Error scanning #{path}: #{e.message}") @@ -65,11 +68,11 @@ def exclude_line?(line, path) re = @ignore_lines_res[File.extname(path)[1..-1]] re && re =~ line end - VALID_KEY_RE_DYNAMIC = /^(#{VALID_KEY_CHARS}|[:\#{@}\[\]])+$/ + VALID_KEY_RE_DYNAMIC = /^(#{VALID_KEY_CHARS}|[:\#{@}\[\]])+$/.freeze def valid_key?(key) if @config[:strict] super(key) else @@ -82,19 +85,19 @@ end def closest_method(occurrence) method = File.readlines(occurrence.path, encoding: 'UTF-8') .first(occurrence.line_num - 1).reverse_each.find { |x| x =~ /\bdef\b/ } - method && method.strip.sub(/^def\s*/, '').sub(/[\(\s;].*$/, '') + method && method.strip.sub(/^def\s*/, '').sub(/[(\s;].*$/, '') end # This method only exists for backwards compatibility with monkey-patches and plugins attr_reader :translate_call_re def default_pattern # capture only the first argument / - #{translate_call_re} [\( ] \s* (?# fn call begin ) + #{translate_call_re} [( ] \s* (?# fn call begin ) (#{first_argument_re}) (?# capture the first argument) /x end def first_argument_re