Skip to content

Commit

Permalink
add simple pre-commit config (#205)
Browse files Browse the repository at this point in the history
* add simple pre-commit config

* update DEVELOPMENT.md

* remove black from github workflow

* set lower version boundary for hypothesmith
  • Loading branch information
finswimmer committed Nov 27, 2021
1 parent 98829c3 commit 71091f9
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 18 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/ci.yml
Expand Up @@ -31,7 +31,3 @@ jobs:
run: |
coverage run tests/test_bugbear.py
coverage report -m
- name: Check formatting
run: |
black --check --experimental-string-processing .
15 changes: 15 additions & 0 deletions .pre-commit-config.yaml
@@ -0,0 +1,15 @@
ci:
autofix_prs: false

repos:
- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort

- repo: https://github.com/psf/black
rev: 21.10b0
hooks:
- id: black
args:
- --experimental-string-processing
12 changes: 9 additions & 3 deletions DEVELOPMENT.md
Expand Up @@ -50,10 +50,16 @@ flake8-bugbear uses coverage to run standard unittest tests.
/path/to/venv/bin/coverage run tests/test_bugbear.py
```

## Running black
## Running linter

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

```console
/path/to/venv/bin/black .
pre-commit run --all-files
```

Or you install the pre-commit hooks to run on every commit:

```console
pre-commit install
```
1 change: 0 additions & 1 deletion bugbear.py
Expand Up @@ -10,7 +10,6 @@
from keyword import iskeyword

import attr

import pycodestyle

__version__ = "21.9.2"
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
@@ -0,0 +1,2 @@
[tool.isort]
profile = "black"
6 changes: 4 additions & 2 deletions setup.py
Expand Up @@ -3,9 +3,9 @@
import ast
import os
import re
from setuptools import setup
import sys

from setuptools import setup

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

Expand Down Expand Up @@ -60,6 +60,8 @@
"Topic :: Software Development :: Quality Assurance",
],
entry_points={"flake8.extension": ["B = bugbear:BugBearChecker"]},
extras_require={"dev": ["coverage", "black", "hypothesis", "hypothesmith"]},
extras_require={
"dev": ["coverage", "hypothesis", "hypothesmith>=0.2", "pre-commit"]
},
project_urls={"Change Log": "https://github.com/PyCQA/flake8-bugbear#change-log"},
)
3 changes: 1 addition & 2 deletions tests/b003.py
Expand Up @@ -3,9 +3,8 @@
B003 - on line 10
"""

from os import environ
import os

from os import environ

os.environ = {}
environ = {} # that's fine, assigning a new meaning to the module-level name
Expand Down
2 changes: 1 addition & 1 deletion tests/b005.py
Expand Up @@ -18,7 +18,7 @@
s.rstrip("\n\t ") # no warning
s.rstrip(r"\n\t ") # warning

from somewhere import strip, other_type
from somewhere import other_type, strip

strip("we") # no warning
other_type().lstrip() # no warning
Expand Down
2 changes: 1 addition & 1 deletion tests/b017.py
Expand Up @@ -2,8 +2,8 @@
Should emit:
B017 - on lines 20
"""
import unittest
import asyncio
import unittest

CONSTANT = True

Expand Down
9 changes: 5 additions & 4 deletions tests/test_bugbear.py
@@ -1,15 +1,14 @@
import ast
import os
from pathlib import Path
import site
import subprocess
import sys
import unittest
from pathlib import Path

from hypothesis import HealthCheck, given, settings
from hypothesmith import from_grammar

from bugbear import BugBearChecker, BugBearVisitor
from bugbear import (
B001,
B002,
Expand All @@ -29,11 +28,13 @@
B016,
B017,
B018,
B904,
B901,
B902,
B903,
B904,
B950,
BugBearChecker,
BugBearVisitor,
)


Expand Down Expand Up @@ -64,7 +65,7 @@ def test_b003(self):
filename = Path(__file__).absolute().parent / "b003.py"
bbc = BugBearChecker(filename=str(filename))
errors = list(bbc.run())
self.assertEqual(errors, self.errors(B003(10, 0)))
self.assertEqual(errors, self.errors(B003(9, 0)))

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

0 comments on commit 71091f9

Please sign in to comment.