Skip to content

Commit da5669c

Browse files
committed
feat: default pre-commit hook now fixes all files
"pass_filenames: false" is the default now. Choose one of the other hooks if you want a different behavior.
1 parent a5532d5 commit da5669c

File tree

5 files changed

+49
-22
lines changed

5 files changed

+49
-22
lines changed

.pre-commit-hooks.yaml

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,53 @@
11
# https://pre-commit.com/#creating-new-hooks
2+
3+
# This is the new default: to fix all files, NOT passing filenames to the hook.
4+
# The usage of "pass_filenames: false`` is not recommended by the authors of pre-commit,
5+
# but it's the only way to make Nitpick work as intended.
6+
# See this comment for more context: https://github.com/andreoliwa/nitpick/pull/673/files#r1714086075
7+
# If this breaks your workflow, choose one of the other hooks below with "pass_filenames: true".
8+
29
- id: nitpick
3-
name: "nitpick fix (auto fixing files)"
4-
description: "Fix configuration files (TOML/INI/JSON/etc.) directly, according to the Nitpick style"
10+
name: "nitpick fix (all files)"
11+
description: "Fix configuration files (TOML/INI/JSON/etc.) directly, according to the Nitpick style. All files are considered by pre-commit."
512
entry: nitpick fix
13+
pass_filenames: false
614
language: python
715

8-
- id: nitpick-suggest
9-
name: "nitpick init --suggest (auto fixing files)"
10-
description: "Suggest new Nitpick styles based on the files in the project root (skipping Git ignored files)"
11-
entry: nitpick init --fix --suggest
12-
language: python
13-
# This hook should NOT be run for changed Git files, otherwise they will be considered style URLS
14-
# and will be added to [tool.nitpick]style in pyproject.toml
16+
# Same as nitpick, but with a more explicit name.
17+
- id: nitpick-fix-all
18+
name: "nitpick fix (all files)"
19+
description: "Fix configuration files (TOML/INI/JSON/etc.) directly, according to the Nitpick style. All files are considered by pre-commit."
20+
entry: nitpick fix
1521
pass_filenames: false
16-
always_run: true
22+
language: python
1723

18-
# This hook is kept for compatibility (or if one wants to be explicit): "nitpick" does the same as "nitpick-fix" now
1924
- id: nitpick-fix
20-
name: "nitpick fix (auto fixing files)"
21-
description: "Fix configuration files (TOML/INI/JSON/etc.) directly, according to the Nitpick style"
25+
name: "nitpick fix (modified files only)"
26+
description: "Fix configuration files (TOML/INI/JSON/etc.) directly, according to the Nitpick style. Only modified files are considered by pre-commit."
2227
entry: nitpick fix
28+
pass_filenames: true
29+
language: python
30+
31+
- id: nitpick-check-all
32+
name: "nitpick check (all files)"
33+
description: "Only check configuration files (TOML/INI/JSON/etc.) and print the violations, according to the Nitpick style. All files are considered by pre-commit."
34+
entry: nitpick check
35+
pass_filenames: false
2336
language: python
2437

2538
- id: nitpick-check
26-
name: "nitpick check (check files only)"
27-
description: "Only check configuration files (TOML/INI/JSON/etc.) and print the violations, according to the Nitpick style"
39+
name: "nitpick check (modified files only)"
40+
description: "Only check configuration files (TOML/INI/JSON/etc.) and print the violations, according to the Nitpick style. Only modified files are considered by pre-commit."
2841
entry: nitpick check
42+
pass_filenames: true
2943
language: python
44+
45+
- id: nitpick-suggest
46+
name: "nitpick init --suggest (auto fixing files)"
47+
description: "Suggest new Nitpick styles based on the files in the project root (skipping Git ignored files)"
48+
entry: nitpick init --fix --suggest
49+
language: python
50+
# This hook should NOT be run for changed Git files, otherwise they will be considered style URLS
51+
# and will be added to [tool.nitpick]style in pyproject.toml
52+
pass_filenames: false
53+
always_run: true

README.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,12 +401,14 @@ this to the ``.pre-commit-config.yaml`` in your repository::
401401
- repo: https://github.com/andreoliwa/nitpick
402402
rev: v0.37.0
403403
hooks:
404+
- id: nitpick-suggest
404405
- id: nitpick
405406

406-
There are 3 available hook IDs:
407+
There are a few hook IDs available:
407408

408-
- ``nitpick`` and ``nitpick-fix`` both run the ``nitpick fix`` command;
409-
- ``nitpick-check`` runs ``nitpick check``.
409+
- ``nitpick``, ``nitpick-fix`` and ``nitpick-fix-all`` run the ``nitpick fix`` command;
410+
- ``nitpick-check`` and ``nitpick-check-all`` runs ``nitpick check``;
411+
- ``nitpick-suggest`` runs ``nitpick init --fix --suggest``;
410412

411413
If you want to run Nitpick as a flake8 plugin instead::
412414

docs/quickstart.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ If you use pre-commit_ on your project, add this to the ``.pre-commit-config.yam
6969
- id: nitpick-suggest
7070
- id: nitpick
7171
72-
There are 4 available hook IDs:
72+
There are a few hook IDs available:
7373

74-
- ``nitpick`` and ``nitpick-fix`` both run the ``nitpick fix`` command;
75-
- ``nitpick-check`` runs ``nitpick check``;
74+
- ``nitpick``, ``nitpick-fix`` and ``nitpick-fix-all`` run the ``nitpick fix`` command;
75+
- ``nitpick-check`` and ``nitpick-check-all`` runs ``nitpick check``;
7676
- ``nitpick-suggest`` runs ``nitpick init --fix --suggest``;
7777

7878
If you want to run Nitpick_ as a flake8_ plugin instead:

docs/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ certifi==2025.10.5 ; python_version >= "3.10" and python_version < "4.0"
88
charset-normalizer==3.4.3 ; python_version >= "3.10" and python_version < "4.0"
99
click==8.3.0 ; python_version >= "3.10" and python_version < "4.0"
1010
colorama==0.4.6 ; python_version >= "3.10" and python_version < "4.0" and (platform_system == "Windows" or sys_platform == "win32")
11-
configupdater==3.1.1 ; python_version >= "3.10" and python_version < "4.0"
11+
configupdater==3.2 ; python_version >= "3.10" and python_version < "4.0"
1212
dictdiffer==0.9.0 ; python_version >= "3.10" and python_version < "4.0"
1313
docutils==0.21.2 ; python_version >= "3.10" and python_version < "4.0"
1414
dpath==2.2.0 ; python_version >= "3.10" and python_version < "4.0"

src/nitpick/core.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ def run(self, *partial_names: str, autofix=False) -> Iterator[Fuss]:
9696
"""
9797
Reporter.reset()
9898

99+
logger.info("File names: {}", partial_names)
99100
try:
100101
yield from chain(
101102
self.project.merge_styles(self.offline),

0 commit comments

Comments
 (0)