Skip to content

Commit

Permalink
Merge pull request #568 from akaihola/formatter-option
Browse files Browse the repository at this point in the history
Add `formatter` command line and config option
  • Loading branch information
akaihola authored Oct 11, 2024
2 parents c70c7fa + f6c6693 commit f8f8d6c
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------
Expand Down
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions src/darker/command_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
1 change: 1 addition & 0 deletions src/darker/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class DarkerConfig(BaseConfig, total=False):
skip_magic_trailing_comma: bool
line_length: int
target_version: str
formatter: str


class OutputMode:
Expand Down
24 changes: 24 additions & 0 deletions src/darker/tests/test_command_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down

0 comments on commit f8f8d6c

Please sign in to comment.