Trailing comma on select or ignore list changes behaviour
Related to https://gitlab.com/pycqa/flake8/issues/329
Please describe how you installed Flake8
Example:
pip3 install flake8 flake8-docstring
Please provide the exact, unmodified output of flake8 --bug-report
$ flake8 --bug-report
{
"dependencies": [
{
"dependency": "setuptools",
"version": "28.8.0"
}
],
"platform": {
"python_implementation": "CPython",
"python_version": "3.6.0",
"system": "Darwin"
},
"plugins": [
{
"plugin": "flake8-docstrings",
"version": "1.1.0, pydocstyle: 2.0.0"
},
{
"plugin": "flake8_commas._base",
"version": "0.4.3"
},
{
"plugin": "mccabe",
"version": "0.6.1"
},
{
"plugin": "pycodestyle",
"version": "2.3.1"
},
{
"plugin": "pyflakes",
"version": "1.5.0"
}
],
"version": "3.3.0"
}
Please describe the problem or feature
Including a trailing comma on the ignore list can dramatically change how it is interpreted.
In line with Python lists etc, this should have no impact.
If this is a bug report, please explain with examples (and example code) what you expected to happen and what actually happened.
Sample test file:
$ python3 nasty.py
42
$ python nasty.py
42
$ cat nasty.py
"""Test case for flake8 with some deliberate bad style."""
#bad spacing, and docstring issues too
def add(x,y):
''' this is a pointless function which will add two variables together
withouth making any assumptions about their type '''
return x+y
print(add(40, 2))
Compare:
$ flake8 nasty.py --isolated --select "E2,D3"
nasty.py:4:1: E265 block comment should start with '# '
nasty.py:5:1: D300 Use """triple double quotes"""
nasty.py:5:10: E231 missing whitespace after ','
vs the problematic output:
$ flake8 nasty.py --isolated --select "E2,D3,"
nasty.py:4:1: E265 block comment should start with '# '
nasty.py:5:1: D205 1 blank line required between summary line and description
nasty.py:5:1: D209 Multi-line docstring closing quotes should be on a separate line
nasty.py:5:1: D210 No whitespaces allowed surrounding docstring text
nasty.py:5:1: D300 Use """triple double quotes"""
nasty.py:5:1: D400 First line should end with a period
nasty.py:5:1: D401 First line should be in imperative mood; try rephrasing
nasty.py:5:1: D403 First word of the first line should be properly capitalized
nasty.py:5:10: E231 missing whitespace after ','
This occurs also when using configuration files where the problem is more likely to occur:
$ cat flake8_no_trailing
[flake8]
select=
E2,
D3
scottishdumpling:tmp pc40583$ flake8 nasty.py --config flake8_no_trailing
nasty.py:4:1: E265 block comment should start with '# '
nasty.py:5:1: D300 Use """triple double quotes"""
nasty.py:5:10: E231 missing whitespace after ','
vs:
$ cat flake8_trailing_comma
[flake8]
select=
E2,
D3,
scottishdumpling:tmp pc40583$ flake8 nasty.py --config flake8_trailing_comma
nasty.py:4:1: E265 block comment should start with '# '
nasty.py:5:1: D205 1 blank line required between summary line and description
nasty.py:5:1: D209 Multi-line docstring closing quotes should be on a separate line
nasty.py:5:1: D210 No whitespaces allowed surrounding docstring text
nasty.py:5:1: D300 Use """triple double quotes"""
nasty.py:5:1: D400 First line should end with a period
nasty.py:5:1: D401 First line should be in imperative mood; try rephrasing
nasty.py:5:1: D403 First word of the first line should be properly capitalized
nasty.py:5:10: E231 missing whitespace after ','
When using multiple lines for the select or ignore list as per http://flake8.pycqa.org/en/latest/user/configuration.html#configuration to facilitate merges etc it would be ideal to support the trailing comma.