"end" is marked as similar
reedstonefood opened this issue · 5 comments
This line
str << '*' * (w+2) << " #{je[4]}"
is showing as being similar to
end
Am I missing something here?
@reedstonefood Hi, thanks for opening this issue. It's really helpful to have a reproduction case when coming across bugs like this.
I can tell you that the engine is mis-reporting the line numbers, and is actually trying to tell you that lines 95 and 96 are similar.
This file reproduces the bug:
# foo.rb
def console_output
w = 36 # width of "card"
str = '*' * (w+2) + "\n"
str << '*' << self.roll_range.center(w) << "* #{je[0]}\n"
str << '*' << @attribute["name"].capitalize.center(w) << "* #{je[1]}\n"
str << '*' << " Symbol : #{@attribute["symbol"]} ".center(w) << "* #{je[2]}\n"
str << '*' << " Cost : #{@attribute["cost"]} ".center(w) << "* #{je[3]}\n"
str << '*' * (w+2) << " #{je[4]}"
puts str.colour(ansi_colour)
endBut this one doesn't:
# foo.rb
def console_output
w = 36 # width of "card"
str = '*' * (w+2) + ""
str << '*' << self.roll_range.center(w) << "* #{je[0]}"
str << '*' << @attribute["name"].capitalize.center(w) << "* #{je[1]}"
str << '*' << " Symbol : #{@attribute["symbol"]} ".center(w) << "* #{je[2]}"
str << '*' << " Cost : #{@attribute["cost"]} ".center(w) << "* #{je[3]}"
str << '*' * (w+2) << " #{je[4]}"
puts str.colour(ansi_colour)
endIt seems to be thrown off by the newline characters in the string literals when coming up with the line numbers. We'll look into where that's happening and try to have a fix out as soon as we can.
Happy to help! The explanation makes perfect sense.
Yes, line numbers and strings (esp w/ heredocs or interpolation) are a mess.
This should be fixed with a newer version of ruby_parser:
3.8.3 / 2016-10-09
-
1 minor enhancement:
- Support Ruby 2.1 number literals. (soutaro)
-
3 bug fixes:
- Fixed line numbers for strs with backslash-newlines. (maxjacobson)
- Improved compatibility on tokenizing number. (soutaro)
- Refactored and fixed multiline array line numbers. (ptoomey3, with changes)
@zenspider @maxjacobson Awesome work!
@reedstonefood I'm going to go ahead and close this issue. Feel free to reopen if you're still getting the same similar to end issues.
Thanks!