Skip to content

Commit

Permalink
MarkdownBear: Add remark-validate-links plugin
Browse files Browse the repository at this point in the history
Remark plugin to validate if links to headings and files in markdown point to existing things.

Closes coala#924
  • Loading branch information
namanyadav12 committed Jan 8, 2017
1 parent 353bce2 commit 2fd6c8d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 6 deletions.
11 changes: 6 additions & 5 deletions bears/markdown/MarkdownBear.py
Expand Up @@ -28,7 +28,7 @@ class MarkdownBear:

_output_regex = re.compile(
r'\s*(?P<line>\d+):(?P<column>\d+)'
r'\s*(?P<severity>warning)\s*(?P<message>.*)')
r'\s*(?P<severity>warning)\s*(?P<message>(?:\S|\s(?!\s))*)')

@staticmethod
@deprecate_settings(bullets='markdown_bullets',
Expand Down Expand Up @@ -126,16 +126,17 @@ def create_arguments(filename, file, config_file,
'ruleSpaces': horizontal_rule_spaces, # Bool
'ruleRepetition': horizontal_rule_repeat, # int
}
remark_configs_plugins = {
remark_lint_configs = {
'maximumLineLength': max_line_length # int
}

config_json = json.dumps(remark_configs_settings)
# Remove { and } as remark adds them on its own
settings = config_json[1:-1]
config_json = json.dumps(remark_configs_plugins)
plugins = 'lint=' + config_json[1:-1]
return '--no-color', '--quiet', '--setting', settings, '--use', plugins
config_json = json.dumps(remark_lint_configs)
lint = 'lint=' + config_json[1:-1]
return (filename, '--no-color', '--quiet', '--setting', settings,
'--use', lint, '--use', 'validate-links')

def process_output(self, output, filename, file):
stdout, stderr = output
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -17,6 +17,7 @@
"postcss-cli": "~2",
"remark-cli": "~2",
"remark-lint": ">=5.1.0",
"remark-validate-links": "~5.0.0",
"tslint": "~3",
"typescript": ">=1.7.3",
"ramllint": "~1.2.2",
Expand Down
35 changes: 34 additions & 1 deletion tests/markdown/MarkdownBearTest.py
@@ -1,5 +1,10 @@
import unittest
from queue import Queue

from bears.markdown.MarkdownBear import MarkdownBear
from coalib.testing.LocalBearTestHelper import verify_local_bear
from coalib.testing.LocalBearTestHelper import verify_local_bear, execute_bear
from coalib.settings.Section import Section
from coala_utils.ContextManagers import prepare_file

test_file1 = """1. abc
1. def
Expand All @@ -14,6 +19,16 @@
2. nopqrstuvwxyz
"""

test_file4 = """# Hello
Read more [This does not exist](#world).
"""

test_file5 = """# World
Read more [This exists](#world).
"""

MarkdownBearTest = verify_local_bear(MarkdownBear,
valid_files=(test_file2,),
invalid_files=(test_file1,))
Expand All @@ -29,3 +44,21 @@
valid_files=(test_file2,),
invalid_files=(test_file3,),
settings={'max_line_length': 10})

MarkdownBearValidateLinksTest = verify_local_bear(
MarkdownBear,
valid_files=(test_file5,),
invalid_files=(test_file4,))


class MarkdownBearValidateLinksMessageTest(unittest.TestCase):

def setUp(self):
self.uut = MarkdownBear(Section('name'), Queue())

def test_info(self):
content = test_file4.splitlines()
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`')

0 comments on commit 2fd6c8d

Please sign in to comment.