benjamn / benjamn/recast

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

Open
#269 2 comments 11 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
5.3k
Forks
363
Avg merge
3d 8h
Merged PRs (30d)
3

Description

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.

Contributor guide

No contributing guide indexed for this repository

Research direction

The issue points to lib/options.js line 21; start there and compare lineTerminator handling with tabWidth inference. Done means recast derives the EOL marker from the original source instead of the host OS, preventing whole-file line-ending changes on Windows or other platforms.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.