Wilfred / difftastic

a structural diff that understands syntax 🟥🟩
https://difftastic.wilfred.me.uk/
MIT License
19.94k stars 317 forks source link

difft does shows single/double quote as a diff for python #714

Closed eduard93 closed 1 month ago

eduard93 commented 1 month ago

Great tool!

(1) A description of the issue. A screenshot is often helpful too.

I'm comparing two python files, where the majority of changes is a swap between single and double quotes, which should be ignored. However difftastic shows quote changes as a difference.

image

(2) A copy of what you're diffing. I'm diffing files.

Before:

def my_func():
    print("Hello World")

After:

def my_func():
    print('Hello World')

Expected result: no differences.

(3) The version of difftastic you're using (see difft --version) and your operating system.

Difftastic 0.58.0 (0c92771 2024-05-10, built with rustc 1.65.0) Running on Windows 11.

Wilfred commented 1 month ago

This is intentional I'm afraid. Difftastic is a syntactic differ, and semantic information about which string literals are equivalent are out of scope. In some languages, single-quoted strings and double-quoted strings are different (e.g. in bash or PHP) due to different interpolation rules.

eduard93 commented 1 month ago

Fair. Any chance you can point me to a place where I can make this change in my forked repo? Something like a place where difftastic gets a list of changes to output? I want to manually remove single/double quote differences.

Wilfred commented 1 month ago

@eduard93 you should be able to change what's considered the content of the Atom when it's a string here:

https://github.com/Wilfred/difftastic/blob/b88b4056203cdd3075cd341595411195671a163b/src/parse/syntax.rs#L411

If it's an AtomKind::String, drop the first and last characters of content.