lib/i18n/tasks/scanners/pattern_scanner.rb in i18n-tasks-0.9.14 vs lib/i18n/tasks/scanners/pattern_scanner.rb in i18n-tasks-0.9.15

- old
+ new

@@ -10,14 +10,24 @@ class PatternScanner < FileScanner include RelativeKeys include OccurrenceFromPosition include RubyKeyLiterals + TRANSLATE_CALL_RE = /(?<=^|[^\w'\-.]|[^\w'\-]I18n\.|I18n\.)t(?:ranslate)?/ + IGNORE_LINES = { + 'opal' => /^\s*#(?!\si18n-tasks-use)/, + 'haml' => /^\s*-\s*#(?!\si18n-tasks-use)/, + 'slim' => %r{^\s*(?:-#|/)(?!\si18n-tasks-use)}, + 'coffee' => /^\s*#(?!\si18n-tasks-use)/, + 'erb' => /^\s*<%\s*#(?!\si18n-tasks-use)/ + }.freeze + def initialize(**args) super + @translate_call_re = config[:translate_call].present? ? Regexp.new(config[:translate_call]) : TRANSLATE_CALL_RE @pattern = config[:pattern].present? ? Regexp.new(config[:pattern]) : default_pattern - @ignore_lines_res = (config[:ignore_lines] || []).each_with_object({}) do |(ext, re), h| + @ignore_lines_res = (config[:ignore_lines] || IGNORE_LINES).each_with_object({}) do |(ext, re), h| h[ext.to_s] = Regexp.new(re) end end protected @@ -73,12 +83,11 @@ 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;].*$/, '') end - def translate_call_re - /(?<=^|[^\w'\-.]|[^\w'\-]I18n\.|I18n\.)t(?:ranslate)?/ - 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 )