diff --git a/CHANGES.rst b/CHANGES.rst index 2c4a937e1..e69f730df 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -13,6 +13,8 @@ Added - The ``--preview`` configuration flag is now supported in the configuration files for Darker and Black - Prevent Pylint from updating beyond version 3.2.7 due to dropped Python 3.8 support. +- The ``--formatter=black`` option (the default) has been added in preparation for + future formatters. Removed ------- diff --git a/README.rst b/README.rst index 7acfc0d10..e378e9dce 100644 --- a/README.rst +++ b/README.rst @@ -370,6 +370,8 @@ The following `command line arguments`_ can also be used to modify the defaults: [py33\|py34\|py35\|py36\|py37\|py38\|py39\|py310\|py311\|py312\|py313] Python versions that should be supported by Black's output. [default: per-file auto- detection] +--formatter FORMATTER + Formatter to use for reformatting code To change default values for these options for a given project, add a ``[tool.darker]`` section to ``pyproject.toml`` in the project's root directory, diff --git a/src/darker/command_line.py b/src/darker/command_line.py index fc72274c0..ab7a7369b 100644 --- a/src/darker/command_line.py +++ b/src/darker/command_line.py @@ -83,6 +83,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 125d34c3a..25f9c9e42 100644 --- a/src/darker/config.py +++ b/src/darker/config.py @@ -44,6 +44,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 49f9e3f42..ac324b1e7 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"),