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

Allow single-quoted strings to be the same as double-quoted strings #714

Open
eduard93 opened this issue May 15, 2024 · 5 comments
Open

Comments

@eduard93
Copy link

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
Copy link
Owner

Wilfred commented May 23, 2024

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.

@Wilfred Wilfred closed this as completed May 23, 2024
@eduard93
Copy link
Author

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
Copy link
Owner

Wilfred commented May 28, 2024

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

let clean_content = if is_comment && content.lines().count() > 1 {

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

@Wilfred Wilfred changed the title difft does shows single/double quote as a diff for python Allow single-quoted strings to be the same as double-quoted strings Jul 16, 2024
@Wilfred
Copy link
Owner

Wilfred commented Jul 16, 2024

Thinking about this some more, I think this is a worthwhile addition, but language configurations should opt-in to it.

@Wilfred Wilfred reopened this Jul 16, 2024
@ekorchmar
Copy link

ekorchmar commented Jul 21, 2024

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

let clean_content = if is_comment && content.lines().count() > 1 {

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

First and last characters are not very clean I am aftaid. The Python itself has variable length of string delimiters. Multiline strings (syntactically different to usual " or ' strings, but not between themselves) are denoted with three of the same "ticks":

my_string = """Hello, World!
I love multiline strings.
"""
other_string = '''Hello, World!
I love multiline strings.
'''

assert my_string == other_string

Good news is that TS understands this; so maybe we can opt-in to take left and right node around the string? Here is generated tree, note "string_start" and "string_end" nodes.

image

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

No branches or pull requests

3 participants