benjamn / recast

JavaScript syntax tree transformer, nondestructive pretty-printer, and automatic source map generator
MIT License
4.99k stars 350 forks source link

Make `lineTerminator` inferred based on the source (like `tabWidth`) #269

Open cowchimp opened 8 years ago

cowchimp commented 8 years ago

Hi.

Recast chooses the lineTerminator to use based on the default end-of-line marker of the host OS. See this line: https://github.com/benjamn/recast/blob/539d044ef2d295878e056f6b5c9648a7c05f9823/lib/options.js#L21

This can cause every single line in the original file appear changed if you're using Windows to run a codemod on a file that was originally written in Mac\Linux, or vice-versa. (As a Windows user, most of the open source-code I depend on uses \n and not \r\n because it was not written on Windows, so this is quite a common scenario for me).

Is it possible to make recast infer the original EOL marker based on the original file, like it does for tabWidth?

Thank you!

Full disclosure: I didn't run recast directly but rather via jscodeshift, but I'm assuming this is still the relevant repo to address this issue.

Please LMK if you need any further clarifications from me. Would be happy to take a swing at submitting a PR with some guidance as to how this could be achieved.

e-cloud commented 6 years ago

@benjamn any progress?