Skip to content

Commit b824fee

Browse files
Add --max-line-length option (#105)
Co-authored-by: Daniël van Noord <13665637+DanielNoord@users.noreply.github.com>
1 parent 33d28d9 commit b824fee

File tree

9 files changed

+54
-6
lines changed

9 files changed

+54
-6
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ options:
5656
-w, --write Write the changes to file instead of printing the diffs to stdout.
5757
--quiet Do not print any logging or status messages to stdout.
5858
-v, --version Show version number and exit.
59+
--max-line-length The maximum docstring line length. Default set to 88.
5960

6061
configuration:
6162
--exclude EXCLUDE A comma separated list of glob patterns of file path names not to be formatted.

docs/usage.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ Current usage of ``pydocstringformatter``:
66
.. code-block:: shell
77
88
usage: pydocstringformatter [-h] [-w] [--quiet] [-v] [--exclude EXCLUDE]
9-
[--exit-code]
10-
[--max-summary-lines MAX_SUMMARY_LINES]
9+
[--exit-code] [--max-summary-lines int]
1110
[--summary-quotes-same-line]
11+
[--max-line-length int]
1212
[--strip-whitespaces --no-strip-whitespaces]
1313
[--split-summary-body --no-split-summary-body]
1414
[--linewrap-full-docstring --no-linewrap-full-docstring]
@@ -35,13 +35,15 @@ Current usage of ``pydocstringformatter``:
3535
--exit-code Turn on if the program should exit with bitwise exit
3636
codes. 0 = No changes, 32 = Changed files or printed
3737
diff.
38-
--max-summary-lines MAX_SUMMARY_LINES
38+
--max-summary-lines int
3939
The maximum numbers of lines a summary can span. The
4040
default value is 1.
4141
--summary-quotes-same-line
4242
Force the start of a multi-line docstring to be on the
4343
same line as the opening quotes. Similar to how this
4444
is enforced for single line docstrings.
45+
--max-line-length int
46+
Maximum line length of docstrings.
4547
4648
default formatters:
4749
these formatters are turned on by default

pydocstringformatter/configuration/arguments_manager.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ def _register_arguments(self, version: str) -> None:
9696
"The maximum numbers of lines a summary can span. "
9797
"The default value is 1."
9898
),
99+
metavar="int",
99100
)
100101

101102
self.configuration_group.add_argument(
@@ -108,6 +109,15 @@ def _register_arguments(self, version: str) -> None:
108109
),
109110
)
110111

112+
self.configuration_group.add_argument(
113+
"--max-line-length",
114+
action="store",
115+
default=88,
116+
type=int,
117+
help="Maximum line length of docstrings.",
118+
metavar="int",
119+
)
120+
111121
def parse_options(
112122
self,
113123
argv: list[str],

pydocstringformatter/formatting/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def _separate_summary_and_description(
145145
# Remove opening quotes
146146
summary = summary[quotes_length:]
147147

148-
# Prefix is the new-line + idententation for summaries that
148+
# Prefix is the new-line + indentation for summaries that
149149
# are not on the same line as the opening quotes
150150
prefix = ""
151151
if summary.startswith("\n"):

pydocstringformatter/formatting/formatter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def _treat_summary(
7373
) -> str:
7474
"""Wrap the summary of a docstring."""
7575

76-
line_length = 88
76+
line_length = self.config.max_line_length
7777

7878
# Without a description we need to consider the length including closing quotes
7979
if not description_exists:
@@ -84,7 +84,7 @@ def _treat_summary(
8484
# If potential length is less than line length we need to consider ending
8585
# quotes as well for the line length
8686
if length_without_ending < line_length:
87-
# We substract one more because we don't want a new line with just the
87+
# We subtract one more because we don't want a new line with just the
8888
# ending quotes
8989
line_length -= quotes_length + 1
9090

requirements-test.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ coveralls==3.3.1
55
pytest==6.2.5
66
pytest-cov==3.0.0
77
gitpython>=3
8+
pre-commit==2.19.0
9+
810

911
# Requirements for docs building
1012
-r docs/requirements-doc.txt
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
--linewrap-full-docstring
2+
--max-line-length=50
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
def func():
2+
"""A very long line that needs to be wrapped especially this sentence."""
3+
4+
def func():
5+
"""Event multi line docstrings need to be wrapped.
6+
7+
This description is way too long. It definitely needs to be wrapped.
8+
"""
9+
10+
# Regression for bug found in pylint
11+
# We should re-add the quotes to line length if they will never be on the first line.
12+
class LinesChunk:
13+
"""The LinesChunk object computes and store."""
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
def func():
2+
"""A very long line that needs to be wrapped
3+
especially this sentence.
4+
"""
5+
6+
def func():
7+
"""Event multi line docstrings need to be
8+
wrapped.
9+
10+
This description is way too long. It definitely needs to be wrapped.
11+
"""
12+
13+
# Regression for bug found in pylint
14+
# We should re-add the quotes to line length if they will never be on the first line.
15+
class LinesChunk:
16+
"""The LinesChunk object computes and
17+
store.
18+
"""

0 commit comments

Comments
 (0)