Reputation: 143
I am working on a Python project where the Formatting is set to Autopep8. Is there any extension or possible settings where can define to exclude a certain line(s) from formatting when VS is set to format modified code/file on save or with keyboard shortcuts?
Upvotes: 5
Views: 1756
Reputation: 1001
For black and autopep8:
# fmt: off
RED = 0
YELLOW = 1
# fmt: on
For black and yapf:
# yapf: disable
RED = 0
YELLOW = 1
# yapf: enable
For autopep8:
# autopep8: off
RED = 0
YELLOW = 1
# autopep8: on
For black:
BLUE = 0 # fmt: skip
For yapf:
BLUE = 0 # yapf: disable
Upvotes: 3
Reputation: 8411
You can take:
# autopep8: off
# autopep8: on
or
# fmt: off
# fmt: on
Upvotes: 8
Reputation: 899
Add the comment # noqa
to the end of each line you want VS Code to leave alone. For instance, to prevent VS Code from changing
RED = 0
YELLOW = 1
to
RED = 0
YELLOW = 1
just do the following:
RED = 0 # noqa
YELLOW = 1 # noqa
Upvotes: 5