spec/support/mri_syntax_checker.rb in rubocop-0.14.1 vs spec/support/mri_syntax_checker.rb in rubocop-0.15.0
- old
+ new
@@ -15,27 +15,31 @@
end
source_buffer = Parser::Source::Buffer.new('test', 1)
source_buffer.source = source
- offences = []
-
- check_syntax(source).each_line do |line|
- line_number, severity, message = process_line(line)
- next unless line_number
- next if grep_message && !message.include?(grep_message)
- begin_pos = source_lines[0...(line_number - 1)].reduce(0) do |a, e|
- a + e.length + "\n".length
- end
- offences << Rubocop::Cop::Offence.new(
- severity,
- Parser::Source::Range.new(source_buffer, begin_pos, begin_pos + 1),
- message.capitalize,
- fake_cop_name
- )
+ offences = check_syntax(source).each_line.map do |line|
+ check_line(line, source_lines, source_buffer, fake_cop_name,
+ grep_message)
end
- offences
+ offences.compact
+ end
+
+ def check_line(line, source_lines, source_buffer, fake_cop_name,
+ grep_message)
+ line_number, severity, message = process_line(line)
+ return unless line_number
+ return if grep_message && !message.include?(grep_message)
+ begin_pos = source_lines[0...(line_number - 1)].reduce(0) do |a, e|
+ a + e.length + "\n".length
+ end
+ Rubocop::Cop::Offence.new(severity,
+ Parser::Source::Range.new(source_buffer,
+ begin_pos,
+ begin_pos + 1),
+ message.capitalize,
+ fake_cop_name)
end
def check_syntax(source)
fail 'Must be running with MRI' unless RUBY_ENGINE == 'ruby'