-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Regression on LineEndConcatenation #1054
Comments
Ops, seems we didn't have a test case for that scenario. I'll have that fixed. |
/cc @barunio |
@jonas054 @yujinakayama I played a bit with this, but didn't manage to solve it in an easy manner (without gutting the cop). I'd appreciate it if you take a look - perhaps you'll find a solution I'm missing. |
How about something like comment_in_between = processed_source.comments.find do |c|
c.loc.line > receiver.loc.line && c.loc.line < first_arg.loc.line
end
return if comment_in_between towards the end of Seems obvious. Maybe too obvious. I might be missing something. 😄 |
@jonas054 Think I did something similar initially, but it messed up the reporting of the multiple offenses. As I played with this a few weeks back my memory's a bit fuzzy on the subject. |
Just a random thought, maybe this can be handled by inspecting tokens rather than AST? Since we are interested only in string literals, there's enough information in tokens. Though this requires gutting the cop. [6] pry(main)> RuboCop::ProcessedSource.new(%('foo' +\n'bar')).tokens
=> [#<RuboCop::Token:0x007f9087818980
@pos=#<Parser::Source::Range (string) 0...5>,
@text="foo",
@type=:tSTRING>,
#<RuboCop::Token:0x007f90878188e0
@pos=#<Parser::Source::Range (string) 6...7>,
@text="+",
@type=:tPLUS>,
#<RuboCop::Token:0x007f9087818840
@pos=#<Parser::Source::Range (string) 8...13>,
@text="bar",
@type=:tSTRING>]
[7] pry(main)> RuboCop::ProcessedSource.new(%('foo' \\\n'bar')).tokens
=> [#<RuboCop::Token:0x007f90824e6e60
@pos=#<Parser::Source::Range (string) 0...5>,
@text="foo",
@type=:tSTRING>,
#<RuboCop::Token:0x007f90824e6dc0
@pos=#<Parser::Source::Range (string) 8...13>,
@text="bar",
@type=:tSTRING>]
[8] pry(main)> RuboCop::ProcessedSource.new(%('foo' +\n# some comment\n'bar')).tokens
=> [#<RuboCop::Token:0x007f9087663a18
@pos=#<Parser::Source::Range (string) 0...5>,
@text="foo",
@type=:tSTRING>,
#<RuboCop::Token:0x007f9087663978
@pos=#<Parser::Source::Range (string) 6...7>,
@text="+",
@type=:tPLUS>,
#<RuboCop::Token:0x007f90876638d8
@pos=#<Parser::Source::Range (string) 8...22>,
@text="# some comment",
@type=:tCOMMENT>,
#<RuboCop::Token:0x007f9087663838
@pos=#<Parser::Source::Range (string) 23...28>,
@text="bar",
@type=:tSTRING>] |
I like @yujinakayama's idea (it's something I considered as well) and I think it'd yield performance improvements over the existing solution. |
I tried to rework the cop with token information and it looked perfect, but it turned out there's a case that cannot be handled with tokens. |
Can't we just do a check if the string is followed by |
This error was caused by the previous LineEndConcationation autocorrection. See possibly rubocop/rubocop#1054
Recent changes in LineEndConcatenation means that
is regarded as incorrect.
The text was updated successfully, but these errors were encountered: