skip to Main Content

I’m currently developing for a Ruby on Rails application. I am on a windows machine, using ubuntu through WSL. We have rubocop setup to track formatting on git pushes, and I always run into the same issue. When adding this comment to the top of any file, I receive the error Layout/EndOfLine: Carriage return character detected. The issue seems to be talked about here as well Layout/EndOfLine: Carriage return character detected. module TieConnector

# frozen_string_literal: true

The solution here seems to be to disable the warning, or manually convert the files before pushing.

Does anyone know if there is another solution here? I don’t believe I can edit the rubocop settings as it is not my project. The converting method does work, but gets a bit tedious to do every time I make a new pull request.

Would there be a way to run the dox2unix convert when running git push while targeting the files staged for commit? Or a way to force my machine to use the unix encoding by default?

Any help is appreciated, thank you

2

Answers


  1. It’s a common issue on windows. If you are using vscode you can convert all your files to LF with this shortcut: ctrl + shift + P => ‘change all end of line sequence’ => Enter => Enter => Enter => ‘LF’ => Enter Then you can commit and push your code. If it still don’t work you might see your git configuration, autocrlf in particular. See this response: stackoverflow.com/a/20653073/7542830

    To solve it on a repository level:
    git config --local core.autocrlf input (on you project root)

    Login or Signup to reply.
  2. I’m using RubyInstaller2 (MSYS2 backend, not WSL) and ran into the same issue when RuboCop made some fixes (apparently is used CRLF instead of LF).

    I fixed all the files in vim with :bufdo %s/r//, but still got the error as the first character was still a CR (or CRLF).

    Had to end up using dos2unix, as recommended in Layout/EndOfLine: Carriage return character detected. module TieConnector

    [EDIT]: Error is intermittent on Windows due to missing BOM: https://github.com/rubocop/rubocop/issues/4669

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search