Skip to content

Commit

Permalink
Add formatter command line and config option
Browse files Browse the repository at this point in the history
The only supported value for now is `black`.

Fixes #562
  • Loading branch information
akaihola committed Sep 15, 2024
1 parent 77ee2fb commit d77d141
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/darker/command_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,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 @@ -24,6 +24,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 d77d141

Please sign in to comment.