Stephen Lints Your Python
Project description
SLYP
Stephen Lints Your Python
Table of Contents
Hi
:wave:
I'm Stephen. I'm going to lint your Python code.
I wrote this linter because nothing else out there implemented these rules, and some of them needed CST (rather than AST), so there was no plugin framework (e.g. flake8 plugins) which I could use. I hope it helps you catch slyp-ups.
Installation
slyp
is a python package and can be run as a pre-commit hook.
On supported python versions, it should be installed with
pip install slyp
Usage
Either use it as a CLI tool:
slyp src/
Or as a pre-commit hook using the following pre-commit-config.yaml
:
- repo: https://github.com/sirosen/slyp
rev: 0.1.0
hooks:
- id: slyp
Options and Arguments
[files...]
: If passed positional arguments, slyp
will treat them as
filenames to check.
Otherwise, it will search the current directory for python files.
-v/--verbose
: Enable more verbose output
--use-git-ls
: Find files to check by doing a git ls-files
call and filtering
the results to files which appear to be python.
This is mutually exclusive with any filename arguments.
--disable CODES
: Pass a comma-delimited list of codes to turn off.
--enable CODES
: Pass a comma-delimited list of codes to turn on.
Implemented Rules
E is for "error" (you should probably change this)
W is for "warning" (you might want to change this)
Some warnings are disabled by default; enable them with --enable
.
E100
'unnecessary string concat'
x = "foo " "bar"
W101
'unparenthesized multiline string concat in keyword arg'
foo(
bar="alpha "
"beta"
)
W102
'unparenthesized multiline string concat in dict value'
{
"foo": "alpha "
"beta"
}
W103
'unparenthesized multiline string concat in collection type'
x = ( # a tuple
"alpha "
"beta",
"gamma"
)
x = { # or a set
"alpha "
"beta",
"gamma"
}
E110
'returning a variable checked as None, rather than returning None'
if x is None:
return x # should be `return None`
W200
'two AST branches have identical contents'
if x is True:
return y + 1
else:
# some comment
return y + 1
W201
disabled by default
'two AST branches have identical trivial contents'
if x is True:
return
else:
return
W202
disabled by default
'two non-adjacent AST branches have identical contents'
if x is True:
return foo(bar())
elif y is True:
return 0
elif z is True:
return 1
else:
return foo(bar())
W203
disabled by default
'two non-adjacent AST branches have identical trivial contents'
if x is True:
return None
elif y is True:
return 0
elif z is True:
return 1
else:
return None
License
slyp
is distributed under the terms of the MIT license.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file slyp-0.1.1.tar.gz
.
File metadata
- Download URL: slyp-0.1.1.tar.gz
- Upload date:
- Size: 16.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b60905313e7c8df2b4bab0db68dbdbfbdeb15f8f0f92f4e674d541194e3acc3 |
|
MD5 | 5970efdb23f47fd7f2bca33b2b34811c |
|
BLAKE2b-256 | 5f2f96a41573e5da1ec0639a302f3be8b3aebb7d08d436df6b678dd885705194 |
File details
Details for the file slyp-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: slyp-0.1.1-py3-none-any.whl
- Upload date:
- Size: 14.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1158f31e5e40e2550c8a9548c72b8881aca9b61cd7e77675ccfab220ca5d22ec |
|
MD5 | 02ebef6c16768bac393e18714b9d3ea6 |
|
BLAKE2b-256 | a1ce856c115b27d9779f6f9e15579115d7f74f768620aeb2c7dfe6e258a3f4f8 |