Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add formatter command line and config option #568

Merged
merged 3 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading