summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryce Guinta <bryce.guinta@protonmail.com>2018-07-24 00:28:13 -0600
committerClaudiu Popa <pcmanticore@gmail.com>2018-07-24 08:28:13 +0200
commit9f0ef30b13500ecba6f1b9f5c71981df976e7e6e (patch)
tree07fcd6caf262e2daf77fa77b8bd821e1f4f9f427
parent2b24ec063a5355648d286633e37f084ced4f1604 (diff)
downloadpylint-git-9f0ef30b13500ecba6f1b9f5c71981df976e7e6e.tar.gz
Fix not being able to disable certain messages on the last line (#2342)
Allow messages to be disabled that occur in ``file_state._msgs_state`` after the end of the ast (but not of the tokens) Close #2278
-rw-r--r--ChangeLog5
-rw-r--r--pylint/test/unittest_checker_format.py31
-rw-r--r--pylint/utils.py3
3 files changed, 38 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 519fac8dc..06864026e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -37,6 +37,11 @@ Release date: |TBA|
Close #2281
+ * Fix not being able to disable certain messages on the last line through
+ the global disable option
+
+ Close #2278
+
* Don't emit `useless-return` when we have a single statement that is the return itself
We still want to be explicit when a function is supposed to return
diff --git a/pylint/test/unittest_checker_format.py b/pylint/test/unittest_checker_format.py
index 6eba23a22..dfa8ed19d 100644
--- a/pylint/test/unittest_checker_format.py
+++ b/pylint/test/unittest_checker_format.py
@@ -25,10 +25,15 @@
from __future__ import unicode_literals
import tokenize
+import os
+import tempfile
import astroid
from pylint.checkers.format import *
+from pylint import reporters
+from pylint import lint
+
from pylint.testutils import (
CheckerTestCase, Message, set_config, _tokenize_str,
@@ -381,3 +386,29 @@ class TestCheckSpace(CheckerTestCase):
encoding_token = tokenize.TokenInfo(tokenize.ENCODING, "utf-8", (0, 0), (0, 0), '')
tokens = [encoding_token] + _tokenize_str('if (\n None):\n pass\n')
self.checker.process_tokens(tokens)
+
+
+def test_disable_global_option_end_of_line():
+ """
+ Test for issue with disabling tokenizer messages
+ that extend beyond the scope of the ast tokens
+ """
+ file_ = tempfile.NamedTemporaryFile('w', delete=False)
+ with file_:
+ file_.write("""
+mylist = [
+ None
+ ]
+ """)
+ try:
+ linter = lint.PyLinter()
+ checker = FormatChecker(linter)
+ linter.register_checker(checker)
+ args = linter.load_command_line_configuration(
+ [file_.name, '-d' ,'bad-continuation'])
+ myreporter = reporters.CollectingReporter()
+ linter.set_reporter(myreporter)
+ linter.check(args)
+ assert not myreporter.messages
+ finally:
+ os.remove(file_.name)
diff --git a/pylint/utils.py b/pylint/utils.py
index 441bd69e2..d5de04572 100644
--- a/pylint/utils.py
+++ b/pylint/utils.py
@@ -397,7 +397,8 @@ class MessagesHandlerMixIn:
# This happens for example with a commented line at the end of a module.
max_line_number = self.file_state.get_effective_max_line_number()
if (max_line_number and line > max_line_number):
- return msgid not in self.file_state._raw_module_msgs_state
+ fallback = msgid not in self.file_state._raw_module_msgs_state
+ return self._msgs_state.get(msgid, fallback)
return self._msgs_state.get(msgid, True)
def add_message(self, msg_descr, line=None, node=None, args=None, confidence=UNDEFINED,