2

I could not find the way how to run black/isort on "read-only" mode, i.e., --check/--check-only flag on VSCode. There was "format on save" option, but I prefer "check where is wrong line and run formatter manually" way. (That is, I want to use black/isort as linter instead of formatter in vscode)

Is there any option to do this? Or, am I missing something?

keisuke
  • 2,123
  • 4
  • 20
  • 31

1 Answers1

3

Both black and isort have a --diff flag that outputs the changes that would have been made in the files without actually changing them. From black docs (isort usage is similar):

$ black test.py --diff
--- test.py     2021-03-08 22:23:40.848954 +0000
+++ test.py     2021-03-08 22:23:47.126319 +0000
@@ -1 +1 @@
-print ( 'hello, world' )
+print("hello, world")
would reformat test.py
All done! ✨  ✨
1 file would be reformatted.

I don't know how to integrate this output with VSCode's editor, but it's a start for what you're looking for.

sourcream
  • 210
  • 1
  • 11