Skip to content

Instantly share code, notes, and snippets.

@bskinn
Last active September 3, 2022 02:19
Show Gist options
  • Save bskinn/ab328d0d9233586641455ac73056f946 to your computer and use it in GitHub Desktop.
Save bskinn/ab328d0d9233586641455ac73056f946 to your computer and use it in GitHub Desktop.
Python module designed to raise errors from various flake8 plugins
"""Source file with intentionally broken flake8 things.
Meant to test that various flake8 extensions are correctly installed.
Does NOT rigorously test all errors for all packages!
If you would like an addin or specific error added to this module,
please let me know on Twitter @btskinn.
Invoke with `flake8 --max-complexity 1 flake8_ext_test.py`;
this file should raise AT LEAST the following:
(core flake8)
flake8/pyflakes F401, W293
pycodestyle E501
mccabe C901
(extensions)
flake8-2020 YTT303
flake8-bandit S110
flake8-black BLK100
flake8-bugbear B006
flake8-builtins A002
flake8-comprehensions C400
flake8-docstrings D103
flake8-eradicate E800
flake8-import-order I100
flake8-pie PIE781
flake8-rst-docstrings RST212
pep8-naming N802
Copyright (c) Brian Skinn, 2019
MIT License
"""
# E501 (pycodestyle) -- Line too long
"This is a really long string. ------------------------------------------------------------------------------------------------"
# E800 (flake8-eradicate) -- Commented-out code
# F401 (flake8/pyflakes) -- Unused import
# I100 (flake8-import-order) -- Import statements are in the wrong order
import csv
import argparse
# import subprocess
import sys
# A002 (flake8-builtins) -- "list" argument shadows a builtin
# B006 (flake8-bugbear) -- No mutable defaults
# D103 (flake8-docstrings) -- Missing docstring in public function
# E121 (pycodestyle) -- Under-indented continuation line
# N802 (pep8-naming) -- Function name should be lowercase
# BLK100 (flake8-black) -- black would make changes
# PIE781 (flake8-pie) -- Assigning to a variable and returning
# YTT303 (flake8-2020) -- sys.version[:1] referenced (python10), use sys.version_info
def BadFunc(
list=[]
):
if sys.version[:1] == 3:
pass
x = 5
return x
# C400 (flake8-comprehensions) -- Unnecessary generator; rewrite as list comprehension
# C901 (mccabe) -- 'docstring_func' too complex (for max-complexity 1, at least)
# S110 (flake8-bandit) -- try/except/pass
# W293 (flake8/pyflakes) -- Blank line contains whitespace
# RST212 (flake8-rst-docstrings) -- Title underline too short
def docstring_func():
"""Provide a docstring with a RST error.
Bad Title
-----
"""
try:
raise TypeError()
except Exception:
pass
for x in list(_ for _ in range(5)):
print(x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment