summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTrevor Bekolay <tbekolay@gmail.com>2019-05-14 20:17:08 -0400
committerClaudiu Popa <pcmanticore@gmail.com>2019-09-12 14:23:19 +0200
commit20e432ebc0c7f760ca80e3700e64c00afb56236e (patch)
treedf69ebb3063eb96793cf80b683b88ff2e3f703a0
parentb758b549a702bf4ed5ff51178eea16a97bab702e (diff)
downloadpylint-git-20e432ebc0c7f760ca80e3700e64c00afb56236e.tar.gz
Add a command to list enabled/disabled messages
When enabling/disabling several messages and groups in a config file, it can be unclear which messages are actually enabled and which are disabled. This new command produces the final resolved lists of enabled/disabled messages, sorted by symbol but with the ID provided for use with `--help-msg`. This commit includes a test, documentation, and adding myself to the contributors list, as this is my first contribution.
-rw-r--r--CONTRIBUTORS.txt3
-rw-r--r--ChangeLog3
-rw-r--r--doc/user_guide/run.rst2
-rw-r--r--doc/whatsnew/2.4.rst13
-rw-r--r--pylint/lint.py36
-rw-r--r--tests/unittest_lint.py26
6 files changed, 77 insertions, 6 deletions
diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt
index 4279fbaec..b46b2d0e8 100644
--- a/CONTRIBUTORS.txt
+++ b/CONTRIBUTORS.txt
@@ -326,3 +326,6 @@ contributors:
* Robert Schweizer: contributor
* Hugo van Kemenade: contributor
+
+* Trevor Bekolay: contributor
+ - Added --list-msgs-enabled command
diff --git a/ChangeLog b/ChangeLog
index 5f16e8f7e..432dd90be 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -9,7 +9,7 @@ Release date: TBA
* Added a new check, ``consider-using-sys-exit``
- This check is emitted when we detect that a quit() or exit() is invoked
+ This check is emitted when we detect that a quit() or exit() is invoked
instead of sys.exit(), which is the preferred way of exiting in program.
Close #2925
@@ -263,6 +263,7 @@ must rename the associated identification.
Closes #2395
+* Added ``--list-msgs-enabled`` command to list all enabled and disabled messages given the current RC file and command line arguments.
What's New in Pylint 2.3.0?
===========================
diff --git a/doc/user_guide/run.rst b/doc/user_guide/run.rst
index ca7e3f16b..338a07064 100644
--- a/doc/user_guide/run.rst
+++ b/doc/user_guide/run.rst
@@ -119,6 +119,8 @@ Other useful global options include:
--output-format=<format> Select output format (text, json, custom).
--msg-template=<template> Modify text output message template.
--list-msgs Generate pylint's messages.
+--list-msgs-enabled Display a list of what messages are enabled and
+ disabled with the given configuration.
--full-documentation Generate pylint's full documentation, in reST
format.
diff --git a/doc/whatsnew/2.4.rst b/doc/whatsnew/2.4.rst
index 15fe03361..e5e5d86af 100644
--- a/doc/whatsnew/2.4.rst
+++ b/doc/whatsnew/2.4.rst
@@ -15,11 +15,11 @@ New checkers
* Added a new check, ``consider-using-sys-exit``
- This check is emitted when we detect that a quit() or exit() is invoked
+ This check is emitted when we detect that a quit() or exit() is invoked
instead of sys.exit(), which is the preferred way of exiting in program.
Close #2925
-
+
* Added a new check, ``arguments-out-of-order``
This check warns if you have arguments with names that match those in
@@ -125,7 +125,7 @@ New checkers
Other Changes
=============
-* Don't emit ``protected-access`` when a single underscore prefixed attribute is used
+* Don't emit ``protected-access`` when a single underscore prefixed attribute is used
inside a special method
Close #1802
@@ -208,3 +208,10 @@ would mean that `no-value-for-parameter` would not be raised for::
to control which logging string format style is valid.
To allow this, a new `fstr` value is valid for the `logging-format-style`
option.
+
+* ``--list-msgs-enabled`` command was added.
+
+When enabling/disabling several messages and groups in a config file,
+it can be unclear which messages are actually enabled and which are disabled.
+This new command produces the final resolved lists of enabled/disabled messages,
+sorted by symbol but with the ID provided for use with ``--help-msg``.
diff --git a/pylint/lint.py b/pylint/lint.py
index a43c4b95a..4d8e87d83 100644
--- a/pylint/lint.py
+++ b/pylint/lint.py
@@ -820,6 +820,25 @@ class PyLinter(
self.global_set_option("disable", value)
self._python3_porting_mode = True
+ def list_messages_enabled(self):
+ enabled = [
+ " %s (%s)" % (message.symbol, message.msgid)
+ for message in self.msgs_store.messages
+ if self.is_message_enabled(message.msgid)
+ ]
+ disabled = [
+ " %s (%s)" % (message.symbol, message.msgid)
+ for message in self.msgs_store.messages
+ if not self.is_message_enabled(message.msgid)
+ ]
+ print("Enabled messages:")
+ for msg in sorted(enabled):
+ print(msg)
+ print("\nDisabled messages:")
+ for msg in sorted(disabled):
+ print(msg)
+ print("")
+
# block level option handling #############################################
#
# see func_block_disable_msg.py test case for expected behaviour
@@ -1514,6 +1533,18 @@ group are mutually exclusive.",
},
),
(
+ "list-msgs-enabled",
+ {
+ "action": "callback",
+ "metavar": "<msg-id>",
+ "callback": self.cb_list_messages_enabled,
+ "group": "Commands",
+ "level": 1,
+ "help": "Display a list of what messages are enabled "
+ "and disabled with the given configuration.",
+ },
+ ),
+ (
"list-groups",
{
"action": "callback",
@@ -1750,6 +1781,11 @@ group are mutually exclusive.",
self.linter.msgs_store.list_messages()
sys.exit(0)
+ def cb_list_messages_enabled(self, option, optname, value, parser):
+ """optik callback for printing available messages"""
+ self.linter.list_messages_enabled()
+ sys.exit(0)
+
def cb_list_groups(self, *args, **kwargs):
"""List all the check groups that pylint knows about
diff --git a/tests/unittest_lint.py b/tests/unittest_lint.py
index e27fa172b..4f942cd02 100644
--- a/tests/unittest_lint.py
+++ b/tests/unittest_lint.py
@@ -596,6 +596,28 @@ def test_full_documentation(linter):
assert re.search(regexp, output)
+def test_list_msgs_enabled(init_linter, capsys):
+ linter = init_linter
+ linter.enable("W0101", scope="package")
+ linter.disable("W0102", scope="package")
+ linter.list_messages_enabled()
+
+ lines = capsys.readouterr().out.splitlines()
+
+ assert "Enabled messages:" in lines
+ assert " unreachable (W0101)" in lines
+
+ assert "Disabled messages:" in lines
+ disabled_ix = lines.index("Disabled messages:")
+
+ # W0101 should be in the enabled section
+ assert lines.index(" unreachable (W0101)") < disabled_ix
+
+ assert " dangerous-default-value (W0102)" in lines
+ # W0102 should be in the disabled section
+ assert lines.index(" dangerous-default-value (W0102)") > disabled_ix
+
+
@pytest.fixture
def pop_pylintrc():
os.environ.pop("PYLINTRC", None)
@@ -776,7 +798,7 @@ def test_by_module_statement_value(init_linter):
linter = init_linter
linter.check(os.path.join(os.path.dirname(__file__), "data"))
- for module, module_stats in linter.stats['by_module'].items():
+ for module, module_stats in linter.stats["by_module"].items():
linter2 = init_linter
if module == "data":
@@ -786,4 +808,4 @@ def test_by_module_statement_value(init_linter):
# Check that the by_module "statement" is equal to the global "statement"
# computed for that module
- assert module_stats['statement'] == linter2.stats['statement']
+ assert module_stats["statement"] == linter2.stats["statement"]