diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 268c22a..e210c6e 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -35,6 +35,27 @@ jobs: - name: run tests run: python setup.py test + lint: + name: pre-commit + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3.0.2 + + - uses: actions/setup-python@v4.2.0 + with: + python-version: 3.x + + - name: install pre-commit + run: pip install pre-commit + + - name: pre-commit cache + uses: actions/cache@v3.0.7 + with: + path: ~/.cache/pre-commit + key: "${{ hashFiles('.pre-commit-config.yaml') }}" + + - run: pre-commit run --all-files --show-diff-on-failure + fuzz: name: fuzz runs-on: ubuntu-latest @@ -43,7 +64,7 @@ jobs: - uses: actions/setup-python@v4.2.0 with: - python-version: "3.10" + python-version: 3.x - run: pip install . diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..121cbc4 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,19 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.3.0 + hooks: + - id: check-yaml + - id: end-of-file-fixer + - id: trailing-whitespace + + - repo: https://github.com/asottile/reorder_python_imports + rev: v3.8.2 + hooks: + - id: reorder-python-imports + args: + - --py37-plus + + - repo: https://github.com/pycqa/flake8 + rev: 5.0.4 + hooks: + - id: flake8 diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml index 02a74d3..0173835 100644 --- a/.pre-commit-hooks.yaml +++ b/.pre-commit-hooks.yaml @@ -3,4 +3,4 @@ entry: autoflake language: python 'types': [python] - require_serial: true \ No newline at end of file + require_serial: true diff --git a/autoflake.py b/autoflake.py index cce9212..a4d0120 100755 --- a/autoflake.py +++ b/autoflake.py @@ -1,5 +1,4 @@ #!/usr/bin/env python - # Copyright (C) 2012-2019 Steven Myint # # Permission is hereby granted, free of charge, to any person obtaining @@ -20,16 +19,10 @@ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - """Removes unused imports and unused variables as reported by pyflakes.""" - -from __future__ import print_function -from __future__ import unicode_literals - import ast -import difflib import collections -import distutils.sysconfig +import difflib import fnmatch import io import logging @@ -40,6 +33,7 @@ import sys import tokenize +import distutils.sysconfig import pyflakes.api import pyflakes.messages import pyflakes.reporter diff --git a/setup.py b/setup.py index a599d64..253d3e7 100755 --- a/setup.py +++ b/setup.py @@ -1,7 +1,5 @@ #!/usr/bin/env python - """Setup for autoflake.""" - import ast import setuptools diff --git a/test_autoflake.py b/test_autoflake.py index 2a37e5e..19ec482 100755 --- a/test_autoflake.py +++ b/test_autoflake.py @@ -1,10 +1,6 @@ #!/usr/bin/env python # coding: utf-8 - """Test suite for autoflake.""" - -from __future__ import unicode_literals - import contextlib import functools import io diff --git a/test_fuzz.py b/test_fuzz.py index b1aa50b..67b09fe 100755 --- a/test_fuzz.py +++ b/test_fuzz.py @@ -1,15 +1,10 @@ #!/usr/bin/env python - """Test that autoflake performs correctly on arbitrary Python files. This checks that autoflake never introduces incorrect syntax. This is done by doing a syntax check after the autoflake run. The number of Pyflakes warnings is also confirmed to always improve. """ - -from __future__ import print_function -from __future__ import unicode_literals - import os import shlex import subprocess diff --git a/test_fuzz_pypi.py b/test_fuzz_pypi.py index 22a4ce1..9cfe281 100755 --- a/test_fuzz_pypi.py +++ b/test_fuzz_pypi.py @@ -1,11 +1,5 @@ #!/usr/bin/env python - """Fuzz test against the latest packages on PyPI.""" - -from __future__ import absolute_import -from __future__ import division -from __future__ import print_function - import os import subprocess import sys