7979 autoupdate_commit_msg: "chore: update pre-commit hooks"
8080` ` `
8181
82- # # Black
82+ # # Format
8383
8484{% rr PC110 %} [Black](https://black.readthedocs.io/en/latest/) is a popular
8585auto-formatter from the Python Software Foundation. One of the main features of
@@ -102,6 +102,8 @@ There are a _few_ options, mostly to enable/disable certain files, remove string
102102normalization, and to change the line length, and those go in your
103103` pyproject.toml` file.
104104
105+ {% tabs %} {% tab black Black %}
106+
105107Here is the snippet to add Black to your `.pre-commit-config.yml` :
106108
107109` ` ` yaml
@@ -124,6 +126,37 @@ Here is the snippet to add Black to your `.pre-commit-config.yml`:
124126
125127{% enddetails %}
126128
129+ {% endtab %} {% tab ruff Ruff-format %}
130+
131+ Ruff, the powerful Rust-based linter, also has a formatter that is designed to
132+ look like Black, but run 30x faster. Here is the snippet to add Black to your
133+ `.pre-commit-config.yml` (combine with Ruff below) :
134+
135+ ` ` ` yaml
136+ - repo: https://github.com/astral-sh/ruff-pre-commit
137+ rev: "v0.1.3"
138+ hooks:
139+ # id: ruff would go here if using both
140+ - id: ruff-format
141+ ` ` `
142+
143+ {% details You can add a Ruff badge to your repo as well %}
144+
145+ [)](https://github.com/astral-sh/ruff)
146+
147+ ` ` ` md
148+ [)](https://github.com/astral-sh/ruff)
149+ ` ` `
150+
151+ ` ` ` rst
152+ .. image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/format.json
153+ :target: https://github.com/astral-sh/ruff
154+ ` ` `
155+
156+ {% enddetails %}
157+
158+ {% endtab %} {% endtabs %}
159+
127160In _very_ specific situations, you may want to retain special formatting. After
128161carefully deciding that it is a special use case, you can use `# fmt: on` and
129162` # fmt: off` around a code block to have it keep custom formatting. _Always_
@@ -179,15 +212,13 @@ src = ["src"]
179212exclude = []
180213
181214[tool.ruff.lint]
182- select = [
183- "E", "F", "W", # flake8
215+ extend-select = [
184216 "B", # flake8-bugbear
185217 "I", # isort
186218 "ARG", # flake8-unused-arguments
187219 "C4", # flake8-comprehensions
188220 "EM", # flake8-errmsg
189221 "ICN", # flake8-import-conventions
190- "ISC", # flake8-implicit-str-concat
191222 "G", # flake8-logging-format
192223 "PGH", # pygrep-hooks
193224 "PIE", # flake8-pie
@@ -203,6 +234,8 @@ select = [
203234 "EXE", # flake8-executable
204235 "NPY", # NumPy specific rules
205236 "PD", # pandas-vet
237+ "FURB", # referb
238+ "PYI", # flake8-pyi
206239]
207240ignore = [
208241 "PLR", # Design related pylint codes
@@ -255,7 +288,8 @@ without this).
255288Here are some good error codes to enable on most (but not all!) projects :
256289
257290- `E`, `F`, `W` : These are the standard flake8 checks, classic checks that have
258- stood the test of time.
291+ stood the test of time. Not required if you use `extend-select` (`W` not
292+ needed if you use a formatter)
259293- `B` : This finds patterns that are very bug-prone. {% rr RF101 %}
260294- `I` : This sorts your includes. There are multiple benefits, such as smaller
261295 diffs, fewer conflicts, a way to auto-inject `__future__` imports, and easier
@@ -270,7 +304,7 @@ Here are some good error codes to enable on most (but not all!) projects:
270304 error string directly in the exception you are throwing, producing a cleaner
271305 traceback without duplicating the error string.
272306- `ISC` : Checks for implicit string concatenation, which can help catch mistakes
273- with missing commas.
307+ with missing commas. (May collide with formatter)
274308- `PGH` : Checks for patterns, such as type ignores or noqa's without a specific
275309 error code.
276310- `PL` : A set of four code groups that cover some (200 or so out of 600 rules)
@@ -284,9 +318,28 @@ Here are some good error codes to enable on most (but not all!) projects:
284318- `T20` : Disallow `print` in your code (built on the assumption that it's a
285319 common debugging tool).
286320- `UP` : Upgrade old Python syntax to your `target-version`. {% rr RF103 %}
321+ - `FURB` : From the refurb tool, a collection of helpful cleanups.
322+ - `PYI` : Typing related checks
287323
288324A few others small ones are included above, and there are even more available in
289- Ruff.
325+ Ruff. You can use `ALL` to get them all, then ignore the ones you want to
326+ ignore. New checks go into `--preview` before being activated in a minor
327+ release.
328+
329+ {% details You can add a Ruff badge to your repo as well %}
330+
331+ [)](https://github.com/astral-sh/ruff)
332+
333+ ` ` ` md
334+ [)](https://github.com/astral-sh/ruff)
335+ ` ` `
336+
337+ ` ` ` rst
338+ .. image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json
339+ :target: https://github.com/astral-sh/ruff
340+ ` ` `
341+
342+ {% enddetails %}
290343
291344{% details Separate tools that Ruff replaces %}
292345
@@ -867,3 +920,5 @@ You also might like the following hook, which cleans Jupyter outputs:
867920[schemastore] : https://schemastore.org
868921
869922<!-- prettier-ignore-end -->
923+
924+ <script src="{% link assets/js/tabs.js %}"></script>
0 commit comments