Skip to content

Commit

Permalink
feat: only support preview = in [tool.black]
Browse files Browse the repository at this point in the history
Avoids confusion about precendence.
  • Loading branch information
akaihola committed Aug 9, 2024
1 parent 62ecbe7 commit c2cafb7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
3 changes: 1 addition & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,6 @@ An example ``pyproject.toml`` configuration file:
line-length = 80 # Passed to isort and Black, override their config
target-version = ["py312"] # Passed to Black, overriding its config
log_level = "INFO"
preview = false # Passed to Black, overriding its config
[tool.black]
line-length = 88 # Overridden by [tool.darker] above
Expand All @@ -426,7 +425,7 @@ An example ``pyproject.toml`` configuration file:
exclude = "test_*\.py"
extend_exclude = "/generated/"
force_exclude = ".*\.pyi"
preview = true # Overridden above
preview = true # Only supported in [tool.black]
[tool.isort]
Expand Down
1 change: 0 additions & 1 deletion src/darker/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class DarkerConfig(BaseConfig, total=False):
skip_magic_trailing_comma: bool
line_length: int
target_version: str
preview: bool


class OutputMode:
Expand Down
23 changes: 23 additions & 0 deletions src/darker/tests/test_command_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,19 @@ def test_parse_command_line_deprecated_option(
assert {c.args[0] for c in warn.call_args_list} == expect_warn


def test_parse_command_line_unknown_conffile_option(tmp_path, monkeypatch):
"""`parse_command_line` warns about deprecated configuration options."""
monkeypatch.chdir(tmp_path)
config = {"unknown": "value", "preview": "true"}
(tmp_path / "pyproject.toml").write_text(toml.dumps({"tool": {"darker": config}}))
with pytest.raises(
ConfigurationError,
match=r"Invalid \[tool.darker\] keys in pyproject.toml: preview, unknown",
):

parse_command_line(["-"])


def test_help_description_without_isort_package(capsys):
"""``darker --help`` description shows how to add ``isort`` if it's not present"""
with isort_present(False):
Expand Down Expand Up @@ -565,6 +578,16 @@ def test_black_options(monkeypatch, tmpdir, git_repo, options, expect):
options=["-t", "py39"],
expect=call(target_versions={TargetVersion.PY39}),
),
dict(
config=["preview = true"],
options=[],
expect=call(preview=True),
),
dict(
config=["preview = false"],
options=["--preview"],
expect=call(preview=True),
),
dict(
config=["preview = true"],
options=["--preview"],
Expand Down

0 comments on commit c2cafb7

Please sign in to comment.