summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYang Yang <y4n9squared@gmail.com>2020-04-11 16:50:22 -0400
committerPierre Sassoulas <pierre.sassoulas@gmail.com>2020-04-19 14:49:19 +0200
commit555004be6f9fbd026a273034771b36b51ee65d17 (patch)
treea0cfcc4598007e37f55fe0a832b2514fa030ba10
parent22fe050a610d0cdb24bd6790d7a6f46da9b5ed8f (diff)
downloadpylint-git-555004be6f9fbd026a273034771b36b51ee65d17.tar.gz
Fix false-negative cases for trailing-comma-tuple
The current logic for detecting trailing-comma-tuple violations fails to detect positive cases that span multiple lines because its look-back mechanism stops at the last NL or NEWLINE token when it should in fact stop at the last NEWLINE token only.
-rw-r--r--CONTRIBUTORS.txt2
-rw-r--r--pylint/checkers/refactoring.py2
-rw-r--r--tests/functional/t/trailing_comma_tuple.py14
-rw-r--r--tests/functional/t/trailing_comma_tuple.txt2
4 files changed, 18 insertions, 2 deletions
diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt
index 070e50fc9..cd15199a8 100644
--- a/CONTRIBUTORS.txt
+++ b/CONTRIBUTORS.txt
@@ -377,3 +377,5 @@ contributors:
* Slavfox: contributor
* Matthew Beckers (mattlbeck): contributor
+
+* Yang Yang: contributor
diff --git a/pylint/checkers/refactoring.py b/pylint/checkers/refactoring.py
index 75a31c7e6..5293097eb 100644
--- a/pylint/checkers/refactoring.py
+++ b/pylint/checkers/refactoring.py
@@ -95,7 +95,7 @@ def _is_trailing_comma(tokens, index):
"""Get the index denoting the start of the current line"""
for subindex, token in enumerate(reversed(tokens[:index])):
# See Lib/tokenize.py and Lib/token.py in cpython for more info
- if token.type in (tokenize.NEWLINE, tokenize.NL):
+ if token.type == tokenize.NEWLINE:
return index - subindex
return 0
diff --git a/tests/functional/t/trailing_comma_tuple.py b/tests/functional/t/trailing_comma_tuple.py
index a832ccc28..322317030 100644
--- a/tests/functional/t/trailing_comma_tuple.py
+++ b/tests/functional/t/trailing_comma_tuple.py
@@ -1,5 +1,5 @@
"""Check trailing comma one element tuples."""
-# pylint: disable=bad-whitespace, missing-docstring
+# pylint: disable=bad-whitespace, missing-docstring, bad-continuation
AAA = 1, # [trailing-comma-tuple]
BBB = "aaaa", # [trailing-comma-tuple]
CCC="aaa", # [trailing-comma-tuple]
@@ -36,3 +36,15 @@ def some_func(first, second):
def some_other_func():
yield 'hello', # [trailing-comma-tuple]
+
+GGG = ["aaa"
+], # [trailing-comma-tuple]
+
+HHH = ["aaa"
+]
+
+III = some_func(0,
+ 0), # [trailing-comma-tuple]
+
+JJJ = some_func(0,
+ 0)
diff --git a/tests/functional/t/trailing_comma_tuple.txt b/tests/functional/t/trailing_comma_tuple.txt
index bdf53a255..cbc6d1a80 100644
--- a/tests/functional/t/trailing_comma_tuple.txt
+++ b/tests/functional/t/trailing_comma_tuple.txt
@@ -5,3 +5,5 @@ trailing-comma-tuple:6::Disallow trailing comma tuple
trailing-comma-tuple:31::Disallow trailing comma tuple
trailing-comma-tuple:34::Disallow trailing comma tuple
trailing-comma-tuple:38::Disallow trailing comma tuple
+trailing-comma-tuple:41::Disallow trailing comma tuple
+trailing-comma-tuple:47::Disallow trailing comma tuple