pronto-rubocop icon indicating copy to clipboard operation
pronto-rubocop copied to clipboard

Fix for syntax error discarding

Open europ opened this issue 7 years ago • 13 comments

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

europ avatar Feb 13 '18 14:02 europ

@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:

skateman avatar Feb 19 '18 19:02 skateman

@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?

doomspork avatar Sep 26 '19 15:09 doomspork

@skateman, looks good. If you would rebase, that would be excellent. (I am not a maintainer, just would like to see this in).

hlascelles avatar Jan 26 '21 09:01 hlascelles

Agreed, there should be a 0.11.1 release soon -- I'd like to include this PR in it 🙂

ashkulz avatar Jan 31 '21 09:01 ashkulz

@skateman can you fix this? I am currently unavailable.

europ avatar Feb 04 '21 17:02 europ

I have no push rights to your repo...

skateman avatar Feb 05 '21 08:02 skateman

@skateman you have them, from now

europ avatar Feb 05 '21 18:02 europ

Any luck on rebasing this PR? I'm hoping to make a release soon with RuboCop >= 1.0 support.

ashkulz avatar Feb 13 '21 08:02 ashkulz

Just checking, is this mandatory / the fix for RuboCop 1.x? Or can there be another PR to get us to that version?

hlascelles avatar Feb 22 '21 18:02 hlascelles

@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?).

ashkulz avatar Feb 23 '21 06:02 ashkulz

Ah, fantastic thank you!

hlascelles avatar Feb 25 '21 20:02 hlascelles

@europ would you be willing to rebase this PR?

ashkulz avatar Jan 17 '23 05:01 ashkulz

Hi @europ... Could you rebase this?

hlascelles avatar Apr 30 '23 19:04 hlascelles