bit icon indicating copy to clipboard operation
bit copied to clipboard

`bit format` struggles with windows line endings

Open mathias-falkenberg opened this issue 2 years ago • 6 comments

Describe the bug

When running bit format in windows, the formatter will report issues in all files - presumably due to the config specifying 'LF' line endings but files having 'CRLF'.

According to the format command output, the issues are fixed, but re-running bit format finds the same issues again.

Steps to Reproduce

  1. On windows, add files to a bit component with windows-style line-endings (CRLF)
  2. Run bit format from the CLI

The format command claims to have fixed the issues, but re-running the command finds the same issues still present

Expected Behavior

The CRLF line endings should be changed to LF as per the prettier config

Screenshots, exceptions and logs

image

Specifications

  • Bit version: 0.1.52
  • Workspace type: harmony
  • Node version: 18.16.0
  • npm version: 9.5.1
  • Platform: Microsoft Windows [Version 10.0.19045.2965]

mathias-falkenberg avatar May 31 '23 07:05 mathias-falkenberg

interesting, according to prettier docs, since v2 the default of prettier is LF - https://prettier.io/docs/en/options.html#end-of-line we are using a newer version. Is there a chance that something else changed it back to CRLF? (it might be your IDE or Git)

GiladShoham avatar May 31 '23 08:05 GiladShoham

The behaviour is reproducible even if I don't have the files open in my IDE (VSCode)

I have tried running prettier (v2.8.8) directly on the files in my workspace (npx prettier **/*.ts --write), which will update the line endings correctly. Afterwards, bit format will no longer report issues, so I do think this is an issue with bit format and not prettier as such

mathias-falkenberg avatar May 31 '23 08:05 mathias-falkenberg

thanks, I'll check it any chance you can send me some files with CRLF ending for testing? I don't have a Windows machine ready to go here :)

GiladShoham avatar May 31 '23 08:05 GiladShoham

Might be difficult to test, then. I assume this could be an issue with the function used to write the formatted contents back to the file which might have some OS-specificity. If I run bit format from Windows Subsystem for Linux (WSL), it correctly replaces line endings. So it smells like the line endings are not the problem per se, but rather that bit format works differently under Windows...

mathias-falkenberg avatar May 31 '23 09:05 mathias-falkenberg

@davidfirst adding you to the discussion here

GiladShoham avatar May 31 '23 10:05 GiladShoham

As a workaround, I can (and perhaps should) add "files.eol": "\n", to my .vscode/settings.json. This causes VSCode to enforce the line endings - but of course, it is not portable to devs not using VSCode...

mathias-falkenberg avatar May 31 '23 12:05 mathias-falkenberg

Fixed in a CR https://bit.cloud/teambit/defender/~change-requests/fix-eol-win

davidfirst avatar Apr 22 '24 17:04 davidfirst