From 1a620ba131fdc258e756fcde946870a7a46233a3 Mon Sep 17 00:00:00 2001 From: naveentata Date: Mon, 17 Jul 2017 03:48:41 +0000 Subject: [PATCH] Add MarkdownfmtBear It suggests better formatting in markdown files. Closes https://github.com/coala/coala-bears/issues/1538 --- .ci/deps.sh | 1 + bears/markdown/MarkdownfmtBear.py | 28 +++++++++++++++++++++++ tests/markdown/MarkdownfmtBearTest.py | 33 +++++++++++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 bears/markdown/MarkdownfmtBear.py create mode 100644 tests/markdown/MarkdownfmtBearTest.py diff --git a/.ci/deps.sh b/.ci/deps.sh index d3b544702b..b29d7cac80 100644 --- a/.ci/deps.sh +++ b/.ci/deps.sh @@ -19,6 +19,7 @@ go get -u sourcegraph.com/sqs/goreturns go get -u golang.org/x/tools/cmd/gotype go get -u github.com/kisielk/errcheck go get -u github.com/BurntSushi/toml/cmd/tomlv +go get -u github.com/shurcooL/markdownfmt # Ruby commands bundle install --path=vendor/bundle --binstubs=vendor/bin --jobs=8 --retry=3 diff --git a/bears/markdown/MarkdownfmtBear.py b/bears/markdown/MarkdownfmtBear.py new file mode 100644 index 0000000000..9b667624ce --- /dev/null +++ b/bears/markdown/MarkdownfmtBear.py @@ -0,0 +1,28 @@ +from coalib.bearlib.abstractions.Linter import linter +from dependency_management.requirements.GoRequirement import GoRequirement + + +@linter(executable='markdownfmt', + output_format='corrected', + result_message='Formatting can be improved.', + use_stdin=True) +class MarkdownfmtBear: + """ + Check and correct formatting of Markdown files using ``mardownfmt``. + Basic checks like alignment, indendation are provided. + Note that MarkdownfmtBear works only with pure Markdown files(shouldn't + contain front matter like TOML, JS etc). + """ + LANGUAGES = {'Markdown'} + REQUIREMENTS = {GoRequirement( + package='github.com/shurcooL/markdownfmt')} + AUTHORS = {'The coala developers'} + AUTHORS_EMAILS = {'coala-devel@googlegroups.com'} + LICENSE = 'AGPL-3.0' + CAN_FIX = {'Formatting'} + ASCIINEMA_URL = 'https://asciinema.org/a/396jhuyw1j0c1l2i9p09wlhye' + SEE_MORE = 'https://github.com/shurcooL/markdownfmt' + + @staticmethod + def create_arguments(filename, file, config_file): + return list() diff --git a/tests/markdown/MarkdownfmtBearTest.py b/tests/markdown/MarkdownfmtBearTest.py new file mode 100644 index 0000000000..11d78b10a4 --- /dev/null +++ b/tests/markdown/MarkdownfmtBearTest.py @@ -0,0 +1,33 @@ +from coalib.testing.LocalBearTestHelper import verify_local_bear + +from bears.markdown.MarkdownfmtBear import MarkdownfmtBear + + +header_in_file1 = """ +MarkdownBear +===== + +""" + +header_out_file1 = """ +MarkdownBear +============ + +""" + +spacing_in_file2 = """ + +This is a test file. + +""" + +spacing_out_file2 = """ + +This is a test file. + +""" + +MarkdownfmtBear = verify_local_bear( + MarkdownfmtBear, + valid_files=(header_in_file1, spacing_in_file2,), + invalid_files=(header_out_file1, spacing_out_file2,))