Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to strip/ignore cr at end of line(?) #343

Closed
oBusk opened this issue Feb 5, 2022 · 1 comment · Fixed by #344
Closed

Option to strip/ignore cr at end of line(?) #343

oBusk opened this issue Feb 5, 2022 · 1 comment · Fixed by #344

Comments

@oBusk
Copy link
Contributor

oBusk commented Feb 5, 2022

Hello!

I've recently created a RFC (npm/rfcs#522) for npm diff to have an option to ignore cr to allow better diffing between platforms.

The problem with npm diff is that if you're developing on a Windows machine and want to compare it to a package built on UNIX, or vice versa, every line will appear as changed since the lineendings are different.

In the RFC I mention git diff --ignore-cr-at-eol and GNU diff --strip-trailing-cr as prior art.

While investigating how this would be implemented, I notice that diff does not have an option for something like this. I tried to find any previous issues/PRs that talked about this but only really found #68 which seems more concerned with separating lines from lineendings (correct me if I'm wrong) and only mentions crlf in passing.

It does mention that diffTrimmedLines() should ignore line endings since it should trim the lines, but as far as I can tell, this is not the case currently ([email protected]). I tested in a simple example setup.

Would an option similar to those in git/GNU diff make sense in jsdiff too, or is this against the nature of this package?

In the previously mentioned issue, there is also a new method, which is now an option, the newlineIsToken option which treats line endings as separate tokens, so I suppose it would be possible to use diffLines() with newLineIsToken: true and then parse the diff to ignore changes to line ending tokens (CRLF and LF). There is no such support in the patch methods as far as I can tell.

(Probable duplicate: #275)

@oBusk
Copy link
Contributor Author

oBusk commented Feb 5, 2022

It should be mentioned that it would of course be possible to preprocess data before it's passed to jsdiff to convert all CRLFLF and thus get a proper diff without modifying jsdiff. Is an option unecessary and/or unwanted? 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant