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 ab16917 commit a3e36ae
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 24 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 @@ -83,26 +83,25 @@ python = "3.12"

[tool.hatch.envs.lint]
dependencies = [
"black",
"ruff",
"ruff>=0.1.3",
"mypy",
"pyproject-fmt",
"pytest", # needed for type-checking plugin_example
]

[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_plugins",
"mypy tests",
"mypy plugin_example",
"shellcheck workflow-support/*.sh",
"pyproject-fmt pyproject.toml plugin_example/pyproject.toml",
]
lint-action = [
"ruff format --check --diff .",
"ruff check --output-format=github .",
"black --check --diff --preview .",
"mypy --package jinjanator_plugins",
"mypy tests",
"mypy plugin_example",
Expand Down Expand Up @@ -173,28 +172,26 @@ replacement = '[\1](https://github.com/kpfleming/jinjanator-plugins/tree/main/\g
pattern = "#(\\d+)"
replacement = "[#\\1](https://github.com/kpfleming/jinjanator-plugins/issues/\\1)"

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

[tool.ruff]
src = ["src"]
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/*" = [
"INP001", # we don't care that these are in implicit namespace packages
"PLC1901", # empty strings are falsey, but are less specific in tests
Expand Down
6 changes: 4 additions & 2 deletions src/jinjanator_plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ class Format(Protocol):
suffixes: Iterable[str] | None
option_names: Iterable[str] | None

def __init__(self, options: Iterable[str] | None) -> None: ... # pragma: no cover
def __init__(self, options: Iterable[str] | None) -> None:
... # pragma: no cover

def parse(self, data_string: str) -> Mapping[str, Any]: ... # pragma: no cover
def parse(self, data_string: str) -> Mapping[str, Any]:
... # pragma: no cover


class FormatOptionUnknownError(Exception):
Expand Down

0 comments on commit a3e36ae

Please sign in to comment.