From f2102e16f8feccdf1c65474edbf91f8248710ee7 Mon Sep 17 00:00:00 2001 From: Antti Kaihola <13725+akaihola@users.noreply.github.com> Date: Wed, 20 Mar 2024 21:34:04 +0200 Subject: [PATCH] Add `formatter` command line and config option The only supported value for now is `black`. Fixes #562 --- src/darker/command_line.py | 7 +++++++ src/darker/config.py | 1 + src/darker/tests/test_command_line.py | 24 ++++++++++++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/src/darker/command_line.py b/src/darker/command_line.py index 04dd17078..661420405 100644 --- a/src/darker/command_line.py +++ b/src/darker/command_line.py @@ -75,6 +75,13 @@ def make_argument_parser(require_src: bool) -> ArgumentParser: metavar="VERSION", choices=[v.name.lower() for v in TargetVersion], ) + add_arg( + "Formatter to use for reformatting code", + "--formatter", + default="black", + choices=["black"], + metavar="FORMATTER", + ) return parser diff --git a/src/darker/config.py b/src/darker/config.py index 7beb307d3..e780b217c 100644 --- a/src/darker/config.py +++ b/src/darker/config.py @@ -21,6 +21,7 @@ class DarkerConfig(BaseConfig, total=False): skip_magic_trailing_comma: bool line_length: int target_version: str + formatter: str class OutputMode: diff --git a/src/darker/tests/test_command_line.py b/src/darker/tests/test_command_line.py index 719e5a9fe..65e531057 100644 --- a/src/darker/tests/test_command_line.py +++ b/src/darker/tests/test_command_line.py @@ -183,6 +183,30 @@ def get_darker_help_output(capsys): expect_config=("target_version", "py37"), expect_modified=("target_version", "py37"), ), + dict( + argv=["--formatter", "black", "."], + expect_value=("formatter", "black"), + expect_config=("formatter", "black"), + expect_modified=("formatter", ...), + ), + dict( + argv=["--formatter=black", "."], + expect_value=("formatter", "black"), + expect_config=("formatter", "black"), + expect_modified=("formatter", ...), + ), + dict( + argv=["--formatter", "rustfmt", "."], + expect_value=SystemExit, + expect_config=None, + expect_modified=None, + ), + dict( + argv=["--formatter=rustfmt", "."], + expect_value=SystemExit, + expect_config=None, + expect_modified=None, + ), dict( argv=["--target-version", "py39", "."], expect_value=("target_version", "py39"),