diff options
author | Andreas Finkler <3929834+DudeNr33@users.noreply.github.com> | 2022-04-02 15:36:39 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-02 15:36:39 +0200 |
commit | 236313a5cfb9dd5cedbf851dcad8be10417016c4 (patch) | |
tree | b36e1940652cffb8889d723f80fc8c1b791bd2bb /doc/data/messages/c | |
parent | be43fff0aea3c7423e17ca0ee62ea346045734ad (diff) | |
download | pylint-git-236313a5cfb9dd5cedbf851dcad8be10417016c4.tar.gz |
Enable usage of custom pylintrc file for message documentation tests (#6131)
Demonstrate it with optional checker message as example.
Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
Diffstat (limited to 'doc/data/messages/c')
4 files changed, 31 insertions, 0 deletions
diff --git a/doc/data/messages/c/confusing-consecutive-elif/bad.py b/doc/data/messages/c/confusing-consecutive-elif/bad.py new file mode 100644 index 000000000..93e1e2dee --- /dev/null +++ b/doc/data/messages/c/confusing-consecutive-elif/bad.py @@ -0,0 +1,6 @@ +def myfunc(shall_continue: bool, shall_exit: bool): + if shall_continue: + if input("Are you sure?") == "y": + print("Moving on.") + elif shall_exit: # [confusing-consecutive-elif] + print("Exiting.") diff --git a/doc/data/messages/c/confusing-consecutive-elif/details.rst b/doc/data/messages/c/confusing-consecutive-elif/details.rst new file mode 100644 index 000000000..bd2ecc4ee --- /dev/null +++ b/doc/data/messages/c/confusing-consecutive-elif/details.rst @@ -0,0 +1 @@ +Creating a function for the nested conditional, or adding an explicit ``else`` in the indented ``if`` statement, even if it only contains a ``pass`` statement, can help clarify the code. diff --git a/doc/data/messages/c/confusing-consecutive-elif/good.py b/doc/data/messages/c/confusing-consecutive-elif/good.py new file mode 100644 index 000000000..1722a6bfa --- /dev/null +++ b/doc/data/messages/c/confusing-consecutive-elif/good.py @@ -0,0 +1,22 @@ +# Option 1: add explicit 'else' +def myfunc(shall_continue: bool, shall_exit: bool): + if shall_continue: + if input("Are you sure?") == "y": + print("Moving on.") + else: + pass + elif shall_exit: + print("Exiting.") + + +# Option 2: extract function +def user_confirmation(): + if input("Are you sure?") == "y": + print("Moving on.") + + +def myfunc2(shall_continue: bool, shall_exit: bool): + if shall_continue: + user_confirmation() + elif shall_exit: + print("Exiting.") diff --git a/doc/data/messages/c/confusing-consecutive-elif/pylintrc b/doc/data/messages/c/confusing-consecutive-elif/pylintrc new file mode 100644 index 000000000..6a11b2c09 --- /dev/null +++ b/doc/data/messages/c/confusing-consecutive-elif/pylintrc @@ -0,0 +1,2 @@ +[MASTER] +load-plugins=pylint.extensions.confusing_elif |