Skip to content

Commit

Permalink
feat(pre-commit): add nitpick hooks to use on .pre-commit-config.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
andreoliwa committed Jun 19, 2019
1 parent e5e1b7f commit 92c13ae
Show file tree
Hide file tree
Showing 13 changed files with 270 additions and 48 deletions.
23 changes: 13 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ repos:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/asottile/pyupgrade
rev: v1.18.0
rev: v1.19.0
hooks:
- id: pyupgrade
- repo: https://github.com/ambv/black
- repo: https://github.com/python/black
rev: 19.3b0
hooks:
- id: black
args: [--safe, --quiet]
- repo: https://github.com/asottile/blacken-docs
rev: v1.0.0
rev: v1.0.0-1
hooks:
- id: blacken-docs
additional_dependencies: [black==19.3b0]
Expand All @@ -39,13 +39,6 @@ repos:
- id: python-no-eval
- id: python-no-log-warn
- id: rst-backticks
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.2.3
hooks:
- id: flake8
additional_dependencies: [flake8-blind-except, flake8-bugbear, flake8-comprehensions,
flake8-debugger, flake8-docstrings, flake8-isort, flake8-mypy, flake8-polyfill,
flake8-pytest, flake8-quotes, yesqa]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.701
hooks:
Expand All @@ -54,3 +47,13 @@ repos:
rev: 0.6.0
hooks:
- id: bashate
- repo: local
hooks:
# Run flake8 locally with nitpick and all the plugins configured in pyproject.toml
- id: nitpick-local
name: Nitpick (Local)
description: Check only nitpick errors (NIP) and ignore other flake8 plugins
entry: flake8
language: python
types: [python]
always_run: true
14 changes: 14 additions & 0 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
- id: nitpick-all
name: Nitpick (All)
description: Run nitpick together with several other flake8 plugins (check pyproject.toml)
entry: flake8
language: python
types: [python]
always_run: true
- id: nitpick-only
name: Nitpick (Only)
description: Check only nitpick errors (NIP) and ignore other flake8 plugins
entry: flake8 --select=NIP
language: python
types: [python]
always_run: true
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,4 @@ help:
dev:
clear
pre-commit run --all-files
flake8
pytest
28 changes: 22 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[![Test Coverage](https://api.codeclimate.com/v1/badges/61e0cdc48e24e76a0460/test_coverage)](https://codeclimate.com/github/andreoliwa/nitpick/test_coverage)
[![Supported Python versions](https://img.shields.io/pypi/pyversions/nitpick.svg)](https://pypi.org/project/nitpick/)
[![Project License](https://img.shields.io/pypi/l/nitpick.svg)](https://pypi.org/project/nitpick/)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/ambv/black)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/python/black)
[![Dependabot Status](https://api.dependabot.com/badges/status?host=github&repo=andreoliwa/nitpick)](https://dependabot.com)
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)

Expand All @@ -30,12 +30,28 @@ A "nitpick code style" is a [TOML](https://github.com/toml-lang/toml) file with

## Installation and usage

Simply install the package (in a virtualenv or globally, wherever) and run `flake8`:
To try the package, simply install it (in a virtualenv or globally, wherever) and run `flake8`:

$ pip install -U nitpick
$ flake8

You will see warnings if your project configuration is different than [the default style file](https://raw.githubusercontent.com/andreoliwa/nitpick//0.15.0/nitpick-style.toml/nitpick-style.toml).
You will see warnings if your project configuration is different than [the default style file](https://raw.githubusercontent.com/andreoliwa/nitpick/0.15.0/nitpick-style.toml/nitpick-style.toml).

### As a pre-commit hook

If you use [pre-commit](https://pre-commit.com/) on your project, add this to the `.pre-commit-config.yaml` in your repository:

repos:
- repo: https://github.com/andreoliwa/nitpick
rev: v0.15.0
hooks:
# Run nitpick and several other flake8 plugins
- id: nitpick-all
# Check only nitpick errors, ignore other flake8 plugins
- id: nitpick-only

Use one hook or the other (`nitpick-all` **or** `nitpick-only`), not both.
To check all the other flake8 plugins that are installed with `nitpick`, see the [pyproject.toml](pyproject.toml).

## Style file

Expand All @@ -44,7 +60,7 @@ You will see warnings if your project configuration is different than [the defau
Change your project config on `pyproject.toml`, and configure your own style like this:

[tool.nitpick]
style = "https://raw.githubusercontent.com/andreoliwa/nitpick//0.15.0/nitpick-style.toml/nitpick-style.toml"
style = "https://raw.githubusercontent.com/andreoliwa/nitpick/0.15.0/nitpick-style.toml/nitpick-style.toml"

You can set `style` with any local file or URL. E.g.: you can use the raw URL of a [GitHub Gist](https://gist.github.com).

Expand All @@ -62,15 +78,15 @@ If a key is defined in more than one file, the value from the last file will pre

2. Any `nitpick-style.toml` file found in the current directory (the one in which `flake8` runs from) or above.

3. If no style is found, then [the default style file from GitHub](https://raw.githubusercontent.com/andreoliwa/nitpick//0.15.0/nitpick-style.toml/nitpick-style.toml) is used.
3. If no style is found, then [the default style file from GitHub](https://raw.githubusercontent.com/andreoliwa/nitpick/0.15.0/nitpick-style.toml/nitpick-style.toml) is used.

### Style file syntax

A style file contains basically the configuration options you want to enforce in all your projects.

They are just the config to the tool, prefixed with the name of the config file.

E.g.: To [configure the black formatter](https://github.com/ambv/black#configuration-format) with a line length of 120, you use this in your `pyproject.toml`:
E.g.: To [configure the black formatter](https://github.com/python/black#configuration-format) with a line length of 120, you use this in your `pyproject.toml`:

[tool.black]
line-length = 120
Expand Down
Loading

0 comments on commit 92c13ae

Please sign in to comment.