Skip to content

Commit 71091f9

Browse files
authored
add simple pre-commit config (#205)
* add simple pre-commit config * update DEVELOPMENT.md * remove black from github workflow * set lower version boundary for hypothesmith
1 parent 98829c3 commit 71091f9

File tree

10 files changed

+38
-18
lines changed

10 files changed

+38
-18
lines changed

.github/workflows/ci.yml

-4
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,3 @@ jobs:
3131
run: |
3232
coverage run tests/test_bugbear.py
3333
coverage report -m
34-
35-
- name: Check formatting
36-
run: |
37-
black --check --experimental-string-processing .

.pre-commit-config.yaml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
ci:
2+
autofix_prs: false
3+
4+
repos:
5+
- repo: https://github.com/pycqa/isort
6+
rev: 5.10.1
7+
hooks:
8+
- id: isort
9+
10+
- repo: https://github.com/psf/black
11+
rev: 21.10b0
12+
hooks:
13+
- id: black
14+
args:
15+
- --experimental-string-processing

DEVELOPMENT.md

+9-3
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,16 @@ flake8-bugbear uses coverage to run standard unittest tests.
5050
/path/to/venv/bin/coverage run tests/test_bugbear.py
5151
```
5252

53-
## Running black
53+
## Running linter
5454

55-
We also format with black. Please ensure you `black` format your PR.
55+
We format the code with `black` and `isort`. You can run those using `pre-commit`.
5656

5757
```console
58-
/path/to/venv/bin/black .
58+
pre-commit run --all-files
59+
```
60+
61+
Or you install the pre-commit hooks to run on every commit:
62+
63+
```console
64+
pre-commit install
5965
```

bugbear.py

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from keyword import iskeyword
1111

1212
import attr
13-
1413
import pycodestyle
1514

1615
__version__ = "21.9.2"

pyproject.toml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[tool.isort]
2+
profile = "black"

setup.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import ast
44
import os
55
import re
6-
from setuptools import setup
76
import sys
87

8+
from setuptools import setup
99

1010
assert sys.version_info >= (3, 6, 0), "bugbear requires Python 3.6+"
1111

@@ -60,6 +60,8 @@
6060
"Topic :: Software Development :: Quality Assurance",
6161
],
6262
entry_points={"flake8.extension": ["B = bugbear:BugBearChecker"]},
63-
extras_require={"dev": ["coverage", "black", "hypothesis", "hypothesmith"]},
63+
extras_require={
64+
"dev": ["coverage", "hypothesis", "hypothesmith>=0.2", "pre-commit"]
65+
},
6466
project_urls={"Change Log": "https://github.com/PyCQA/flake8-bugbear#change-log"},
6567
)

tests/b003.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
B003 - on line 10
44
"""
55

6-
from os import environ
76
import os
8-
7+
from os import environ
98

109
os.environ = {}
1110
environ = {} # that's fine, assigning a new meaning to the module-level name

tests/b005.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
s.rstrip("\n\t ") # no warning
1919
s.rstrip(r"\n\t ") # warning
2020

21-
from somewhere import strip, other_type
21+
from somewhere import other_type, strip
2222

2323
strip("we") # no warning
2424
other_type().lstrip() # no warning

tests/b017.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
Should emit:
33
B017 - on lines 20
44
"""
5-
import unittest
65
import asyncio
6+
import unittest
77

88
CONSTANT = True
99

tests/test_bugbear.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import ast
22
import os
3-
from pathlib import Path
43
import site
54
import subprocess
65
import sys
76
import unittest
7+
from pathlib import Path
88

99
from hypothesis import HealthCheck, given, settings
1010
from hypothesmith import from_grammar
1111

12-
from bugbear import BugBearChecker, BugBearVisitor
1312
from bugbear import (
1413
B001,
1514
B002,
@@ -29,11 +28,13 @@
2928
B016,
3029
B017,
3130
B018,
32-
B904,
3331
B901,
3432
B902,
3533
B903,
34+
B904,
3635
B950,
36+
BugBearChecker,
37+
BugBearVisitor,
3738
)
3839

3940

@@ -64,7 +65,7 @@ def test_b003(self):
6465
filename = Path(__file__).absolute().parent / "b003.py"
6566
bbc = BugBearChecker(filename=str(filename))
6667
errors = list(bbc.run())
67-
self.assertEqual(errors, self.errors(B003(10, 0)))
68+
self.assertEqual(errors, self.errors(B003(9, 0)))
6869

6970
def test_b004(self):
7071
filename = Path(__file__).absolute().parent / "b004.py"

0 commit comments

Comments
 (0)