facebook / facebook/jscodeshift
toSource() outputs CRLF newline when input file only had LF
Open
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
Assessment
This issue has not been assessed yet.