pydiatra (github) is yet another static checker for Python code.
Among other checks pydiatra offers number of regexp checks which are hard to find within other analyzers:
- duplicate range (e.g. re.compile("[aa]"))
- overlapping ranges (e.g. re.compile("[a-zA-z]"))
- bad escape sequences (e.g. re.compile(r"\eggs"))
- misplaced inline flags (e.g. re.compile("eggs(?i)"); Python 3.6+ only)
- combining incompatible flags
- redundant flags
- misplaced flags arguments in re.split(), re.sub(), re.subn()
And some other nice to have checks:
- invalid escape sequences in strings (Python 3.6+ only)
- hardcoded errno values (e.g. exc.errno == 2 instead of exc.errno == errno.ENOENT)
For complete list of implemented checks consult pydiatra page.
Below is list of checks supported by this plugin:
PYD001assertion always truePYD002async await used as namePYD003embedded code copyPYD004except shadows builtinPYD005bare exceptPYD006hardcoded errno valuePYD007inconsistent indentationPYD008mkstemp file descriptor leakPYD009obsolete pil importPYD010py3k compat warningPYD011regexp bad escapePYD012regexp duplicate rangePYD013regexp incompatible flagsPYD014regexp misplaced inline flagsPYD015regexp misplaced flags argumentPYD016regexp overlapping rangesPYD017regexp redundant flagPYD018regexp syntax errorPYD019regexp syntax warningPYD020string exceptionPYD021string formatting errorPYD022syntax errorPYD023syntax warningPYD024sys.hexversion comparisonPYD025sys.version comparison
This plugin uses PYD0 as violation class. Add it to flake8's select to enable.
flake8 --select PYD0 .