Skip to content

Commit af8cc2e

Browse files
Produce a score of 0 for fatal errors and add fatal to score evaluation (#5521)
Co-authored-by: Daniël van Noord <[email protected]>
1 parent 80e43a9 commit af8cc2e

File tree

7 files changed

+33
-10
lines changed

7 files changed

+33
-10
lines changed

ChangeLog

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ Release date: TBA
5454
* The ``PyLinter`` class will now be initialiazed with a ``TextReporter``
5555
as its reporter if none is provided.
5656

57+
* Fatal errors now emit a score of 0.0 regardless of whether the linted module
58+
contained any statements
59+
60+
Closes #5451
61+
62+
* ``fatal`` was added to the variables permitted in score evaluation expressions.
63+
5764
* Fix false positive - Allow unpacking of ``self`` in a subclass of ``typing.NamedTuple``.
5865

5966
Closes #5312

doc/faq.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ default value by changing the mixin-class-rgx option.
252252
Even though the final rating Pylint renders is nominally out of ten, there's no
253253
lower bound on it. By default, the formula to calculate score is ::
254254

255-
10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10)
255+
0 if fatal else 10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10)
256256

257257
However, this option can be changed in the Pylint rc file. If having negative
258258
values really bugs you, you can set the formula to be the maximum of 0 and the

doc/whatsnew/2.13.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,14 @@ Other Changes
6868

6969
Closes #5065
7070

71-
* The ``PyLinter`` class will now be initialiazed with a ``TextReporter``
71+
* Fatal errors now emit a score of 0.0 regardless of whether the linted module
72+
contained any statements
73+
74+
Closes #5451
75+
76+
* ``fatal`` was added to the variables permitted in score evaluation expressions.
77+
78+
* The ``PyLinter`` class will now be initialized with a ``TextReporter``
7279
as its reporter if none is provided.
7380

7481
* The ``testutils`` for unittests now accept ``end_lineno`` and ``end_column``. Tests

examples/pylintrc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ enable=c-extension-no-member
9090
[REPORTS]
9191

9292
# Python expression which should return a score less than or equal to 10. You
93-
# have access to the variables 'error', 'warning', 'refactor', and 'convention'
93+
# have access to the variables 'fatal', 'error', 'warning', 'refactor', 'convention' and 'info'
9494
# which contain the number of messages in each category, as well as 'statement'
9595
# which is the total number of statements analyzed. This score is used by the
9696
# global evaluation report (RP0004).
97-
evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10)
97+
evaluation=0 if fatal else 10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10)
9898

9999
# Template used to display messages. This is a python new-style format string
100100
# used to format the message information. See doc for all details.

pylint/lint/pylinter.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,7 @@ def enable_fail_on_messages(self):
764764
self.enable(msg.msgid)
765765
self.fail_on_symbols.append(msg.symbol)
766766
elif msg.msgid[0] in fail_on_cats:
767-
# message starts with a cateogry value, flag (but do not enable) it
767+
# message starts with a category value, flag (but do not enable) it
768768
self.fail_on_symbols.append(msg.symbol)
769769

770770
def any_fail_on_issues(self):
@@ -1315,6 +1315,7 @@ def _report_evaluation(self):
13151315
evaluation = self.config.evaluation
13161316
try:
13171317
stats_dict = {
1318+
"fatal": self.stats.fatal,
13181319
"error": self.stats.error,
13191320
"warning": self.stats.warning,
13201321
"refactor": self.stats.refactor,

pylintrc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,11 @@ files-output=no
9898
reports=no
9999

100100
# Python expression which should return a note less than 10 (10 is the highest
101-
# note). You have access to the variables errors warning, statement which
102-
# respectively contain the number of errors / warnings messages and the total
103-
# number of statements analyzed. This is used by the global evaluation report
104-
# (RP0004).
105-
evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10)
101+
# note). You have access to the variables 'fatal', 'error', 'warning', 'refactor', 'convention'
102+
# and 'info', which contain the number of messages in each category, as
103+
# well as 'statement', which is the total number of statements analyzed. This
104+
# score is used by the global evaluation report (RP0004).
105+
evaluation=0 if fatal else 10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10)
106106

107107
# Template used to display messages. This is a python new-style format string
108108
# used to format the message information. See doc for all details

tests/test_self.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,6 +1154,14 @@ def test_fail_on_exit_code(self, args, expected):
11541154
# and errors that are generated they don't affect the exit code.
11551155
self._runtest([path, "--fail-under=-10"] + args, code=expected)
11561156

1157+
def test_one_module_fatal_error(self):
1158+
"""
1159+
Fatal errors in one of several modules linted still exits non-zero.
1160+
"""
1161+
valid_path = join(HERE, "conftest.py")
1162+
invalid_path = join(HERE, "garbagePath.py")
1163+
self._runtest([valid_path, invalid_path], code=1)
1164+
11571165
@pytest.mark.parametrize(
11581166
"args, expected",
11591167
[

0 commit comments

Comments
 (0)