diff options
author | Pierre Sassoulas <pierre.sassoulas@gmail.com> | 2023-01-30 15:59:23 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-30 14:59:23 +0000 |
commit | 4036863950f8ad04d66b507ee3d851cec1dc066b (patch) | |
tree | 282a8b4068dc7ad9c4ae198ad14a3caeeca57b37 | |
parent | df85f7a1b8d441555483ed8cc7f6ea89fb4803eb (diff) | |
download | pylint-git-4036863950f8ad04d66b507ee3d851cec1dc066b.tar.gz |
[doc] Make sure that doc examples are of a reasonable length (#8135)
And upgrade existing unreasonable length. Reading ease is drastically
reduced on read the doc after 103 chars (Because of horizontal scrolling)
-rw-r--r-- | .pre-commit-config.yaml | 7 | ||||
-rw-r--r-- | doc/data/.flake8 | 6 | ||||
-rw-r--r-- | doc/data/messages/b/bad-exception-cause/bad.py | 3 | ||||
-rw-r--r-- | doc/data/messages/c/class-variable-slots-conflict/bad.py | 3 | ||||
-rw-r--r-- | doc/data/messages/c/consider-using-dict-comprehension/bad.py | 3 | ||||
-rw-r--r-- | doc/data/messages/c/consider-using-dict-comprehension/details.rst | 3 | ||||
-rw-r--r-- | doc/data/messages/c/consider-using-f-string/bad.py | 16 | ||||
-rw-r--r-- | doc/data/messages/c/consider-using-set-comprehension/bad.py | 3 | ||||
-rw-r--r-- | doc/data/messages/c/consider-using-set-comprehension/details.rst | 3 | ||||
-rw-r--r-- | doc/data/messages/l/line-too-long/bad.py | 3 | ||||
-rw-r--r-- | doc/data/messages/l/line-too-long/pylintrc | 2 | ||||
-rw-r--r-- | doc/data/messages/n/no-self-use/details.rst | 2 | ||||
-rw-r--r-- | doc/data/messages/n/no-self-use/good.py | 2 | ||||
-rw-r--r-- | doc/data/messages/t/too-many-boolean-expressions/bad.py | 3 | ||||
-rw-r--r-- | doc/data/messages/t/too-many-format-args/bad.py | 3 |
15 files changed, 48 insertions, 14 deletions
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c6306e9f2..c2ba36f51 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -60,6 +60,13 @@ repos: additional_dependencies: [flake8-bugbear==23.1.20, flake8-typing-imports==1.14.0] exclude: *fixtures + - repo: https://github.com/PyCQA/flake8 + rev: 6.0.0 + hooks: + - id: flake8 + name: line-length-doc + files: doc/data/messages + args: ["--config", "doc/data/.flake8"] - repo: local hooks: - id: pylint diff --git a/doc/data/.flake8 b/doc/data/.flake8 new file mode 100644 index 000000000..676bedc0d --- /dev/null +++ b/doc/data/.flake8 @@ -0,0 +1,6 @@ +[flake8] +select = + E501, +# Reading ease is drastically reduced on read the doc after 103 chars +# (Because of horizontal scrolling) +max-line-length=103 diff --git a/doc/data/messages/b/bad-exception-cause/bad.py b/doc/data/messages/b/bad-exception-cause/bad.py index 76138f080..ad4228af8 100644 --- a/doc/data/messages/b/bad-exception-cause/bad.py +++ b/doc/data/messages/b/bad-exception-cause/bad.py @@ -3,5 +3,6 @@ def divide(x, y): try: result = x / y except ZeroDivisionError: - raise ValueError(f"Division by zero when dividing {x} by {y} !") from result # [bad-exception-cause] + # +1: [bad-exception-cause] + raise ValueError(f"Division by zero when dividing {x} by {y} !") from result return result diff --git a/doc/data/messages/c/class-variable-slots-conflict/bad.py b/doc/data/messages/c/class-variable-slots-conflict/bad.py index 87f0b578e..770566962 100644 --- a/doc/data/messages/c/class-variable-slots-conflict/bad.py +++ b/doc/data/messages/c/class-variable-slots-conflict/bad.py @@ -1,5 +1,6 @@ class Person: - __slots__ = ("age", "name", "say_hi",) # [class-variable-slots-conflict, class-variable-slots-conflict, class-variable-slots-conflict] + # +1: [class-variable-slots-conflict, class-variable-slots-conflict, class-variable-slots-conflict] + __slots__ = ("age", "name", "say_hi") name = None def __init__(self, age, name): diff --git a/doc/data/messages/c/consider-using-dict-comprehension/bad.py b/doc/data/messages/c/consider-using-dict-comprehension/bad.py index 78129c56f..d9b02c71b 100644 --- a/doc/data/messages/c/consider-using-dict-comprehension/bad.py +++ b/doc/data/messages/c/consider-using-dict-comprehension/bad.py @@ -1,3 +1,4 @@ NUMBERS = [1, 2, 3] -DOUBLED_NUMBERS = dict([(number, number * 2) for number in NUMBERS]) # [consider-using-dict-comprehension] +# +1: [consider-using-dict-comprehension] +DOUBLED_NUMBERS = dict([(number, number * 2) for number in NUMBERS]) diff --git a/doc/data/messages/c/consider-using-dict-comprehension/details.rst b/doc/data/messages/c/consider-using-dict-comprehension/details.rst new file mode 100644 index 000000000..c287fc484 --- /dev/null +++ b/doc/data/messages/c/consider-using-dict-comprehension/details.rst @@ -0,0 +1,3 @@ +pyupgrade_ can fix this issue automatically. + +.. _pyupgrade: https://github.com/asottile/pyupgrade diff --git a/doc/data/messages/c/consider-using-f-string/bad.py b/doc/data/messages/c/consider-using-f-string/bad.py index d706d08e2..26da6a166 100644 --- a/doc/data/messages/c/consider-using-f-string/bad.py +++ b/doc/data/messages/c/consider-using-f-string/bad.py @@ -1,10 +1,16 @@ from string import Template -menu = ('eggs', 'spam', 42.4) +menu = ("eggs", "spam", 42.4) -old_order = "%s and %s: %.2f ¤" % menu # [consider-using-f-string] +old_order = "%s and %s: %.2f ¤" % menu # [consider-using-f-string] beginner_order = menu[0] + " and " + menu[1] + ": " + str(menu[2]) + " ¤" joined_order = " and ".join(menu[:2]) -format_order = "{} and {}: {:0.2f} ¤".format(menu[0], menu[1], menu[2]) # [consider-using-f-string] -named_format_order = "{eggs} and {spam}: {price:0.2f} ¤".format(eggs=menu[0], spam=menu[1], price=menu[2]) # [consider-using-f-string] -template_order = Template('$eggs and $spam: $price ¤').substitute(eggs=menu[0], spam=menu[1], price=menu[2]) +# +1: [consider-using-f-string] +format_order = "{} and {}: {:0.2f} ¤".format(menu[0], menu[1], menu[2]) +# +1: [consider-using-f-string] +named_format_order = "{eggs} and {spam}: {price:0.2f} ¤".format( + eggs=menu[0], spam=menu[1], price=menu[2] +) +template_order = Template("$eggs and $spam: $price ¤").substitute( + eggs=menu[0], spam=menu[1], price=menu[2] +) diff --git a/doc/data/messages/c/consider-using-set-comprehension/bad.py b/doc/data/messages/c/consider-using-set-comprehension/bad.py index 657a21162..ffdc9e526 100644 --- a/doc/data/messages/c/consider-using-set-comprehension/bad.py +++ b/doc/data/messages/c/consider-using-set-comprehension/bad.py @@ -1,3 +1,4 @@ NUMBERS = [1, 2, 2, 3, 4, 4] -UNIQUE_EVEN_NUMBERS = set([number for number in NUMBERS if number % 2 == 0]) # [consider-using-set-comprehension] +# +1: [consider-using-set-comprehension] +UNIQUE_EVEN_NUMBERS = set([number for number in NUMBERS if number % 2 == 0]) diff --git a/doc/data/messages/c/consider-using-set-comprehension/details.rst b/doc/data/messages/c/consider-using-set-comprehension/details.rst new file mode 100644 index 000000000..c287fc484 --- /dev/null +++ b/doc/data/messages/c/consider-using-set-comprehension/details.rst @@ -0,0 +1,3 @@ +pyupgrade_ can fix this issue automatically. + +.. _pyupgrade: https://github.com/asottile/pyupgrade diff --git a/doc/data/messages/l/line-too-long/bad.py b/doc/data/messages/l/line-too-long/bad.py index 4b82d8cd2..94e9042a3 100644 --- a/doc/data/messages/l/line-too-long/bad.py +++ b/doc/data/messages/l/line-too-long/bad.py @@ -1 +1,2 @@ -FRUIT = ["apricot", "blackcurrant", "cantaloupe", "dragon fruit", "elderberry", "fig", "grapefruit"] # [line-too-long] +# +1: [line-too-long] +FRUIT = ["apricot", "blackcurrant", "cantaloupe", "dragon fruit", "elderberry", "fig", "grapefruit", ] diff --git a/doc/data/messages/l/line-too-long/pylintrc b/doc/data/messages/l/line-too-long/pylintrc new file mode 100644 index 000000000..81ee5451e --- /dev/null +++ b/doc/data/messages/l/line-too-long/pylintrc @@ -0,0 +1,2 @@ +[MAIN] +max-line-length=100 diff --git a/doc/data/messages/n/no-self-use/details.rst b/doc/data/messages/n/no-self-use/details.rst new file mode 100644 index 000000000..9862ff2de --- /dev/null +++ b/doc/data/messages/n/no-self-use/details.rst @@ -0,0 +1,2 @@ +If a function is not using any class attribute it can be a ``@staticmethod``, +or a function outside the class. diff --git a/doc/data/messages/n/no-self-use/good.py b/doc/data/messages/n/no-self-use/good.py index dd401b73e..cc1ad2bdc 100644 --- a/doc/data/messages/n/no-self-use/good.py +++ b/doc/data/messages/n/no-self-use/good.py @@ -1,5 +1,3 @@ -"""If a function is not using any class attribute it can be a @staticmethod, or a function outside the class.""" - def developer_greeting(): print("Greetings developer!") diff --git a/doc/data/messages/t/too-many-boolean-expressions/bad.py b/doc/data/messages/t/too-many-boolean-expressions/bad.py index 8bd65e40b..5f3ae4194 100644 --- a/doc/data/messages/t/too-many-boolean-expressions/bad.py +++ b/doc/data/messages/t/too-many-boolean-expressions/bad.py @@ -1,4 +1,5 @@ def can_be_divided_by_two_and_are_not_zero(x, y, z): # Maximum number of boolean expressions in an if statement (by default 5) - if (x and y and z) and (x % 2 == 0 and y % 2 == 0 and z % 2 == 0): # [too-many-boolean-expressions] + # +1: [too-many-boolean-expressions] + if (x and y and z) and (x % 2 == 0 and y % 2 == 0 and z % 2 == 0): pass diff --git a/doc/data/messages/t/too-many-format-args/bad.py b/doc/data/messages/t/too-many-format-args/bad.py index 0c98c084d..548f41042 100644 --- a/doc/data/messages/t/too-many-format-args/bad.py +++ b/doc/data/messages/t/too-many-format-args/bad.py @@ -1 +1,2 @@ -print("Today is {0}, so tomorrow will be {1}".format("Monday", "Tuesday", "Wednesday")) # [too-many-format-args] +# +1: [too-many-format-args] +print("Today is {0}, so tomorrow will be {1}".format("Monday", "Tuesday", "Wednesday")) |