-
-
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
Layout/EndOfLine detects Carriage Return in first line when BOM is not set in UTF-8 #4669
Comments
Are you absolutely sure there are no carriage return characters in the file when RuboCop reports |
No
|
Well I'll be darned. Then I don't know. I haven't been able to reproduced the problem, and I've tried on a MinGW system. If you could write a failing spec example, that would be perfect. |
I have similar issues. Depending on the platform I use: windows commandline, mingw, or msys, I am getting different results. Note that if rubocop is running in windows commandline The problems start to multiply when using |
I have no idea ... https://gist.github.com/HansPeterIngo/aae6e1cb95b584ec9a70c93b72e9e416 |
If have done some more testing. I don't understand how the parameter --force-exclusion could change the results. https://gist.github.com/HansPeterIngo/8fb359ba8cbec21e220cf7bfa2bfb6d2 |
I have an idea what might be going on here. It's related to caching. It looks like a file whose line endings have changed still has the same hash key (used when caching the inspection result) as it had before the change. This is a bug in the caching mechanism. You should be able to work around it by running
|
You are correct, after adding |
I'll try to fix it. |
IO.read converts CRLF to LF on Windows. This means that the cached results for a file are still considered valid even if the file has changed EOL characters. This is not good for the Layout/EndOfLine cop, which will produce incorrect results taken from the cache. Reading in binary mode fixes the problem.
Hi, @jonas054 I have a cr in my file, can you explain how to solve this? Thanks. |
Unfortunately, the The solution depends on which platform you're running on (Mac, Windows, ...) and which IDE/Editor. In Emacs, for example, you can search and replace |
Layout/EndOfLine detects CRLF in the first line of UTF-8 LF formatted files if BOM is not set.
Problem goes away after setting BOM.
Expected behavior
Pass with no errors for UTF-8 file without BOM.
Actual behavior
Steps to reproduce the problem
test.rb
.rubocop.yml
Command line
RuboCop version
The text was updated successfully, but these errors were encountered: