Skip to content

Commit

Permalink
Use Ruff formatter instead of Black.
Browse files Browse the repository at this point in the history
  • Loading branch information
kpfleming committed Nov 2, 2023
1 parent 1913d50 commit b64d25a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 28 deletions.
11 changes: 3 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
repos:
- repo: https://github.com/tox-dev/pyproject-fmt
rev: "1.2.0"
rev: "1.4.1"
hooks:
- id: pyproject-fmt
# Ruff must be run before Black, so Black can reformat fixes made by Ruff
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.292
rev: v0.1.3
hooks:
- id: ruff-format
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- repo: https://github.com/psf/black-pre-commit-mirror
rev: "23.9.1"
hooks:
- id: black
args: [--preview]
25 changes: 11 additions & 14 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,25 +85,24 @@ python = "3.12"

[tool.hatch.envs.lint]
dependencies = [
"black",
"ruff",
"ruff>=0.1.3",
"mypy",
"pyproject-fmt",
"types-xmltodict",
]

[tool.hatch.envs.lint.scripts]
lint = [
"ruff check --fix --show-fixes .",
"black --preview .",
"ruff format .",
"ruff check --output-format=grouped --fix --show-source --show-fixes .",
"mypy --package jinjanator_plugin_format_xml",
"mypy tests",
"shellcheck workflow-support/*.sh",
"pyproject-fmt pyproject.toml",
]
lint-action = [
"ruff format --check --diff .",
"ruff check --output-format=github .",
"black --check --diff --preview .",
"mypy --package jinjanator_plugin_format_xml",
"mypy tests",
"shellcheck workflow-support/*.sh",
Expand Down Expand Up @@ -175,28 +174,26 @@ replacement = '[\1](https://github.com/kpfleming/jinjanator-plugin-format-xml/tr
pattern = "#(\\d+)"
replacement = "[#\\1](https://github.com/kpfleming/jinjanator-plugin-format-xml/issues/\\1)"

[tool.black]
line-length = 90
target-version = ["py38"]

[tool.ruff]
src = ["src", "tests"]
output-format = "grouped"
target-version = "py38"
ignore-init-module-imports = true
line-length = 100

[tool.ruff.lint]
select = ["ALL"]

ignore = [
"ANN", # Mypy is better at this.
"COM812", # conflicts with formatter
"C901", # Leave complexity to me.
"COM", # Leave commas to Black.
"D", # We have different ideas about docstrings.
"E501", # leave line-length enforcement to Black
"ISC001", # conflicts with formatter
"PLR0912", # Leave complexity to me.
"TRY301", # Raise in try blocks can totally make sense.
]
unfixable = ["F401"]

[tool.ruff.per-file-ignores]
[tool.ruff.lint.per-file-ignores]
"tests/*" = [
"PLC1901", # empty strings are falsey, but are less specific in tests
"PT005", # we use always underscores and explicit names
Expand Down
8 changes: 2 additions & 6 deletions tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,15 @@ def test_format() -> None:

def test_format_namespaces() -> None:
fmt = plugin.XMLFormat("process-namespaces")
result = fmt.parse(
'<testdoc xmlns:a="http://a.com/"><a:cheese>bleu</a:cheese></testdoc>'
)
result = fmt.parse('<testdoc xmlns:a="http://a.com/"><a:cheese>bleu</a:cheese></testdoc>')
assert "testdoc" in result
assert "http://a.com/:cheese" in result["testdoc"]
assert "bleu" == result["testdoc"]["http://a.com/:cheese"]


def test_format_ignore_namespaces() -> None:
fmt = plugin.XMLFormat(None)
result = fmt.parse(
'<testdoc xmlns:a="http://a.com/"><a:cheese>bleu</a:cheese></testdoc>'
)
result = fmt.parse('<testdoc xmlns:a="http://a.com/"><a:cheese>bleu</a:cheese></testdoc>')
assert "testdoc" in result
assert "a:cheese" in result["testdoc"]
assert "bleu" == result["testdoc"]["a:cheese"]

0 comments on commit b64d25a

Please sign in to comment.