facebook / facebook/jscodeshift

toSource() outputs CRLF newline when input file only had LF

Open
#262 5 comments 10 reactions 0 assignees View on GitHub
bug
Dominant language
JavaScript
Stars
10k
Forks
498
PR merge metrics
No merged PRs in 30d

Description

The README claims that it will do its best to preserve whitespace/formatting. But instead it adds CRLF when I wasn’t expecting it. It looks like I can work around it by doing something like:

```javascript
module.exports = function (fileInfo, {
jscodeshift,
}, options) {
const isUnix = fileInfo.source.indexOf('\r\n') === -1;
const dom = jscodeshift(fileInfo.source);
return dom.toSource().replace(/\r\n/g, isUnix ? '\n' : '\r\n');
};
```

However, that behavior should probably just be provided out of the box instead of requiring this hack.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.