Skip to content

Commit

Permalink
DEV: Add Import Sorting & Extra Flake8 Rules (#141)
Browse files Browse the repository at this point in the history
Add many extra checks to pre-commit, some of which are the same as those
used by deepsource. Proposed new additions to pre-commit:

- isort: Sort and group imports (stdlibrary, 3rd party, current package)
- flake8-isort: Check import ordering
- flake8-comprehensions: Suggestions for better comprehensions
- flake8-mutable: Check for mutable default arguments
- flake8-use-fstring: Use of f-strings vs old style format strings
- flake8-simplify: Suggestions to simplify code
- pep8-naming: Check PEP8 class naming
- flake8-eradicate: Find dead/commented out code
- flake8-builtins: Check for built-ins being used as variables
- flake8-cognitive-complexity: Check max function complexity
- flake8-expression-complexity: Check max expression complexity
- flake8-return: Check return statements (no redundant assignments)
- flake8-spellcheck: Spelling checker (comments only)
- flake8-pytest-style: Check against pytest style guide
- flake8-fixme: Check for FIXME, TODO, and XXX left in comments
- flake8-sql: Check SQL statement style
- nitpick: Check that black, flake8, isort have compaible options
- flake8-logging-format: Validate (lack of) logging format strings
- flake8-pie: Misc. linting rules

Co-authored by: @John-P
  • Loading branch information
John-P committed Sep 10, 2021
1 parent 0a26f42 commit 662a143
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
28 changes: 26 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,35 @@
repos:
- repo: https://github.com/pycqa/isort
rev: 5.8.0
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: 20.8b1 # Replace by any tag/version: https://github.com/psf/black/tags
rev: 20.8b1 # Replace with any tag/version: https://github.com/psf/black/tags
hooks:
- id: black
language_version: python3 # Should be a command that runs python3.7+
- repo: https://gitlab.com/pycqa/flake8
rev: 3.7.9
hooks:
- id: flake8
additional_dependencies: [flake8-bugbear]
additional_dependencies: [
flake8-bugbear, # Detect potential bugs
flake8-isort, # Check import ordering
flake8-comprehensions, # Suggestions for better list/set/dict comprehensions
flake8-mutable, # Check for mutable default arguments
flake8-use-fstring, # Encourages use of f-strings vs old style
flake8-simplify, # Suggestions to simplify code
pep8-naming, # Check PEP8 class naming
flake8-eradicate, # Find dead/commented out code
flake8-builtins, # Check for built-ins being used as variables
flake8-cognitive-complexity, # Check max function complexity
flake8-expression-complexity, # Check max expression complexity
flake8-return, # Check return statements
flake8-spellcheck, # Spelling checker
flake8-pytest-style, # Check against pytest style guide
flake8-fixme, # Check for FIXME, TODO, and XXX left in comments
flake8-sql, # Check SQL statement style
nitpick, # Check that black, flake8, isort have compaible options
flake8-logging-format, # Validate (lack of) logging format strings
flake8-pie, # Misc. linting rules
]
10 changes: 10 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,20 @@ universal = 1
exclude = docs, *__init__*
max-line-length = 88
extend-ignore = E203 # For black compatibility
spellcheck-targets = comments
dictionaries = en_US,python,technical
max-cognitive-complexity = 7
max-expression-complexity = 7

[aliases]
test = pytest

[tool:pytest]
collect_ignore = ['setup.py']

[isort]
profile = black
multi_line_output = 3
skip_gitignore = True
line_length = 88
filter_files = True
2 changes: 2 additions & 0 deletions whitelist.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Spell checking whitelist for flake8-spellcheck
pyright

0 comments on commit 662a143

Please sign in to comment.