Skip to content
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

Autocorrecting Style/LineEndConcatenation changes behaviour #6597

Closed
glowacki-dev opened this issue Dec 22, 2018 · 2 comments
Closed

Autocorrecting Style/LineEndConcatenation changes behaviour #6597

glowacki-dev opened this issue Dec 22, 2018 · 2 comments
Labels
enhancement good first issue Easy task, suitable for newcomers to the project

Comments

@glowacki-dev
Copy link

When using << to append multiple string to array, Style/LineEndConcatenation suggests using \ to join the strings together.

array = []
array << 'Foo' <<
         'Bar' <<
         'Baz'
puts array.join('-')

Expected behavior

The way we append strings to array should not be changed. Running corrected code should output Foo-Bar-Baz

Actual behavior

Autocorrect changes the code to use \ instead of << which causes strings to be joined before appending them to the array. Running corrected code outputs FooBarBaz

Steps to reproduce the problem

Autocorrect the code snippet above with rubocop -a

RuboCop version

$ rubocop -V
0.61.1 (using Parser 2.5.3.0, running on ruby 2.5.3 x86_64-linux)
@Drenmi
Copy link
Collaborator

Drenmi commented Dec 24, 2018

Unfortunately we can't know what type a variable dereferences to at runtime using static analysis. What we can do is mark this auto-correction as unsafe in the configuration.

@Drenmi Drenmi added enhancement good first issue Easy task, suitable for newcomers to the project labels Dec 24, 2018
@jaredbeck
Copy link
Contributor

Fixed by #6605

@koic koic closed this as completed in e39d0c8 Jan 29, 2019
koic added a commit that referenced this issue Jan 29, 2019
[Fix #6597] - LineEndConcatenation is unsafe
@Drenmi Drenmi mentioned this issue Feb 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement good first issue Easy task, suitable for newcomers to the project
Projects
None yet
Development

No branches or pull requests

3 participants