Skip to content

Commit

Permalink
restLintBear: Ignore unknown errors
Browse files Browse the repository at this point in the history
Fixes #1716
  • Loading branch information
SanketDG committed May 8, 2017
1 parent 18febd5 commit 1f357ad
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
20 changes: 19 additions & 1 deletion bears/rest/reSTLintBear.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import re

from restructuredtext_lint import lint

from coalib.bears.LocalBear import LocalBear
Expand All @@ -6,6 +8,18 @@
from coalib.results.RESULT_SEVERITY import RESULT_SEVERITY


def _ignore_unknown(errors):
for error in errors:
msg = error.full_message
res = re.search(
r'No directive entry for "[\w|\-]+"|'
r'Unknown directive type "[\w|\-]+"|'
r'No role entry for "[\w|\-]+"|'
r'Unknown interpreted text role "[\w|\-]+"', msg)
if not res:
yield error


class reSTLintBear(LocalBear):
LANGUAGES = {'reStructuredText'}
REQUIREMENTS = {PipRequirement('restructuredtext-lint', '1.0.0')}
Expand All @@ -14,13 +28,17 @@ class reSTLintBear(LocalBear):
LICENSE = 'AGPL-3.0'
CAN_DETECT = {'Formatting', 'Syntax'}

def run(self, filename, file):
def run(self, filename, file, ignore_unknown_roles: bool=False):
"""
Lints reStructuredText.
:param ignore_unknown_roles: Ignore unknown directives and roles.
"""
content = ''.join(file)
errors = lint(content)

errors = _ignore_unknown(errors) if ignore_unknown_roles else errors

for error in errors:
severity = {
1: RESULT_SEVERITY.INFO,
Expand Down
9 changes: 9 additions & 0 deletions tests/rest/reSTLintBearTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,16 @@
good_file = 'test\n====\n'
bad_file = 'test\n==\n'

good_file2 = ':doc:`here <../Users/Tutorial>`'
bad_file2 = 'test\n==\n'

reSTLintBearTest = verify_local_bear(reSTLintBear,
valid_files=(good_file,),
invalid_files=(bad_file,))


reSTLintBearSettingsTest = verify_local_bear(
reSTLintBear,
valid_files=(good_file2,),
invalid_files=(bad_file2,),
settings={'ignore_unknown_roles': True})

0 comments on commit 1f357ad

Please sign in to comment.