pronto-rubocop
pronto-rubocop copied to clipboard
Fix for syntax error discarding
The result of pronto-rubocop does not include syntactic errors.
Missing syntactic error in the result of pronto-rubocop was solved by mapping this error on the last element of the patch.
File containing syntax error:
while a < 15
(
print a, " "
if a == 10 then
prin"made it to ten!!"
a = a + 1
end
Variable offences
's value in method inspect(patch)
in file lib/pronto/rubocop.rb
:
https://github.com/prontolabs/pronto-rubocop/blob/master/lib/pronto/rubocop.rb#L38
[42] pry(#<Pronto::Rubocop>)> offences
=> [#<RuboCop::Cop::Offense:0x0000564daa700d20
@cop_name="Lint/Syntax",
@location=#<Parser::Source::Range /root/miq_bot/testrepo/error.rb 99...99>,
@message=
"unexpected token $end\n(Using Ruby 2.3 parser; configure using `TargetRubyVersion` parameter, under `AllCops`)",
@severity=#<RuboCop::Cop::Severity:0x0000564daa7014f0 @name=:error>,
@status=:uncorrected>]
before:
The syntactic error is missing in the result of the rubocop.
[168] pry(#<Pronto::Rubocop>)> offences.sort.reject(&:disabled?).map do |offence|
[168] pry(#<Pronto::Rubocop>)* patch.added_lines
[168] pry(#<Pronto::Rubocop>)* .select { |line| line.new_lineno == offence.line }
[168] pry(#<Pronto::Rubocop>)* .map { |line| new_message(offence, line) }
[168] pry(#<Pronto::Rubocop>)* end
=> [[]]
after:
The syntactic error message is assigned to the last element of patch variable.
[174] pry(#<Pronto::Rubocop>)> offences.sort.reject(&:disabled?).map do |offence|
[174] pry(#<Pronto::Rubocop>)* patch.added_lines
[174] pry(#<Pronto::Rubocop>)* .select { |line| line.new_lineno == offence.line }
[174] pry(#<Pronto::Rubocop>)* .map { |line| new_message(offence, line) }
[174] pry(#<Pronto::Rubocop>)* end.concat(
[174] pry(#<Pronto::Rubocop>)* offences.sort.reject(&:disabled?).select do |offence|
[174] pry(#<Pronto::Rubocop>)* offence.cop_name == "Lint/Syntax"
[174] pry(#<Pronto::Rubocop>)* end.map do |offence|
[174] pry(#<Pronto::Rubocop>)* new_message(offence, patch.added_lines.last)
[174] pry(#<Pronto::Rubocop>)* end
[174] pry(#<Pronto::Rubocop>)* )
=> [[],
#<Pronto::Message:0x0000564da7503070
@commit_sha="dfa09b8920c8932aa0454dcffb93966fc1c9b2f5",
@level=:error,
@line=
#<struct Pronto::Git::Line
line=
#<Rugged::Diff::Line:47445775201620 {line_origin: :addition, content: "end\n">,
patch=
#<struct Pronto::Git::Patch
patch=#<Rugged::Patch:47445789709400>,
repo=
#<Pronto::Git::Repository:0x0000564daae22db0
@repo=
#<Rugged::Repository:47445789710020 {path: "/root/miq_bot/testrepo/.git/"}>>>,
hunk=
#<Rugged::Diff::Hunk:47445775202180 {header: "@@ -0,0 +1,8 @@\n", count: 8}>>,
@msg=
"unexpected token $end\n(Using Ruby 2.3 parser; configure using `TargetRubyVersion` parameter, under `AllCops`)",
@path="error.rb",
@runner=Pronto::Rubocop>]
Informations (version, platform, engine)
[175] pry(#<Pronto::Rubocop>)> RUBY_VERSION
=> "2.3.1"
[176] pry(#<Pronto::Rubocop>)> RUBY_PLATFORM
=> "x86_64-linux-gnu"
[177] pry(#<Pronto::Rubocop>)> RUBY_ENGINE
=> "ruby"
[178] pry(#<Pronto::Rubocop>)> Pronto::RubocopVersion::VERSION
=> "0.9.0"
[179] pry(#<Pronto::Rubocop>)> ::RuboCop::Version.version
=> "0.52.1"
/cc @skateman @romanblanco
@mmozuras is this something you would want? Maybe this is not The Right Way™ but the syntax errors are not always mappable to patch changes :disappointed:
@europ sorry it's taken someone so long to get back to you. I'm open to accepting this change if you'd be willing to rebase and resolve conflicts 👌
@prontolabs/core any thoughts or objections?
@skateman, looks good. If you would rebase, that would be excellent. (I am not a maintainer, just would like to see this in).
Agreed, there should be a 0.11.1
release soon -- I'd like to include this PR in it 🙂
@skateman can you fix this? I am currently unavailable.
I have no push rights to your repo...
@skateman you have them, from now
Any luck on rebasing this PR? I'm hoping to make a release soon with RuboCop >= 1.0 support.
Just checking, is this mandatory / the fix for RuboCop 1.x? Or can there be another PR to get us to that version?
@hlascelles the 0.11.1 release with 1.0 support has already happened; I guess this will be present in a followup release (0.11.2?).
Ah, fantastic thank you!
@europ would you be willing to rebase this PR?
Hi @europ... Could you rebase this?