-
-
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
--auto-correct on windows changes the line-ending #1566
Comments
On my system (Ubuntu Linux), everything still works if I change to |
Hmm. You could have opened a PR... |
Yes, I could have, but since I had no way of verifying other platforms at that time and my sketchy knowledge of the codebase, i chose not to. I am glad that you are taking this up again, I have to admit that I did not use |
This change fixes the main call site of `File.open` when autocorrecting to use binary I/O, so no additional translation from ruby is happening. Additionally there are some required changes to the test infrastructure to keep everything aligned.
This still seems to be an issue in current rubocop. Here's my monkey patch solution that seems to work for anyone else having this issue: # lib/rubocop_autocorrect.rb
RuboCop::Cop::Team.class_eval do
def autocorrect(processed_source, report, original:, offset:)
@updated_source_file = false
return unless autocorrect?
return if report.processed_source.parser_error
new_source = autocorrect_report(report, original:, offset:)
return unless new_source
if @options[:stdin]
# holds source read in from stdin, when --stdin option is used
@options[:stdin] = new_source
else
filename = processed_source.file_path
File.write(filename, new_source, mode: 'wb')
end
@updated_source_file = true
end
end and # .rubocop.yml
require:
- ./lib/rubocop_autocorrect.rb |
I am using Unix-Line-Endings everywhere, but
--auto-correct
writes back CRLF to my files on windows. As far as i can see, there is no setting to change that.If you are opening a file for writing on windows with filemode "W" (
File.open(name, 'w')
), the resulting file will always haveCRLF
as newline characters. To write\n
, you would have to open a file for binary writing ('wb'
)I found two places where a file was opened for writing, i am not sure which is the right place, but maybe it helps: formatter_set.rb#add_formatter and team.rb#autocorrect.
As an experiment, i changed this to be 'wb' on my machine, this did the trick. I was rewarded with unix-style newlines.
The text was updated successfully, but these errors were encountered: