Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --strict option to fail on informational messages #3363

Closed
xavfernandez opened this issue Jan 24, 2020 · 6 comments · Fixed by #4713
Closed

Add --strict option to fail on informational messages #3363

xavfernandez opened this issue Jan 24, 2020 · 6 comments · Fixed by #4713
Assignees
Labels
Enhancement ✨ Improvement to a component
Milestone

Comments

@xavfernandez
Copy link

Is your feature request related to a problem? Please describe

A bunch of useful informational messages exist in pylint but enforcing them in CI is tricky since their presence doesn't affect the exit code.

Describe the solution you'd like

The activation of this --strict (or --fail-on-informational) option would simply change
MSG_TYPES_STATUS['I'] value to a none-zero value to be determined (I'd go with 1)

https://github.com/PyCQA/pylint/blob/f2f4e6f42416644471ab003d4df7ecf052c3c411/pylint/constants.py#L33

to make pylint fail when an informational message is produced.

Additional context

This could be an alternative to #3251

@xavfernandez
Copy link
Author

In the meantime, a fake plugin pylint-strict-informational that does exactly that has been published.

To use, pip install pylint-strict-informational then use pylint --load-plugins=pylint_strict_informational (or set it in your configuration file).
(From an original idea of @dbaty).

@PCManticore
Copy link
Contributor

A strict mode could make sense for other checks as well. It's definitely something we should consider.

@PCManticore PCManticore added the Enhancement ✨ Improvement to a component label Feb 29, 2020
@papb
Copy link

papb commented Jul 15, 2021

@xavfernandez Unfortunately pylint-strict-informational did not work for me (Polyconseil/pylint-strict-informational#2).

I ended up with the following workaround (executed before calling pylint):

find .venv/lib -path '*/pylint/constants.py' -exec sed -r -i -e 's@(^MSG_TYPES_STATUS = .*):\s*0,(.*)@\1: 4,\2  # monkey-patched, waiting for pylint#3363@g' {} ';'

@MarkCBell
Copy link
Contributor

MarkCBell commented Jul 15, 2021

Note, since ab094ae, it is not just enough to change the MSG_TYPES_STATUS of the informational type messages. This is because this commit means that a shortcut exit(0) is applied whenever a run completes with a score >= config.fail_under (which is 10.0 by default). Since informational messages do not affect the score, if only informational messages are raised during a run then the run completes with a perfect score and so this shortcut is applied and the job exits with return code 0 regardless of the value of self.linter.msg_status.

This is the reason that pylint-strict-informational no longer works (unless you use an option like --fail-under=11 to prevent this shortcut from ever being applied).

@papb
Copy link

papb commented Sep 15, 2022

Hello @Pierre-Sassoulas and everyone, sorry to take long, but: why was this issue closed? PR #4713 does not seem to add a flag to allow failing on any informational message.

At least it seems I can now achieve it by manually adding --fail-on for all existing informational messages, but I don't like that. Thoughts?

@papb
Copy link

papb commented Sep 15, 2022

Never mind, adding the following to my .pylintrc worked:

evaluation=10.0 - ((float(5 * error + warning + refactor + convention + info) / statement) * 10)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement ✨ Improvement to a component
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants