facebook / jscodeshift

A JavaScript codemod toolkit.
https://jscodeshift.com
MIT License
9.22k stars 477 forks source link

jscodeshift command converts LF to CRLF #509

Closed arai-a closed 2 years ago

arai-a commented 2 years ago

Related to https://github.com/facebook/jscodeshift/issues/262 , running jscodeshift command on a file with LF converts the newline to CRLF, even if there's no other change.

workaround posted in https://github.com/facebook/jscodeshift/issues/262#issuecomment-516563941 isn't applicable for jscodeshift command.

ElonVolo commented 2 years ago

Are you perchance running jscodeshift on Windows (I'm guessing that won't matter, but I'd like to rule our anything platform-specific first).

arai-a commented 2 years ago

oh, sorry, I forgot to explain the context. yes, I bumped into the issue when running jscodeshift across OSes, and I see the behavior only on Windows.

ElonVolo commented 2 years ago

The behavior itself you're seeing is caused by a recast issue. Recast defaults to the platform-specific line terminator.

https://github.com/benjamn/recast/issues/269

So is the issue that toSource() in your workaround isn't actually changing the line terminator used for the output?

arai-a commented 2 years ago

I'm running node_modules/.bin/jscodeshift command after npm install jscodeshift. instead of importing jscodeshift from JS application. So there's no toSource call I can modify.

https://github.com/facebook/jscodeshift/blob/main/bin/jscodeshift.js

Possible fix is to add new command-line parameter to jscodeshift command that receives the override for line terminator.

If the fix sounds reasonable, I'll look into fixing the command.

arai-a commented 2 years ago

oh, sorry, I misunderstood the issue. I see toSource() call in the transform file I'm using.