Skip to content

Commit

Permalink
MarkdownBear: Add validate-links plugin
Browse files Browse the repository at this point in the history
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 18, 2017
1 parent c9be1bf commit f68bd91
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
14 changes: 10 additions & 4 deletions bears/markdown/MarkdownBear.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@




@linter(executable='remark', @linter(executable='remark',
use_stdin=True,
use_stdout=True, use_stdout=True,
use_stderr=True) use_stderr=True)
class MarkdownBear: class MarkdownBear:
Expand All @@ -21,7 +20,8 @@ class MarkdownBear:


LANGUAGES = {'Markdown'} LANGUAGES = {'Markdown'}
REQUIREMENTS = {NpmRequirement('remark-cli', '2'), REQUIREMENTS = {NpmRequirement('remark-cli', '2'),
NpmRequirement('remark-lint', '5')} NpmRequirement('remark-lint', '5'),
NpmRequirement('remark-validate-links', '5')}
AUTHORS = {'The coala developers'} AUTHORS = {'The coala developers'}
AUTHORS_EMAILS = {'coala-devel@googlegroups.com'} AUTHORS_EMAILS = {'coala-devel@googlegroups.com'}
LICENSE = 'AGPL-3.0' LICENSE = 'AGPL-3.0'
Expand Down Expand Up @@ -65,7 +65,8 @@ def create_arguments(filename, file, config_file,
horizontal_rule: str='*', horizontal_rule: str='*',
horizontal_rule_spaces: bool=False, horizontal_rule_spaces: bool=False,
horizontal_rule_repeat: int=3, horizontal_rule_repeat: int=3,
max_line_length: int=None): max_line_length: int=None,
check_links: bool=False):
""" """
:param bullets: :param bullets:
Character to use for bullets in lists. Can be "-", "*" or "+". Character to use for bullets in lists. Can be "-", "*" or "+".
Expand Down Expand Up @@ -108,6 +109,8 @@ def create_arguments(filename, file, config_file,
The number of times the horizontal rule character will be repeated. The number of times the horizontal rule character will be repeated.
:param max_line_length: :param max_line_length:
The maximum line length allowed. The maximum line length allowed.
:param check_links:
Checks if links to headings and files in markdown are valid.
""" """
remark_configs_settings = { remark_configs_settings = {
'bullet': bullets, # - or * 'bullet': bullets, # - or *
Expand Down Expand Up @@ -136,13 +139,16 @@ def create_arguments(filename, file, config_file,
# Remove { and } as remark adds them on its own # Remove { and } as remark adds them on its own
settings = config_json[1:-1] settings = config_json[1:-1]


args = ['--no-color', '--quiet', '--setting', settings] args = [filename, '--no-color', '--quiet', '--setting', settings]


if remark_configs_plugins: if remark_configs_plugins:
config_json = json.dumps(remark_configs_plugins) config_json = json.dumps(remark_configs_plugins)
plugins = 'lint=' + config_json[1:-1] plugins = 'lint=' + config_json[1:-1]
args += ['--use', plugins] args += ['--use', plugins]


if check_links:
args += ['--use', 'validate-links']

return args return args


def process_output(self, output, filename, file): def process_output(self, output, filename, file):
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"ramllint": ">=1.2.2 <1.2.4 || >=1.2.5 <1.3.0", "ramllint": ">=1.2.2 <1.2.4 || >=1.2.5 <1.3.0",
"remark-cli": "~2", "remark-cli": "~2",
"remark-lint": "~5", "remark-lint": "~5",
"remark-validate-links": "~5",
"standard": "~7", "standard": "~7",
"stylelint": "~7", "stylelint": "~7",
"stylint": "~1.5.9", "stylint": "~1.5.9",
Expand Down
28 changes: 28 additions & 0 deletions tests/markdown/MarkdownBearTest.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@
2. nopqrstuvwxyz 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, MarkdownBearTest = verify_local_bear(MarkdownBear,
valid_files=(test_file2,), valid_files=(test_file2,),
invalid_files=(test_file1,)) invalid_files=(test_file1,))
Expand Down Expand Up @@ -55,3 +65,21 @@ def test_invalid_message(self):
'Line must be at most 10 characters' 'Line must be at most 10 characters'
' maximum-line-length remark-lint') ' maximum-line-length remark-lint')
self.assertEqual(results[0].severity, RESULT_SEVERITY.NORMAL) 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.