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

Layout/EndOfLine does not choose correct default line ending #6720

Closed
enkessler opened this issue Jan 30, 2019 · 4 comments · Fixed by #6736
Closed

Layout/EndOfLine does not choose correct default line ending #6720

enkessler opened this issue Jan 30, 2019 · 4 comments · Fixed by #6736

Comments

@enkessler
Copy link
Contributor

The Layout/EndOfLine cop automatically decides the 'correct' line ending when set to :native. However, the logic used to make that decision does not come to the correct answer when using JRuby. The check being used is RuboCop::Platform.windows? which just does an inspection of RUBY_PLATFORM:

RUBY_PLATFORM =~ /cygwin|mswin|mingw|bccwin|wince|emx/

However, when using JRuby the value of RUBY_PLATFORM will be java, even when using Windows. This results in the cop deciding that it is in a non-Windows environment and thus check for 'lf' line endings instead of 'crlf'.


Expected behavior

The Layout/EndOfLine cop should natively use 'crlf' line endings for Windows with JRuby.

Actual behavior

The Layout/EndOfLine cop natively uses 'lf' line endings for Windows with JRuby.

Steps to reproduce the problem

  • use Windows
  • use JRuby (9.1.17, in my case)
  • have a Ruby file with crlf line endings

Run rubocop against the file and the generated report will contain violations for Layout/EndOfLine.

RuboCop version

0.63.1 (using Parser 2.6.0.0, running on jruby 2.3.3 java)

@mikegee
Copy link
Contributor

mikegee commented Jan 30, 2019

Do you know how Rubocop can know the correct line ending on JRuby?

@enkessler
Copy link
Contributor Author

enkessler commented Jan 31, 2019

Using RbConfig::CONFIG['host_os'] instead of using RUBY_PLATFORM seems to be the way. I get 'mswin32' when I check it instead of getting 'java', like I do RUBY_PLATFORM.

Edit: Gem.win_platform? could also work.

@Drenmi
Copy link
Collaborator

Drenmi commented Feb 5, 2019

Thanks for the report and investigation @enkessler! 🙇 Would you be interested in opening a PR for this?

@enkessler
Copy link
Contributor Author

I can take a crack at it some time this week, sure.

enkessler added a commit to enkessler/rubocop that referenced this issue Feb 6, 2019
Using a different constant to determine the current operating system.
@koic koic closed this as completed in #6736 Feb 6, 2019
enkessler added a commit to enkessler/rubocop that referenced this issue Feb 8, 2019
Including the bug fix for rubocop#6720.
@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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants