question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Migration] v4 to v5 codemod converts all .js files to CRLF line endings on Windows, ignoring existing line endings

See original GitHub issue

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Current behavior 😯

The codemod rewrites every JS file in the specified directory using CRLF line endings, even files that aren’t otherwise modified by the codemod.

Expected behavior 🤔

Files that need to be modified to migrate to v5 should be written out with the existing line endings, regardless of which OS the codemod is being run on. Other files should be left untouched.

Steps to reproduce 🕹

Steps:

  1. On Windows 10, check out a repo with LF line endings.
  2. Run npx @mui/codemod v5.0.0/preset-safe .

Result: every file will now have CRLF line endings.

Context 🔦

The repo I’m working with has all files checked in with LF line endings. The autocrlf git setting is set to input on my machine, so the files are checked out with unchanged line endings.

I looked at the jscodeshift options, but didn’t see anything obvious that would be able to change this behavior.

Your environment 🌎

`npx @mui/envinfo`
  System:
    OS: Windows 10 10.0.19043
    CPU: (8) x64 Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
    Memory: 1.43 GB / 15.81 GB
  Binaries:
    Node: 16.13.0 - C:\Program Files\nodejs\node.EXE
    npm: 8.1.4 - ~\AppData\Roaming\npm\npm.CMD
  Managers:
    RubyGems: 3.1.4 - C:\Ruby27-x64\bin\gem.CMD
  Utilities:
    Git: 2.34.0.
  Virtualization:
    Docker: 20.10.8 - C:\Program Files\Docker\Docker\resources\bin\docker.EXE
  SDKs:
    Windows SDK:
      AllowAllTrustedApps: Disabled
  Languages:
    Bash: 5.0.17 - C:\WINDOWS\system32\bash.EXE
    Ruby: 2.7.2 - C:\Ruby27-x64\bin\ruby.EXE
  Browsers:
    Chrome: 95.0.4638.69
    Edge: Spartan (44.19041.1266.0), Chromium (96.0.1054.29), ChromiumDev (97.0.1069.0)
    Internet Explorer: 11.0.19041.1202

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:3
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
fwextensionscommented, Dec 1, 2021

The line endings does not change when I run the tests (I am using Windows).

If the files you’re running the tests on already have CRLF line endings (the default on Windows), then you won’t see any change. It’s when you run the codemod on an LF file on Windows that you see the line endings get changed.

Here I created a 3 line JS file and set the line endings to LF. I copied it to another folder and ran the codemod on it there. Then I diff’d the modded file with the original one:

image

The code is completely unchanged, since there are no MUI references in the file. But every line now ends with CRLF instead of LF. In a larger project, dozens or hundreds of files will appear changed, even though it’s just a line ending change.

1reaction
bdeforecommented, Jan 8, 2022

A further note for the future fix: this occurred to me in reverse: running the codemon tool converted CRLF -> LF when run on my Manjaro Linux machine, causing a loud diff that interfered with review. This alerted me to another tool that had inadvertently changed my LF -> CRLF and something I wanted to address anyway, but ideally codemon’s underlying tools don’t make any line ending changes.

More reading on this and how to prevent it happening to you: https://www.aleksandrhovhannisyan.com/blog/crlf-vs-lf-normalizing-line-endings-in-git/

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Migration] v4 to v5 codemod converts all .js files to CRLF line ...
[Migration] v4 to v5 codemod converts all .js files to CRLF line endings on Windows, ignoring existing line endings #29822.
Read more >
How to force consistent line endings in Git commits with cross ...
If you're on a Windows machine, set it to true — this converts LF endings into CRLF when you check out code: $...
Read more >
Important changes on CotEditor 4.2
Prior to version 4.2.0, all line ending codes were internally treated as LF ( U+000A ). From version 4.2.0, the actual line ending...
Read more >
react-native-cli | Yarn - Package Manager
The first one is a lightweight package that should be installed globally ( npm install -g react-native-cli ), while the second one contains...
Read more >
Dealing with line endings in Windows with Git and ESLint
When you checkout a branch in Windows, Git may replace the line endings with CRLF. In this post, we'll see how you can...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found