black icon indicating copy to clipboard operation
black copied to clipboard

Change the error report style to file:line:column

Open ptsl opened this issue 3 years ago • 3 comments

Currently, the following error message is produced if Black fails to format a file:

error: cannot format foo/bar.py: Cannot parse: 1187:8:         text = "xyzzy"
Oh no! 💥 💔 💥
1 file failed to reformat.

Modern editors support the file:line syntax, and even some of them the file:line:column syntax.

For example, Sublime Text:

$ subl -h
...
Filenames may be given a :line or :line:column suffix to open at a specific
location.

Please, change the error message to:

error: cannot parse: foo/bar.py:1187:8:         text = "xyzzy"
Oh no! 💥 💔 💥
1 file failed to reformat.

This will make it easier to copy the file name together with line and column numbers a paste them on the command line for subl.

ptsl avatar Jul 06 '22 09:07 ptsl

+1 to this feature.

From the GH Actions it would open a possibility of adding automated annotations for specific file:line in the PR code via problem matchers:

  • https://github.com/actions/toolkit/blob/master/docs/commands.md#problem-matchers
  • https://github.com/actions/toolkit/blob/master/docs/problem-matchers.md

See an example for pylint or similar:

Makes the GH experience and PR review so much nicer.

arm4b avatar Dec 12 '22 20:12 arm4b

I'll note that Black will never be a linter so this would only be helpful for errors or warnings (if we start emitting them), but in general I'm +1 to the idea. I will be stricter when I come around to reviewing the PR though.

ichard26 avatar Dec 15 '22 22:12 ichard26

I'm not averse to changing the error output if it's helpful but I question how useful this is. These errors are printed when there is a syntax error, and it doesn't seem particularly useful for Black to give you annotations saying there's a syntax error in your file.

JelleZijlstra avatar Dec 16 '22 01:12 JelleZijlstra