Skip to content
Flake8 extension for enforcing trailing commas in python
Python
Branch: master
Clone or download
graingert Merge pull request #56 from shaleh/patch-1
Add some examples to the README.
Latest commit 32647a9 Jun 17, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
flake8_commas Improve error message Mar 17, 2018
test add test for return bare tuple Mar 19, 2018
.gitignore
.travis.yml remove EOL Python 3.3 Jan 2, 2018
CHANGES.rst Back to development: 2.0.1 Mar 19, 2018
FLAKE8_TRAILING_COMMAS_CHANGES.rst rename back to flake8-commas Jan 13, 2017
LICENSE rename back to flake8-commas Jan 13, 2017
MANIFEST.in add changelog Jan 13, 2017
README.rst Add some examples. Feb 28, 2019
setup.cfg remove __about__ nonsense Jan 13, 2017
setup.py Back to development: 2.0.1 Mar 19, 2018
tox.ini remove EOL Python 3.3 Jan 2, 2018
travis.yml test with 3.6 Jan 13, 2017

README.rst

Flake8 Extension to enforce better comma placement.

Usage

If you are using flake8 it's as easy as:

pip install flake8-commas

Now you can avoid those annoying merge conflicts on dictionary and list diffs.

Errors

Different versions of python require commas in different places. Ignore the errors for languages you don't use in your flake8 config:

Code message
C812 missing trailing comma
C813 missing trailing comma in Python 3
C814 missing trailing comma in Python 2
C815 missing trailing comma in Python 3.5+
C816 missing trailing comma in Python 3.6+
C818 trailing comma on bare tuple prohibited
C819 trailing comma prohibited

Examples

lookup_table = {
    'key1': 'value',
    'key2': 'something'  # <-- missing a trailing comma
}

json_data = json.dumps({
    "key": "value",
}),                      # <-- incorrect trailing comma. json_data is now a tuple. Likely by accident.
You can’t perform that action at this time.