diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9a4271a..9e87814 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,7 +31,3 @@ jobs: run: | coverage run tests/test_bugbear.py coverage report -m - - - name: Check formatting - run: | - black --check --experimental-string-processing . diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..81197f1 --- /dev/null +++ b/.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 diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 668c891..cc841f9 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -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 ``` diff --git a/bugbear.py b/bugbear.py index efab5ab..0db4df2 100644 --- a/bugbear.py +++ b/bugbear.py @@ -10,7 +10,6 @@ from keyword import iskeyword import attr - import pycodestyle __version__ = "21.9.2" diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..9483b04 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,2 @@ +[tool.isort] +profile = "black" \ No newline at end of file diff --git a/setup.py b/setup.py index 7e1ec6a..d993e7c 100644 --- a/setup.py +++ b/setup.py @@ -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+" @@ -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"}, ) diff --git a/tests/b003.py b/tests/b003.py index a2621f0..65bd137 100644 --- a/tests/b003.py +++ b/tests/b003.py @@ -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 diff --git a/tests/b005.py b/tests/b005.py index b3bbb98..1c582e6 100644 --- a/tests/b005.py +++ b/tests/b005.py @@ -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 diff --git a/tests/b017.py b/tests/b017.py index 21836a6..6332fc4 100644 --- a/tests/b017.py +++ b/tests/b017.py @@ -2,8 +2,8 @@ Should emit: B017 - on lines 20 """ -import unittest import asyncio +import unittest CONSTANT = True diff --git a/tests/test_bugbear.py b/tests/test_bugbear.py index 0ec95c4..591812a 100644 --- a/tests/test_bugbear.py +++ b/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, @@ -29,11 +28,13 @@ B016, B017, B018, - B904, B901, B902, B903, + B904, B950, + BugBearChecker, + BugBearVisitor, ) @@ -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"