Skip to content

Commit

Permalink
Add pre-commit config; update README
Browse files Browse the repository at this point in the history
  • Loading branch information
cyyc1 committed Oct 3, 2022
1 parent 97de991 commit 2886eec
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 12 deletions.
34 changes: 34 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: debug-statements
- id: double-quote-string-fixer
- id: requirements-txt-fixer
- repo: https://github.com/asottile/setup-cfg-fmt
rev: v2.0.0
hooks:
- id: setup-cfg-fmt
- repo: https://github.com/asottile/add-trailing-comma
rev: v2.3.0
hooks:
- id: add-trailing-comma
args: [--py36-plus]
- repo: https://github.com/asottile/pyupgrade
rev: v2.38.2
hooks:
- id: pyupgrade
args: [--py37-plus]
- repo: https://github.com/pre-commit/mirrors-autopep8
rev: v1.7.0
hooks:
- id: autopep8
args: [--in-place, --max-line-length=88]
- repo: https://github.com/PyCQA/flake8
rev: 5.0.4
hooks:
- id: flake8
args: [--max-line-length=88]
24 changes: 14 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,8 @@ class MyClass(
```
You can opt out of class inheritence checks by ignoring rules `IND201` and `IND202`.

## Rationale

When we only indent by 4 spaces in function definitions, it is difficult to visually distinguish function arguments with the function name and the function body. This reduces readability.

It is similar for base classes in class definitions, but it's less of an issue than function definitions.
### _Notes_

## Interaction with other style checkers and formatters

* [`black`](https://github.com/psf/black)-formatted code will cause a style violation here, because `black` authors [explicitly opted for the 4-space indentation and do not plan to change it](https://github.com/psf/black/issues/1178#issuecomment-614050678)
* The style enforced in this plugin contradicts with rule [WPS318](https://wemake-python-styleguide.readthedocs.io/en/latest/pages/usage/violations/consistency.html#wemake_python_styleguide.violations.consistency.ExtraIndentationViolation) enforced by [wemake-python-styleguide](https://github.com/wemake-services/wemake-python-styleguide) ("WPS")
- But WPS is configurable so you can always opt out of WPS318
* This plugin does not check trailing commas, because [flake8-commas](https://github.com/PyCQA/flake8-commas) already does it
* This plugin does not forbid grouping arguments (see example below), because [WPS317](https://wemake-python-styleguide.readthedocs.io/en/latest/pages/usage/violations/consistency.html#wemake_python_styleguide.violations.consistency.ParametersIndentationViolation) can enforce it
```python
Expand All @@ -117,3 +108,16 @@ def some_func(
):
pass
```

## Rationale

When we only indent by 4 spaces in function definitions, it is difficult to visually distinguish function arguments with the function name and the function body. This reduces readability.

It is similar for base classes in class definitions, but it's less of an issue than function definitions.

## Interaction with other style checkers and formatters

* By design, [`black`](https://github.com/psf/black)-formatted code will cause a style violation here, because `black` authors [explicitly opted for the 4-space indentation and do not plan to change it](https://github.com/psf/black/issues/1178#issuecomment-614050678)
* The style enforced in this plugin contradicts with rule [WPS318](https://wemake-python-styleguide.readthedocs.io/en/latest/pages/usage/violations/consistency.html#wemake_python_styleguide.violations.consistency.ExtraIndentationViolation) enforced by [wemake-python-styleguide](https://github.com/wemake-services/wemake-python-styleguide) ("WPS")
- But WPS is configurable, so you can always opt out of WPS318
* You can use [py-def-indent-formatter](https://github.com/cyyc1/py-def-indent-formatter) right after `black` to make your code satisfy the style requirements of this plugin
2 changes: 0 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ description = A flake8 plugin that enforces 8-space indentation in function/clas
long_description = file: README.md
long_description_content_type = text/markdown
url = https://github.com/cyyc1/flake8-indent-in-def
author =
author_email =
license = MIT
license_file = LICENSE
classifiers =
Expand Down

0 comments on commit 2886eec

Please sign in to comment.