Rubocop: Style/EndOfLine doesn't work on windows

Created on 10 Aug 2016  Â·  13Comments  Â·  Source: rubocop-hq/rubocop

When I examined the crlf.rb containing the CRLF, COP Style/EndOfLine didn't detect CRLF on Windows 7.

This problem is due to the text mode.
processed_source.rb Input file is automatically converted by this code.
"\r\n" => "\n" on Windows.

please add binary mode.

file = File.read(path, mode:'rb')

and options.rb
please add '$stdin.binmode'.

option(opts, '-s', '--stdin') { $stdin.binmode; @options[:stdin] = $stdin.read }

Expected behavior

F:\DEV>rubocop crlf.rb
Inspecting 1 file
C

Offenses:

crlf.rb:1:1: C: Carriage return character detected.
puts 'hello' ...
^^^^^^^^^^^^

1 file inspected, 1 offense detected

Actual behavior

F:\DEV>rubocop crlf.rb
Inspecting 1 file
.

1 file inspected, no offenses detected

Steps to reproduce the problem

ruby -e "STDOUT.binmode;print %(puts 'hello'\r\n)" > crlf.rb
rubocop crlf.rb

ruby -e "STDOUT.binmode;print %(puts 'hello'\r\n)" | rubocop -s crlf.rb

RuboCop version

Include the output of rubocop -V:

F:\DEV>rubocop -V
0.42.0 (using Parser 2.3.1.2, running on ruby 2.2.4 x64-mingw32)

Most helpful comment

Why would you enforce non-windows line endings on windows?

I would have expected this cop to enforce "native" line endings by default (CRLF on windows, LF on linux & osx), perhaps with an option to override that to LF everywhere.

As a windows dev it was very surprising to have this rule enabled by default and flagging every file.

All 13 comments

Why would you enforce non-windows line endings on windows?

I would have expected this cop to enforce "native" line endings by default (CRLF on windows, LF on linux & osx), perhaps with an option to override that to LF everywhere.

As a windows dev it was very surprising to have this rule enabled by default and flagging every file.

Why would you enforce non-windows line endings on windows?

The rule is geared towards distributed development where different developers can be on different platforms. It's more important that we have a consistent behavior in that case than living up to what we think might be expected in projects that only live on one particular platform.

The Style Guide doesn't explain the reasoning behind it, but it's pretty obvious to me that a consistent rule is better than a platform-dependent rule.

@jonas054

Assuming you use git with the defaults, git for Windows will checkout CRLF line endings (even if a Linux/Mac dev committed them as LF). I'd say rubocop and git have different opinions on the same subject here.

This change has made this cop very confusing. I clone the my git project on both linux box and windows box. I see Carriage return character detected. warnings on my windows machine but nothing on my linux machine. On windows I use eclipse editor and have unix line endings set for all files edited in my workspace. But it still complaining about CRLF for every file when running rubocop on windows.

Would you not at least expect the same warnings appearing on linux development machine?

<= 0.42.0 at least things were consistent on both development environments.

file: 'file:///d%3A/My_programs/main_1.rb'
severity: 'Info'
message: 'Carriage return character detected. (convention:Style/EndOfLine)'
at: '1,1'source: ''
I am getting this error on the first line of my first file. This is my first line,{ puts "Ruby is awesome!")
I am also getting this error for the same line
file: 'file:///d%3A/My_programs/main_1.rb'
severity: 'Info'
message: 'Prefer single-quoted strings when you don't need string interpolation or special symbols. (convention:Style/StringLiterals)'
at: '1,6'
source: ''

@lostcowboy I don't think you are reporting bugs in Rubocop. Those messages are suggesting changes to your code. Perhaps you should post a question to StackOverflow if you are requesting assistance.

Hi mikegee, I understand that they are just suggesting changes. But why suggest changes that I can do nothing about? I am real new to all this programing. that one line of code from a book on ruby is showing up as error messages or suggestions if you prefer. I am using windows 10 with the windows version of Ruby22-x64, with visual studeo code 1.10.1, extentions ruby 0.10.4 and ruby-rubocop 0.3.4

untitled_1.zip This file as is shows one suggest message. file: 'file:///d%3A/my_programs/untitled_1.rb'
severity: 'Info'
message: 'Final newline missing. (convention:Style/TrailingBlankLines)'
at: '1,24'
source: ''.
When I add a newline and save it. the message changes to this. file: 'file:///d%3A/my_programs/untitled_1.rb'
severity: 'Info'
message: 'Carriage return character detected. (convention:Style/EndOfLine)'
at: '1,1'
source: ''
I admit I do hit the enter key to add the new line, that's the only way I know how to do it, maybe that's the wrong way. But if that is so, when I copy and paste the first line to the second line and save the file. the suggestion message only shows for the first line, not both lines

Comment: New programmers install extensions like rubocop to catch dumb errors! But I don't know how to fix a error that is caused by saving a file. That's why I think this is a problem with rubocop giving me a error message that I can do nothing about, a bug in other words. It maybe that visual studio code(windows version) is putting a Carriage return character in the first line of the file, but I don't know how to fix it.

New programmers install extensions like rubocop to catch dumb errors!

Great! I wish more did.

Style/EndOfLine is supposed to notice you are on Windows and do the right thing. I suspect this method is returning false for you. Would you please reply with the value of RUBY_PLATFORM Ruby returns for you? Perhaps via: ruby -e'p RUBY_PLATFORM' on the command line.

ruby -e'p RUBY_PLATFORM
"x64-mingw32"

I did install the 64 bit version of ruby. rubyinstaller-2.2.6-x64,
DevKit-mingw64-64-4.7.2-20130224-1432-sfx,
VSCodeSetup-1.9.0 I think this is 32 bit., and I think it did a update to 1.10.1.
I think I ended up adding three gem's files also for dependences. ruby-debug-ide 0.6.0 , debase 0.2.1 , debase-ruby_core_source 0.9.6

Well, that's confusing. That RUBY_PLATFORM should have worked as expected. I think you should open a new issue for this behavior. Also, try to make sure you are using the latest version of Rubocop.

I saw in Notepad ++, setting/preferences/ new document, that you can change the format(line ending) from (windows (cr,lf), Unix (lf), Macintosh (cr). I did not find any format setting like that in VS code, could that be what rubocop is complaining about. I think it is the windows version of VS code that is doing the line formatting.
I am using the latest version, 0.3.4

That setting is at the bottom right of the VS Code window.

Alex -- http://therightstuff.de/ Tiny phone, tiny mail On Fri, Mar 03, 2017 at 10:24pm, lostcowboy < [email protected] [[email protected]] > wrote:
I saw in Notepad ++, setting/preferences/ new document, that you can change the format(line ending) from (windows (cr,lf), Unix (lf), Macintosh (cr). I did not find any format setting like that in VS code, could that be what rubocop is complaining about. I think it is the windows version of VS code that is doing the line formatting.

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub [https://github.com/bbatsov/rubocop/issues/3401#issuecomment-284073948] , or mute the thread [https://github.com/notifications/unsubscribe-auth/AAA_dShida1B5fDI-QZpwaLNpAPW3ptXks5riIT3gaJpZM4Jhbb1] .

Agross, that was Awesome! Changing that to LF fixed the suggest message/error!

Was this page helpful?
0 / 5 - 0 ratings