Flake8 lint for trailing commas.
.. image:: https://unmaintained.tech/badge.svg :target: https://unmaintained.tech :alt: No Maintenance Intended
Note: Black <https://pypi.org/project/black/>
, the uncompromising Python code
formatter, or add-trailing-comma <https://github.com/asottile/add-trailing-comma>
can do all this comma insertion automatically. We recommend you use one of those tools
instead.
If you are using flake8 it's as easy as:
.. code:: shell
pip install flake8-commas
Now you can avoid those annoying merge conflicts on dictionary and list diffs.
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 | +------+-----------------------------------------+
.. code:: Python
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.
Issue #67 <https://github.com/PyCQA/flake8-commas/issues/67>
_)Issue #63 <https://github.com/PyCQA/flake8-commas/pull/63>
)
(Issue #69 <https://github.com/PyCQA/flake8-commas/pull/69>
)Issue #45 <https://github.com/PyCQA/flake8-commas/issue/45>
)Issue #51 <https://github.com/PyCQA/flake8-commas/pull/51>
_)Chris AtLee <https://github.com/catlee>
_ and
Arkadiusz Adamski <https://github.com/ar4s/flake8_tuple>
_
(PR #52 <https://github.com/PyCQA/flake8-commas/pull/52>
_)Issue #48 <https://github.com/flake8-commas/flake8-commas/pull/48>
_)Issue #47 <https://github.com/flake8-commas/flake8-commas/pull/47>
_)Issue #46 <https://github.com/flake8-commas/flake8-commas/pull/46>
_)Issue #42 <https://github.com/flake8-commas/flake8-commas/pull/42>
_)Issue #41 <https://github.com/flake8-commas/flake8-commas/pull/41>
_)Issue #35 <https://github.com/flake8-commas/flake8-commas/issues/35>
_)Issue #39 <https://github.com/flake8-commas/flake8-commas/pull/39>
_)Issue #37 <https://github.com/flake8-commas/flake8-commas/pull/37>
_)Issue #20 <https://github.com/flake8-commas/flake8-commas/issue/20>
_)issue9232 <https://bugs.python.org/issue9232>
_
trailing commas.
(Issue #33 <https://github.com/flake8-commas/flake8-commas/pull/33>
_)Issue #30 <https://github.com/flake8-commas/flake8-commas/issue/30>
_)Issue #18 <https://github.com/flake8-commas/flake8-commas/issue/18>
_)Issue #17 <https://github.com/flake8-commas/flake8-commas/issue/17>
_)Issue #26 <https://github.com/flake8-commas/flake8-commas/issue/26>
_)*args
should not require a trailing comma.
(Issue #27 <https://github.com/flake8-commas/flake8-commas/issue/27>
_)