Comments (12)
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.
@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.
@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.
And the output from Ripper is the same on both. So it should be something else
from rubocop.
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.
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.
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 towhen :on_rbrace, :on_embexpr_end
- the call to
process_embedded_expressions
is only necessary for 1.9.3 and below.
from rubocop.
Fixed in PR #46.
from rubocop.
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.
@lloeki awesome! 👍
from rubocop.
Good job!
from rubocop.
RuboCop 0.4.1 is now out and features that fix!
from rubocop.
Related Issues (20)
- Style/CommentedKeyword has different definition of disable/todo comment format
- Lint/Debugger does not catch require "debug/start" HOT 3
- Invalid offense/autocorrect for `Style/RedundantLineContinuation` HOT 1
- Wrong Style/RedundantLineContinuation and autocorrect HOT 1
- Fix auto-generation of outstanding issues to respect XDG configuration
- `AssignmentInCondition` didn't find the style problem HOT 6
- Invalid autocorrect in Layout/SpaceInsideHashLiteralBraces
- Infinite loop in `Style/Encoding` with uppercase token
- Improve the error message in expect_offense
- def_node_matcher for explicit and implicit nil HOT 5
- rubocop-1.61.0 crashes when the project's gemspec dynamically sets `spec.required_ruby_version` HOT 1
- Many methods on `Parser::Source::Range` from `Offense.highlighted_area` raise `NoMethodError` HOT 2
- False positive for `Lint/ToEnumArguments`
- Incompatibility between `parser_prism` and `ruby_extractors` HOT 4
- Error for `Lint/MixedCaseRange` when invalid utf8 and offense exists
- Infinite loop with `Style/IfUnlessModifier -> Layout/EndAlignment, Layout/IndentationWidth`
- False positives for Lint/UnusedBlockArgument when using parser_prism HOT 4
- Invalid offense/autocorrect for `Style/RedundantLineContinuation`
- invalid offense Style/HashEachMethods
- False positive for `Lint/RedundantWithIndex` when calling with_index without each beforehand
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rubocop.