Skip to content

Commit

Permalink
Use pre-commit for linting
Browse files Browse the repository at this point in the history
Also run it in CI. Not adding pyupgrade here, as this will likely be
done in #111.

Aside from reorder-python-imports, I'm not adding any formatters (even
though I truly like black and add-trailing-comma).
  • Loading branch information
fsouza committed Aug 23, 2022
1 parent e9e0825 commit 49d4ec4
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 27 deletions.
23 changes: 22 additions & 1 deletion .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -43,7 +64,7 @@ jobs:

- uses: actions/setup-python@v4.2.0
with:
python-version: "3.10"
python-version: 3.x

- run: pip install .

Expand Down
19 changes: 19 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
entry: autoflake
language: python
'types': [python]
require_serial: true
require_serial: true
10 changes: 2 additions & 8 deletions autoflake.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -40,6 +33,7 @@
import sys
import tokenize

import distutils.sysconfig
import pyflakes.api
import pyflakes.messages
import pyflakes.reporter
Expand Down
2 changes: 0 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/usr/bin/env python

"""Setup for autoflake."""

import ast

import setuptools
Expand Down
4 changes: 0 additions & 4 deletions test_autoflake.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 0 additions & 5 deletions test_fuzz.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 0 additions & 6 deletions test_fuzz_pypi.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 49d4ec4

Please sign in to comment.