Open nate-selzer opened 1 year ago
Hello.
This punctuation problem is mentioned in the doc. The example is about prettier
but it also applies to similar beautifier tools like black
in your case : https://difftastic.wilfred.me.uk/tricky_cases.html#autoformatter-punctuation
We can probably cover the simple cases by defining a list of tree-sitter syntax kinds where trailing commas don't matter. That seems nice to add, and would really help the formatting case.
I know that (1)
and (1,)
are different in Python, and other cases might exist. It'll need care.
Would it be useful to add a CLI argument to ignore trailing commas? It could be a stop-gap solution to this problem.
Some cases to consider:
// ignore final comma
[1]
[1,]
// highlight final comma
[1,]
[1, 2,]
// possibly ignore first comma, especially if `1,` is on a separate line
[1]
[1, 2, 3]
Thanks for reporting a bug! Please include all of the following:
(1) A description of the issue. A screenshot is often helpful too.
When declaring a generator or typing method arguments over multiple lines, formatting libraries like
black
will add a trailing comma like soThese are not syntactically significant, and it'd be nice if they could be ignored by difftastic.
Note that in cases where there is a single object inside parentheses, the comma is syntactically significant.
In the example below, foo is a string, bar is a generator.
Sidenote: it would also be nice if the parentheses around "hi" in the example above would be ignored.
(2) A copy of what you're diffing. If you're diffing files, include the before and after files. If you're using difftastic with a VCS repository (e.g. git), include the URL and commit hash.
Can't share the whole thing as it's proprietary code, but comparing these 2 functions should work
(3) The version of difftastic you're using (see
difft --version
) and your operating system.Difftastic 0.37.0 MacOS Monterey 12.5.1