Permalink
Browse files

MarkdownBear: Add `validate-links` plugin

Add `validate-links` plugin and since the `validate-links`
plugin is incompatible with stdin input, `use_stdin=True`
was removed.

Closes #924
  • Loading branch information...
yash-nisar committed Jul 14, 2017
1 parent c9be1bf commit f68bd91a820293a1c6d376a58a7f60228c33fa3a
Showing with 39 additions and 4 deletions.
  1. +10 −4 bears/markdown/MarkdownBear.py
  2. +1 −0 package.json
  3. +28 −0 tests/markdown/MarkdownBearTest.py
@@ -8,7 +8,6 @@
@linter(executable='remark',
use_stdin=True,
use_stdout=True,
use_stderr=True)
class MarkdownBear:
@@ -21,7 +20,8 @@ class MarkdownBear:
LANGUAGES = {'Markdown'}
REQUIREMENTS = {NpmRequirement('remark-cli', '2'),
NpmRequirement('remark-lint', '5')}
NpmRequirement('remark-lint', '5'),
NpmRequirement('remark-validate-links', '5')}
AUTHORS = {'The coala developers'}
AUTHORS_EMAILS = {'coala-devel@googlegroups.com'}
LICENSE = 'AGPL-3.0'
@@ -65,7 +65,8 @@ def create_arguments(filename, file, config_file,
horizontal_rule: str='*',
horizontal_rule_spaces: bool=False,
horizontal_rule_repeat: int=3,
max_line_length: int=None):
max_line_length: int=None,
check_links: bool=False):
"""
:param bullets:
Character to use for bullets in lists. Can be "-", "*" or "+".
@@ -108,6 +109,8 @@ def create_arguments(filename, file, config_file,
The number of times the horizontal rule character will be repeated.
:param max_line_length:
The maximum line length allowed.
:param check_links:
Checks if links to headings and files in markdown are valid.
"""
remark_configs_settings = {
'bullet': bullets, # - or *
@@ -136,13 +139,16 @@ def create_arguments(filename, file, config_file,
# Remove { and } as remark adds them on its own
settings = config_json[1:-1]
args = ['--no-color', '--quiet', '--setting', settings]
args = [filename, '--no-color', '--quiet', '--setting', settings]
if remark_configs_plugins:
config_json = json.dumps(remark_configs_plugins)
plugins = 'lint=' + config_json[1:-1]
args += ['--use', plugins]
if check_links:
args += ['--use', 'validate-links']
return args
def process_output(self, output, filename, file):
View
@@ -19,6 +19,7 @@
"ramllint": ">=1.2.2 <1.2.4 || >=1.2.5 <1.3.0",
"remark-cli": "~2",
"remark-lint": "~5",
"remark-validate-links": "~5",
"standard": "~7",
"stylelint": "~7",
"stylint": "~1.5.9",
@@ -22,6 +22,16 @@
2. nopqrstuvwxyz
"""
test_file4 = """# Hello
Read more [This link does not exist](#world).
"""
test_file5 = """# world
Read more [This link exists](#world).
"""
MarkdownBearTest = verify_local_bear(MarkdownBear,
valid_files=(test_file2,),
invalid_files=(test_file1,))
@@ -55,3 +65,21 @@ def test_invalid_message(self):
'Line must be at most 10 characters'
' maximum-line-length remark-lint')
self.assertEqual(results[0].severity, RESULT_SEVERITY.NORMAL)
def test_invalid_link(self):
content = test_file4.splitlines()
self.section.append(Setting('check_links', True))
with prepare_file(content, None) as (file, fname):
with execute_bear(self.uut, fname, file) as results:
self.assertEqual(results[0].message,
'Link to unknown heading: `world`'
' remark-validate-links '
'remark-validate-links')
self.assertEqual(results[0].severity, RESULT_SEVERITY.NORMAL)
def test_valid_link(self):
content = test_file5.splitlines()
self.section.append(Setting('check_links', True))
with prepare_file(content, None) as (file, fname):
with execute_bear(self.uut, fname, file) as results:
self.assertEqual(results, [])

0 comments on commit f68bd91

Please sign in to comment.