-
Notifications
You must be signed in to change notification settings - Fork 581
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
DocformatterBear: Add DocformatterBear #1556
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from coalib.bearlib.abstractions.Linter import linter | ||
from dependency_management.requirements.PipRequirement import PipRequirement | ||
|
||
|
||
@linter(executable='docformatter', | ||
output_format='unified-diff', | ||
diff_distance=-1, | ||
prerequisite_check_command=('docformatter', '--version'), | ||
prerequisite_check_fail_message='docformatter is not installed. Run ' | ||
'`pip install docformatter` to install' | ||
'docformatter.', | ||
result_message='The documentation string does not meet PEP 257 ' | ||
'conventions.') | ||
class DocformatterBear: | ||
""" | ||
Check the docstrings according to PEP 257 conventions. | ||
|
||
More information available at https://github.com/myint/docformatter | ||
""" | ||
|
||
LANGUAGES = {'Python', 'Python 2', 'Python 3'} | ||
REQUIREMENTS = {PipRequirement('docformatter')} | ||
AUTHORS = {'The coala developers'} | ||
AUTHORS_EMAILS = {'[email protected]'} | ||
LICENSE = 'AGPL-3.0' | ||
CAN_FIX = {'Formatting', 'Documentation'} | ||
|
||
@staticmethod | ||
def create_arguments(filename, file, config_file, | ||
wrap_summaries_length: int=79, | ||
wrap_descriptions_length: int=72, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if 72 is relative to 79, then this default should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "79" and "72" were the default values specified in docformatter's documentation. Actually, I was not aware if we used coala-provided defaults or the defaults for the external linter that the bear wraps 😅 |
||
no_blank: bool=False, | ||
pre_summary_newline: bool=False, | ||
make_summary_multi_line: bool=False, | ||
force_wrap: bool=False): | ||
""" | ||
:param wrap_summaries_length: | ||
Wrap long summary lines at this length. | ||
:param wrap_descriptions_length: | ||
Wrap descriptions at this length. | ||
:param no_blank: | ||
Do not add blank line after description. | ||
:param pre_summary_newline: | ||
Add a newline before the summary of a multi-line | ||
docstring. | ||
:param make_summary_multi_line: | ||
Add a newline before and after the summary of a one- | ||
line docstring. | ||
:param force_wrap: | ||
Force descriptions to be wrapped even if it may result | ||
in a mess. | ||
""" | ||
options = ('--wrap-summaries', str(wrap_summaries_length), | ||
'--wrap-descriptions', str(wrap_descriptions_length)) | ||
options += (('--no-blank',) if no_blank else ()) | ||
options += (('--pre-summary-newline',) if pre_summary_newline else ()) | ||
options += (('--make-summary-multi-line',) | ||
if make_summary_multi_line else ()) | ||
options += (('--force-wrap',) if force_wrap else ()) | ||
return options + (filename,) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from queue import Queue | ||
|
||
from bears.python.DocformatterBear import DocformatterBear | ||
from coalib.testing.LocalBearTestHelper import LocalBearTestHelper | ||
from coalib.settings.Section import Section | ||
|
||
|
||
bad_file = ''' | ||
"""Let's check indentation. | ||
|
||
This module docstring should be dedented.""" | ||
''' | ||
|
||
good_file = ''' | ||
"""Here are some examples. | ||
|
||
This module docstring is dedented. | ||
|
||
""" | ||
''' | ||
|
||
result_message = 'The documentation string does not meet PEP 257 conventions.' | ||
|
||
|
||
class DocformatterBearTest(LocalBearTestHelper): | ||
|
||
def setUp(self): | ||
self.uut = DocformatterBear(Section('name'), Queue()) | ||
|
||
def test_run(self): | ||
self.check_validity(self.uut, bad_file.splitlines(), valid=False) | ||
self.check_validity(self.uut, good_file.splitlines()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
80
is defined in coala's repo SpacingHelper iirc.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also shouldnt this default to the value of
max_line_length