-
-
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
Style/EndOfLine doesn't work on windows #3401
Comments
Make sure file/stdin contents are read in binary mode so that CR+LF line endings are preserved. Otherwise Style/EndOfLine will never report on Windows.
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. |
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. |
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 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' |
@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' 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. |
Great! I wish more did.
|
ruby -e'p RUBY_PLATFORM I did install the 64 bit version of ruby. rubyinstaller-2.2.6-x64, |
Well, that's confusing. That |
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. |
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 [#3401 (comment)] , 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! |
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.
and options.rb
please add '$stdin.binmode'.
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
:The text was updated successfully, but these errors were encountered: