lib/goodcheck/analyzer.rb in goodcheck-1.5.0 vs lib/goodcheck/analyzer.rb in goodcheck-1.5.1
- old
+ new
@@ -10,37 +10,26 @@
def scan(&block)
if block_given?
issues = []
- rule.patterns.each do |pattern|
- scanner = StringScanner.new(buffer.content)
+ regexp = Regexp.union(*rule.patterns.map(&:regexp))
+ scanner = StringScanner.new(buffer.content)
- break_head = pattern.regexp.source.start_with?("\\b")
- after_break = true
-
- until scanner.eos?
- case
- when scanner.scan(pattern.regexp)
- next if break_head && !after_break
-
- text = scanner.matched
- range = (scanner.pos - text.bytesize) .. scanner.pos
- unless issues.any? {|issue| issue.range == range }
- issues << Issue.new(buffer: buffer, range: range, rule: rule, text: text)
- end
- when scanner.scan(/.\b/m)
- after_break = true
- else
- scanner.scan(/./m)
- after_break = false
- end
+ while true
+ case
+ when scanner.scan_until(regexp)
+ text = scanner.matched
+ range = (scanner.pos - text.bytesize) .. scanner.pos
+ issues << Issue.new(buffer: buffer, range: range, rule: rule, text: text)
+ else
+ break
end
end
issues.each(&block)
else
- enum_for(:scan, &block)
+ enum_for(:scan)
end
end
end
end