Giter Club home page Giter Club logo

Comments (12)

ismaelga avatar ismaelga commented on May 18, 2024

I got the the same problem using String interpolation inside a block. So I guess there should be made some changes on how interpolation braces are identified.

Ehm? What comma? I've already had that comma here.

Commas in [1,2,3], It should be [1, 2, 3]

from rubocop.

jonas054 avatar jonas054 commented on May 18, 2024

@ismaelga Were you also using Ruby 2.0? My suspicion is that these errors are all related to differences in the output from Ripper in 1.9 and 2.0. They are bugs nonetheless, but it would be interesting to see if they appear in Ruby 1.9 or not.

from rubocop.

ismaelga avatar ismaelga commented on May 18, 2024

@jonas054 Yeah. I just tested on 1.9.3 and it worked there. So this seems to be only on 2.0.0

from rubocop.

ismaelga avatar ismaelga commented on May 18, 2024

And the output from Ripper is the same on both. So it should be something else

from rubocop.

lloeki avatar lloeki commented on May 18, 2024

Minimal ruby source:

foo { "#{n}" }

I pry'ed blocks.rb, and this is what I get for @reverse_correlations on 1.9.3:

{70102431113960=>[0], 70102431112780=>[2, 10], 70102431121220=>[6]}

Here's the matching @correlations:

{0=>[:program, :method_add_block, :method_add_arg, :fcall, :@ident],
 2=>[:program, :method_add_block, :brace_block],
 10=>[:program, :method_add_block, :brace_block],
 6=>
  [:program,
   :method_add_block,
   :brace_block,
   :string_literal,
   :string_content,
   :string_embexpr,
   :vcall,
   :@ident]}

while this is what I get for @reverse_correlations on 2.0:

{70225979303160=>[0], 70225979322180=>[2], 70225979338680=>[6]}

and the matching @correlations

{0=>[:program, :method_add_block, :method_add_arg, :fcall, :@ident],
 2=>[:program, :method_add_block, :brace_block],
 6=>
  [:program,
   :method_add_block,
   :brace_block,
   :string_literal,
   :string_content,
   :string_embexpr,
   :vcall,
   :@ident]}

So #inspect and #check look correct, just fed with bad data.

Next stop, Cop::Grammar#correlate found via cli.rb#L61 and #L91

from rubocop.

lloeki avatar lloeki commented on May 18, 2024

In Grammar#add_matching_rbrace, @tokens_without_pos contains:

[[:on_ident, "foo"],
 [:on_sp, " "],
 [:on_lbrace, "{"],
 [:on_sp, " "],
 [:on_tstring_beg, "\""],
 [:on_embexpr_beg, "\#{"],
 [:on_ident, "n"],
 [:on_embexpr_end, "}"],
 [:on_tstring_end, "\""],
 [:on_sp, " "],
 [:on_embexpr_end, "}"]]

Since it misses :on_rbrace, it won't be able to match.

in Grammar#initialize, @tokens_without_pos has :on_rbrace before the call to process_embedded_expressions and lacks :on_rbrace right after. This is, I gather, the crux of the problem.

from rubocop.

lloeki avatar lloeki commented on May 18, 2024

I focused too much on the last brace and finally found the cause:

On ruby 2.0, this is what @tokens_without_pos looks like right after being set:

[[:on_ident, "foo"],
 [:on_sp, " "],
 [:on_lbrace, "{"],
 [:on_sp, " "],
 [:on_tstring_beg, "\""],
 [:on_embexpr_beg, "\#{"],
 [:on_ident, "n"],
 [:on_embexpr_end, "}"],
 [:on_tstring_end, "\""],
 [:on_sp, " "],
 [:on_rbrace, "}"]]

Notice how @tokens_without_pos[-4] is not a :on_rbrace, as it is supposed to be according to the process_embedded_expressions code and comment.

It follows that:

  • when :on_rbrace can be changed to when :on_rbrace, :on_embexpr_end
  • the call to process_embedded_expressions is only necessary for 1.9.3 and below.

from rubocop.

lloeki avatar lloeki commented on May 18, 2024

Fixed in PR #46.

from rubocop.

bbatsov avatar bbatsov commented on May 18, 2024

That's some impressive bug hunting you did, @lloeki! You fixed this issue just as I was about to take a closer look at it. Thanks!

from rubocop.

ismaelga avatar ismaelga commented on May 18, 2024

@lloeki awesome! 👍

from rubocop.

jonas054 avatar jonas054 commented on May 18, 2024

Good job!

from rubocop.

bbatsov avatar bbatsov commented on May 18, 2024

RuboCop 0.4.1 is now out and features that fix!

from rubocop.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.