`bit format` struggles with windows line endings
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
- On windows, add files to a bit component with windows-style line-endings (CRLF)
- Run
bit formatfrom 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
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]
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)
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
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 :)
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...
@davidfirst adding you to the discussion here
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...
Fixed in a CR https://bit.cloud/teambit/defender/~change-requests/fix-eol-win