Skip to content

Commit

Permalink
Use the ruff formatter, instead of black
Browse files Browse the repository at this point in the history
I have based this commit on:
- ruff-pre-commit README.md | Using Ruff with pre-commit
  https://github.com/astral-sh/ruff-pre-commit/blob/main/README.md
- The Ruff Formatter | Conflicting lint rules
  https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules

Support for the ruff formatter was added in pytest-ruff by commits from
October 2023, released the same day as versions 0.2 and 0.2.1. Hence, it
makes sense to require pytest-ruff ≥ 0.2.1 now that we use the ruff
formatter.

I cannot find in ruff the equivalent for `skip-string-normalization` in
black. This is currently an open issue, in progress:
  astral-sh/ruff#7305
  astral-sh/ruff#7525
  astral-sh/ruff#8822
I have settled on single quotes, for now.
  • Loading branch information
DimitriPapadopoulos committed Nov 23, 2023
1 parent 5732ebe commit 03f4e29
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 22 deletions.
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
repos:
- repo: https://github.com/psf/black
rev: 22.6.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.6
hooks:
- id: black
- id: ruff-format
4 changes: 0 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@
:target: https://github.com/astral-sh/ruff
:alt: Ruff

.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
:target: https://github.com/psf/black
:alt: Code style: Black

.. .. image:: https://readthedocs.org/projects/PROJECT_RTD/badge/?version=latest
.. :target: https://PROJECT_RTD.readthedocs.io/en/latest/?badge=latest
Expand Down
3 changes: 0 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,4 @@
requires = ["setuptools>=56", "setuptools_scm[toml]>=3.4.1"]
build-backend = "setuptools.build_meta"

[tool.black]
skip-string-normalization = true

[tool.setuptools_scm]
8 changes: 0 additions & 8 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,6 @@ filterwarnings=
# Ensure ResourceWarnings are emitted
default::ResourceWarning

# shopkeep/pytest-black#55
ignore:<class 'pytest_black.BlackItem'> is not using a cooperative constructor:pytest.PytestDeprecationWarning
ignore:The \(fspath. py.path.local\) argument to BlackItem is deprecated.:pytest.PytestDeprecationWarning
ignore:BlackItem is an Item subclass and should not be a collector:pytest.PytestWarning

# shopkeep/pytest-black#67
ignore:'encoding' argument not specified::pytest_black

# realpython/pytest-mypy#152
ignore:'encoding' argument not specified::pytest_mypy

Expand Down
22 changes: 22 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[lint]
extend-ignore = [
# https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules
"W191",
"E111",
"E114",
"E117",
"D206",
"D300",
"Q000",
"Q001",
"Q002",
"Q003",
"COM812",
"COM819",
"ISC001",
"ISC002",
]

[format]
# https://docs.astral.sh/ruff/settings/#format-quote-style
quote-style = "single"
5 changes: 1 addition & 4 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,12 @@ testing =
# upstream
pytest >= 6
pytest-checkdocs >= 2.4
pytest-black >= 0.3.7; \
# workaround for jaraco/skeleton#22
python_implementation != "PyPy"
pytest-cov
pytest-mypy >= 0.9.1; \
# workaround for jaraco/skeleton#22
python_implementation != "PyPy"
pytest-enabler >= 2.2
pytest-ruff
pytest-ruff >= 0.2.1

# local

Expand Down

0 comments on commit 03f4e29

Please sign in to comment.