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

Style/EndOfLine doesn't work on windows #3401

Closed
asm256 opened this issue Aug 10, 2016 · 13 comments
Closed

Style/EndOfLine doesn't work on windows #3401

asm256 opened this issue Aug 10, 2016 · 13 comments

Comments

@asm256
Copy link

asm256 commented Aug 10, 2016

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)
Neodelf pushed a commit to Neodelf/rubocop that referenced this issue Oct 15, 2016
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.
@jarredholman
Copy link

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.

@jonas054
Copy link
Collaborator

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.

@agross
Copy link

agross commented Dec 13, 2016

@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.

@poliva83
Copy link

poliva83 commented Dec 16, 2016

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.

@lostcowboy
Copy link

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: ''

@mikegee
Copy link
Contributor

mikegee commented Mar 3, 2017

@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.

@lostcowboy
Copy link

lostcowboy commented Mar 3, 2017

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.

@mikegee
Copy link
Contributor

mikegee commented Mar 3, 2017

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.

@lostcowboy
Copy link

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

@mikegee
Copy link
Contributor

mikegee commented Mar 3, 2017

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.

@lostcowboy
Copy link

lostcowboy commented Mar 3, 2017

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

@agross
Copy link

agross commented Mar 3, 2017 via email

@lostcowboy
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants