Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
doc8 is a style checker for Sphinx (or other) RST documentation. doc8 is like flake8 for reStructuredText. See https://pypi.python.org/pypi/doc8 for more information. Testing Done: - Uploaded a diff an .rst file as review request as saw that it added some "errors" of this reStructuredText file. - Uploaded a "clean" .rst file and saw that it did no add any errors. Reviewed at https://reviews.reviewboard.org/r/9489/
- Loading branch information
Showing
4 changed files
with
132 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
"""Review Bot tool to run doc8.""" | ||
|
||
from __future__ import unicode_literals | ||
|
||
import logging | ||
|
||
from reviewbot.tools import Tool | ||
from reviewbot.utils.process import execute, is_exe_in_path | ||
|
||
|
||
class Doc8Tool(Tool): | ||
"""Review Bot tool to run doc8.""" | ||
|
||
name = 'doc8' | ||
version = '1.0' | ||
description = 'Checks reStructuredText for style.' | ||
timeout = 30 | ||
options = [ | ||
{ | ||
'name': 'max_line_length', | ||
'field_type': 'django.forms.IntegerField', | ||
'default': 79, | ||
'field_options': { | ||
'label': 'Maximum Line Length', | ||
'help_text': 'The maximum line length to allow.', | ||
'required': True, | ||
}, | ||
}, | ||
{ | ||
'name': 'encoding', | ||
'field_type': 'django.forms.CharField', | ||
'default': 'utf-8', | ||
'field_options': { | ||
'label': 'Encoding', | ||
'help_text': 'Encoding used for rst files.', | ||
'required': True, | ||
}, | ||
}, | ||
] | ||
|
||
def check_dependencies(self): | ||
"""Verify that the tool's dependencies are installed. | ||
Returns: | ||
bool: | ||
True if all dependencies for the tool are satisfied. If this | ||
returns False, the worker will not be listed for this Tool's queue, | ||
and a warning will be logged. | ||
""" | ||
return is_exe_in_path('doc8') | ||
|
||
def handle_file(self, f, settings): | ||
"""Perform a review of a single file. | ||
Args: | ||
f (reviewbot.processing.review.File): | ||
The file to process. | ||
settings (dict): | ||
Tool-specific settings. | ||
""" | ||
if not f.dest_file.lower().endswith('.rst'): | ||
# Ignore the file. | ||
return | ||
|
||
path = f.get_patched_file_path() | ||
|
||
if not path: | ||
return | ||
|
||
output = execute( | ||
[ | ||
'doc8', '-q', | ||
'--max-line-length=%s' % settings['max_line_length'], | ||
'--file-encoding=%s' % settings['encoding'], | ||
path, | ||
], | ||
split_lines=True, | ||
ignore_errors=True) | ||
|
||
for line in output: | ||
try: | ||
# Strip off the filename, since it might have colons in it. | ||
line = line[len(path) + 1:] | ||
line_num, message = line.split(':', 1) | ||
f.comment(message.strip(), int(line_num)) | ||
except Exception: | ||
logging.error('Cannot parse line with doc8: %s', line) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
.. _tool-doc8: | ||
|
||
==== | ||
doc8 | ||
==== | ||
|
||
DOC8_ is a style checker for Sphinx (or other) reStructuredText | ||
documentation. Also it has basic support for plain text. | ||
:command:`doc8` uses RST_LINT_ as a backend for the verification. | ||
|
||
.. _DOC8: https://pypi.python.org/pypi/doc8 | ||
.. _RST_LINT: https://pypi.python.org/pypi/restructuredtext_lint | ||
|
||
|
||
Checks | ||
====== | ||
|
||
doc8 verifies the following styles in ``.rst`` files. | ||
|
||
* Invalid rst format - D000 | ||
* Lines should not be longer than 79 characters - D001 | ||
|
||
* RST exception: line with no whitespace except in the beginning | ||
* RST exception: lines with http or https urls | ||
* RST exception: literal blocks | ||
* RST exception: rst target directives | ||
|
||
* No trailing whitespace - D002 | ||
* No tabulation for indentation - D003 | ||
* No carriage returns (use unix newlines) - D004 | ||
* No newline at end of file - D005 | ||
|
||
|
||
Installation | ||
============ | ||
|
||
:command:`pydocstyle` can be installed on most systems by running:: | ||
|
||
$ pip install doc8 | ||
|
||
It may also be available in your system's package manager. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ Review Bot Tools | |
clang | ||
cppcheck | ||
cpplint | ||
doc8 | ||
flake8 | ||
jshint | ||
pmd | ||
|