Skip to content

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

Closed
@oBusk

Description

@oBusk

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 (diff@5.0.0). 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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions