Skip to content

Commit

Permalink
feat: default pre-commit hook now runs "nitpick fix"
Browse files Browse the repository at this point in the history
  • Loading branch information
andreoliwa committed Dec 26, 2021
1 parent 36f4065 commit cb4c242
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 9 deletions.
5 changes: 4 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ repos:
- repo: local
hooks:
# Run nitpick also with tox, because local repos don't seem to work well with https://pre-commit.ci/
# Nitpick doesn't run on pre-commit.ci because it needs HTTP requests to get the default style from GitHub
# pre-commit.ci intentionally does not allow network access at runtime for free tier as this is easy to abuse (miners, etc.)
# https://github.com/pre-commit-ci/issues/issues/47
- id: local-nitpick
name: "nitpick fix (modify files directly, local hook)"
name: "nitpick fix (auto fixing files, local hook)"
entry: poetry run nitpick fix
language: system
always_run: true
Expand Down
11 changes: 5 additions & 6 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
# https://pre-commit.com/#creating-new-hooks
- id: nitpick
name: "nitpick flake8 plugin (check files only)"
description: "Run as a flake8 plugin and only check configuration files (TOML/INI/JSON/etc.), according to the Nitpick style"
entry: flake8 --select=NIP
name: "nitpick fix (auto fixing files)"
description: "Fix configuration files (TOML/INI/JSON/etc.) directly, according to the Nitpick style"
entry: nitpick fix
language: python
types: [python]
always_run: true
stages: [commit]

# This hook is kept for compatibility (or if one wants to be explicit): "nitpick" does the same as "nitpick-fix" now
- id: nitpick-fix
name: "nitpick fix (modify files directly)"
name: "nitpick fix (auto fixing files)"
description: "Fix configuration files (TOML/INI/JSON/etc.) directly, according to the Nitpick style"
entry: nitpick fix
language: python
Expand Down
20 changes: 18 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -229,16 +229,32 @@ You can use it as a template to configure your own style.
Run as a pre-commit hook
~~~~~~~~~~~~~~~~~~~~~~~~

If you use `pre-commit <https://pre-commit.com/>`__ on your project, add
If you use `pre-commit <https://pre-commit.com/>`_ on your project, add
this to the ``.pre-commit-config.yaml`` in your repository::

.. code-block:: yaml
repos:
- repo: https://github.com/andreoliwa/nitpick
rev: v0.29.0
hooks:
- id: nitpick
There are 3 available hook IDs: ``nitpick``, ``nitpick-fix``, ``nitpick-check``.
There are 3 available hook IDs:

- ``nitpick`` and ``nitpick-fix`` both run the ``nitpick fix`` command;
- ``nitpick-check`` runs ``nitpick check``.

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

.. code-block:: yaml
repos:
- repo: https://github.com/PyCQA/flake8
rev: 4.0.1
hooks:
- id: flake8
additional_dependencies: [nitpick]
More information
----------------
Expand Down
1 change: 1 addition & 0 deletions docs/generate_rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ def write_config() -> int:

def write_readme(file_types: Set[FileType], divider: str) -> int:
"""Write the README."""
# TODO: quickstart.rst has some parts of README.rst as a copy/paste/change
rows: List[Tuple[str, ...]] = [("File type", "``nitpick check``", "``nitpick fix``")]
for file_type in sorted(file_types):
rows.append(file_type.row)
Expand Down
16 changes: 16 additions & 0 deletions docs/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,22 @@ If you use pre-commit_ on your project, add this to the ``.pre-commit-config.yam
hooks:
- id: nitpick
There are 3 available hook IDs:

- ``nitpick`` and ``nitpick-fix`` both run the ``nitpick fix`` command;
- ``nitpick-check`` runs ``nitpick check``.

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

.. code-block:: yaml
repos:
- repo: https://github.com/PyCQA/flake8
rev: 4.0.1
hooks:
- id: flake8
additional_dependencies: [nitpick]
To install the ``pre-commit`` and ``commit-msg`` Git hooks:

.. code-block:: shell
Expand Down

0 comments on commit cb4c242

Please sign in to comment.