summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Walls <jacobtylerwalls@gmail.com>2021-12-28 10:30:41 -0500
committerGitHub <noreply@github.com>2021-12-28 16:30:41 +0100
commitf56db7d76429ddd86b3e333b60720c389fbd1025 (patch)
treedc783f813b57d96feb0a1833008c3efe8a07b921
parentefe59ca44b9ed350c9790d79a39a7343af5e7ea7 (diff)
downloadpylint-git-f56db7d76429ddd86b3e333b60720c389fbd1025.tar.gz
Fix #2399: Avoid negative scores by default (#5595)
-rw-r--r--ChangeLog4
-rw-r--r--doc/faq.rst15
-rw-r--r--doc/whatsnew/2.13.rst4
-rw-r--r--examples/pylintrc2
-rw-r--r--pylint/lint/pylinter.py4
-rw-r--r--pylintrc2
-rw-r--r--tests/test_self.py9
-rw-r--r--tests/unittest_reporting.py4
8 files changed, 31 insertions, 13 deletions
diff --git a/ChangeLog b/ChangeLog
index 77e77dfe5..87cf8b765 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -96,6 +96,10 @@ Release date: TBA
* ``fatal`` was added to the variables permitted in score evaluation expressions.
+* The default score evaluation now uses a floor of 0.
+
+ Closes #2399
+
* Fix false positive - Allow unpacking of ``self`` in a subclass of ``typing.NamedTuple``.
Closes #5312
diff --git a/doc/faq.rst b/doc/faq.rst
index a2c0f2252..47dc9b501 100644
--- a/doc/faq.rst
+++ b/doc/faq.rst
@@ -249,15 +249,16 @@ default value by changing the mixin-class-rgx option.
6.1 Pylint gave my code a negative rating out of ten. That can't be right!
--------------------------------------------------------------------------
-Even though the final rating Pylint renders is nominally out of ten, there's no
-lower bound on it. By default, the formula to calculate score is ::
+Prior to Pylint 2.13.0, the score formula used by default had no lower
+bound. The new default score formula is ::
- 0 if fatal else 10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10)
-
-However, this option can be changed in the Pylint rc file. If having negative
-values really bugs you, you can set the formula to be the maximum of 0 and the
-above expression.
+ max(0, 0 if fatal else 10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10))
+If your project contains a configuration file created by an earlier version of
+Pylint, you can set ``evaluation`` to the above expression to get the new
+behavior. Likewise, since negative values are still technically supported,
+``evaluation`` can be set to a version of the above expression that does not
+enforce a floor of zero.
6.2 I think I found a bug in Pylint. What should I do?
-------------------------------------------------------
diff --git a/doc/whatsnew/2.13.rst b/doc/whatsnew/2.13.rst
index 219aec512..bf38d767e 100644
--- a/doc/whatsnew/2.13.rst
+++ b/doc/whatsnew/2.13.rst
@@ -104,6 +104,10 @@ Other Changes
* ``fatal`` was added to the variables permitted in score evaluation expressions.
+* The default score evaluation now uses a floor of 0.
+
+ Closes #2399
+
* Fix ``comparison-with-callable`` false positive for callables that raise, such
as typing constants.
diff --git a/examples/pylintrc b/examples/pylintrc
index eb48b4a1f..8fb3c179a 100644
--- a/examples/pylintrc
+++ b/examples/pylintrc
@@ -94,7 +94,7 @@ enable=c-extension-no-member
# which contain the number of messages in each category, as well as 'statement'
# which is the total number of statements analyzed. This score is used by the
# global evaluation report (RP0004).
-evaluation=0 if fatal else 10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10)
+evaluation=max(0, 0 if fatal else 10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10))
# Template used to display messages. This is a python new-style format string
# used to format the message information. See doc for all details.
diff --git a/pylint/lint/pylinter.py b/pylint/lint/pylinter.py
index e46577615..db316caed 100644
--- a/pylint/lint/pylinter.py
+++ b/pylint/lint/pylinter.py
@@ -310,8 +310,8 @@ class PyLinter(
"metavar": "<python_expression>",
"group": "Reports",
"level": 1,
- "default": "0 if fatal else 10.0 - ((float(5 * error + warning + refactor + "
- "convention) / statement) * 10)",
+ "default": "max(0, 0 if fatal else 10.0 - ((float(5 * error + warning + refactor + "
+ "convention) / statement) * 10))",
"help": "Python expression which should return a score less "
"than or equal to 10. You have access to the variables 'fatal', "
"'error', 'warning', 'refactor', 'convention', and 'info' which "
diff --git a/pylintrc b/pylintrc
index 8dec45074..4e093a87c 100644
--- a/pylintrc
+++ b/pylintrc
@@ -120,7 +120,7 @@ reports=no
# and 'info', which contain the number of messages in each category, as
# well as 'statement', which is the total number of statements analyzed. This
# score is used by the global evaluation report (RP0004).
-evaluation=0 if fatal else 10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10)
+evaluation=max(0, 0 if fatal else 10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10))
# Template used to display messages. This is a python new-style format string
# used to format the message information. See doc for all details
diff --git a/tests/test_self.py b/tests/test_self.py
index 27bf17cf6..9f33d745c 100644
--- a/tests/test_self.py
+++ b/tests/test_self.py
@@ -718,11 +718,15 @@ class TestRunTC:
],
code=0,
)
+ # Need the old evaluation formula to test a negative score
+ # failing below a negative --fail-under threshold
self._runtest(
[
"--fail-under",
"-9",
"--enable=all",
+ "--evaluation",
+ "0 if fatal else 10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10)",
join(HERE, "regrtest_data", "fail_under_minus10.py"),
],
code=22,
@@ -732,6 +736,8 @@ class TestRunTC:
"--fail-under",
"-5",
"--enable=all",
+ "--evaluation",
+ "0 if fatal else 10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10)",
join(HERE, "regrtest_data", "fail_under_minus10.py"),
],
code=22,
@@ -777,6 +783,9 @@ class TestRunTC:
f"--fail-on={fo_msgs}",
"--enable=all",
join(HERE, "regrtest_data", fname),
+ # Use the old form of the evaluation that can go negative
+ "--evaluation",
+ "0 if fatal else 10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10)",
],
code=out,
)
diff --git a/tests/unittest_reporting.py b/tests/unittest_reporting.py
index dbf2eb1fd..29aac8640 100644
--- a/tests/unittest_reporting.py
+++ b/tests/unittest_reporting.py
@@ -332,8 +332,8 @@ def test_multi_format_output(tmp_path):
"\n"
"\n"
"\n"
- "-------------------------------------\n"
- "Your code has been rated at -10.00/10\n"
+ "-----------------------------------\n"
+ "Your code has been rated at 0.00/10\n"
"\n"
"direct output\n"
)