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 documentation for too-many-lines #8323

Merged
merged 19 commits into from
Feb 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions doc/data/messages/t/too-many-lines/bad.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
def is_palindrome(string): # [too-many-lines]
left_pos = 0
right_pos = len(string) - 1
while right_pos >= left_pos:
if not string[left_pos] == string[right_pos]:
return False
left_pos += 1
right_pos -= 1
return True

Pierre-Sassoulas marked this conversation as resolved.
Show resolved Hide resolved

def main():
print(isPalindrome("aza"))
print(isPalindrome("racecar"))
print(isPalindrome("trigger"))
print(isPalindrome("ogre"))
10 changes: 9 additions & 1 deletion doc/data/messages/t/too-many-lines/details.rst
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
You can help us make the doc better `by contributing <https://github.com/PyCQA/pylint/issues/5953>`_ !
ollie-iterators marked this conversation as resolved.
Show resolved Hide resolved
When a module has too many lines it can make it difficult to read and understand. There might be
performance issue while editing the file because the IDE must parse more code. You need more expertise
to navigate the file properly (go to a particular line when debugging, or search for a specific code construct, instead of navigating by clicking and scrolling)

This measure is a proxy for higher cyclomatic complexity that you might not be calculating if you're not using ``load-plugins=pylint.extensions.mccabe,``. Cyclomatic complexity is slower to compute, but also a more fine grained measure than raw SLOC. In particular, you can't make the code less readable by making a very complex one liner if you're using cyclomatic complexity.

The example simplify the code, but it's not always possible. Most of the time bursting the file
by creating a package with the same API is the only solution. Anticipating and creating the file
from the get go will permit to have the same end result with a better version control history.
1 change: 0 additions & 1 deletion doc/data/messages/t/too-many-lines/good.py

This file was deleted.

4 changes: 4 additions & 0 deletions doc/data/messages/t/too-many-lines/good/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
__all__ = ["is_palindrome", "main"]

from is_palindrome import is_palindrome
from main import main
2 changes: 2 additions & 0 deletions doc/data/messages/t/too-many-lines/good/is_palindrome.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def is_palindrome(string):
return string == string[::-1]
6 changes: 6 additions & 0 deletions doc/data/messages/t/too-many-lines/good/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from is_palindrome import is_palindrome


def main():
for string in ["aza", "racecar", "trigger", "ogre"]:
print(is_palindrome(string))
2 changes: 2 additions & 0 deletions doc/data/messages/t/too-many-lines/pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[main]
max-module-lines=15