Skip to content

Commit

Permalink
Merge pull request #2829 from csordasmarton/markdownlint_support
Browse files Browse the repository at this point in the history
[report-converter] Support Markdownlint
  • Loading branch information
csordasmarton authored Aug 31, 2020
2 parents c2d6a60 + 212f285 commit b16365c
Show file tree
Hide file tree
Showing 12 changed files with 378 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ The following tools are supported:
| **JavaScript** | [ESLint](/tools/report-converter/README.md#eslint) |
| **TypeScript** | [TSLint](/tools/report-converter/README.md#tslint) |
| **Go** | [Golint](/tools/report-converter/README.md#golint) |
| **Markdown** | [Markdownlint](/tools/report-converter/README.md#markdownlint) |


For details see
Expand Down
1 change: 1 addition & 0 deletions docs/supported_code_analyzers.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ CodeChecker result directory which can be stored to a CodeChecker server.
| **Go** | [Golint](/tools/report-converter/README.md#golint) ||
| | [Staticcheck](https://staticcheck.io/) ||
| | [go-critic](https://github.com/go-critic/go-critic) ||
| **Markdown** | [Markdownlint](https://github.com/markdownlint/markdownlint) ||

## Clang Sanitizers
| Name | Support storage of analyzer results |
Expand Down
24 changes: 24 additions & 0 deletions tools/report-converter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ a CodeChecker server.
* [TSLint](#tslint)
* [Golint](#golint)
* [Pyflakes](#pyflakes)
* [Markdownlint](#markdownlint)
* [License](#license)

## Install guide
Expand Down Expand Up @@ -82,6 +83,7 @@ Supported analyzers:
eslint - ESLint, https://eslint.org/
fbinfer - Facebook Infer, https://fbinfer.com
golint - Golint, https://github.com/golang/lint
mdl - Markdownlint, https://github.com/markdownlint/markdownlint
msan - MemorySanitizer, https://clang.llvm.org/docs/MemorySanitizer.html
pyflakes - Pyflakes, https://github.com/PyCQA/pyflakes
pylint - Pylint, https://www.pylint.org
Expand Down Expand Up @@ -362,6 +364,28 @@ report-converter -t golint -o ./codechecker_golint_reports ./golint_reports.out
CodeChecker store ./codechecker_golint_reports -n golint
```
## [Markdownlint](https://github.com/markdownlint/markdownlint)
[Markdownlint](https://github.com/markdownlint/markdownlint) is a static
analysis tool for markdown files.
The recommended way of running Markdownlint is to redirect the output to a file
and give this file to the report converter tool.
The following example shows you how to run Markdownlint and store the results
found by Markdownlint to the CodeChecker database.
```sh
# Run Markdownlint.
mdl /path/to/your/project > ./mdl_reports.out

# Use 'report-converter' to create a CodeChecker report directory from the
# analyzer result of Markdownlint.
report-converter -t mdl -o ./codechecker_mdl_reports ./mdl_reports.out

# Store Markdownlint reports with CodeChecker.
CodeChecker store ./codechecker_mdl_reports -n mdl
```
## License
The project is licensed under Apache License v2.0 with LLVM Exceptions.
Expand Down
5 changes: 4 additions & 1 deletion tools/report-converter/codechecker_report_converter/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
GolintAnalyzerResult # noqa
from codechecker_report_converter.pyflakes.analyzer_result import \
PyflakesAnalyzerResult # noqa
from codechecker_report_converter.markdownlint.analyzer_result import \
MarkdownlintAnalyzerResult # noqa


LOG = logging.getLogger('ReportConverter')
Expand Down Expand Up @@ -83,7 +85,8 @@ class RawDescriptionDefaultHelpFormatter(
TSANAnalyzerResult.TOOL_NAME: TSANAnalyzerResult,
TSLintAnalyzerResult.TOOL_NAME: TSLintAnalyzerResult,
UBSANAnalyzerResult.TOOL_NAME: UBSANAnalyzerResult,
SpotBugsAnalyzerResult.TOOL_NAME: SpotBugsAnalyzerResult
SpotBugsAnalyzerResult.TOOL_NAME: SpotBugsAnalyzerResult,
MarkdownlintAnalyzerResult.TOOL_NAME: MarkdownlintAnalyzerResult
}

supported_metadata_keys = ["analyzer_command", "analyzer_version"]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# -------------------------------------------------------------------------
#
# Part of the CodeChecker project, under the Apache License v2.0 with
# LLVM Exceptions. See LICENSE for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
# -------------------------------------------------------------------------
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# -------------------------------------------------------------------------
#
# Part of the CodeChecker project, under the Apache License v2.0 with
# LLVM Exceptions. See LICENSE for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
# -------------------------------------------------------------------------

from codechecker_report_converter.analyzer_result import AnalyzerResult

from .output_parser import MarkdownlintParser
from ..plist_converter import PlistConverter


class MarkdownlintAnalyzerResult(AnalyzerResult):
""" Transform analyzer result of Markdownlint. """

TOOL_NAME = 'mdl'
NAME = 'Markdownlint'
URL = 'https://github.com/markdownlint/markdownlint'

def parse(self, analyzer_result):
""" Creates plist data from the given analyzer results. """
parser = MarkdownlintParser(analyzer_result)

content = self._get_analyzer_result_file_content(analyzer_result)
if not content:
return

messages = parser.parse_messages(content)

plist_converter = PlistConverter(self.TOOL_NAME)
plist_converter.add_messages(messages)
return plist_converter.get_plist_results()
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# -------------------------------------------------------------------------
#
# Part of the CodeChecker project, under the Apache License v2.0 with
# LLVM Exceptions. See LICENSE for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
# -------------------------------------------------------------------------

import logging
import os
import re

from ..output_parser import Message, BaseParser

LOG = logging.getLogger('ReportConverter')


class MarkdownlintParser(BaseParser):
""" Parser for Markdownlint output. """

def __init__(self, analyzer_result):
super(MarkdownlintParser, self).__init__()

self.analyzer_result = analyzer_result

# Regex for parsing a clang-tidy message.
self.message_line_re = re.compile(
# File path followed by a ':'.
r'^(?P<path>[\S ]+?):'
# Line number followed by a ':'.
r'(?P<line>\d+?): '
# Checker name.
r'(?P<checker>[\S]+) '
# Message.
r'(?P<message>[\S \t]+)\s*')

def parse_message(self, it, line):
"""Parse the given line.
Returns a (message, next_line) pair or throws a StopIteration.
The message could be None.
"""
match = self.message_line_re.match(line)
if match is None:
return None, next(it)

file_path = os.path.normpath(
os.path.join(os.path.dirname(self.analyzer_result),
match.group('path')))

message = Message(
file_path,
int(match.group('line')),
0,
match.group('message').strip(),
match.group('checker').strip())

try:
return message, next(it)
except StopIteration:
return message, ''
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
all:
# There is a docker image which can be used to install and execute
# markdownlint easier:
# docker run --rm -v ${PWD}:/data markdownlint/markdownlint .
mdl ./files/readme.md > readme.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# My first section
This is my first section.

# My second section
This is my second section.
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>diagnostics</key>
<array>
<dict>
<key>category</key>
<string>unknown</string>
<key>check_name</key>
<string>MD022</string>
<key>description</key>
<string>Headers should be surrounded by blank lines</string>
<key>issue_hash_content_of_line_in_context</key>
<string>217c9bcb51e264ba7a3e4e8f36e02cca</string>
<key>location</key>
<dict>
<key>col</key>
<integer>0</integer>
<key>file</key>
<integer>0</integer>
<key>line</key>
<integer>1</integer>
</dict>
<key>path</key>
<array>
<dict>
<key>depth</key>
<integer>0</integer>
<key>kind</key>
<string>event</string>
<key>location</key>
<dict>
<key>col</key>
<integer>0</integer>
<key>file</key>
<integer>0</integer>
<key>line</key>
<integer>1</integer>
</dict>
<key>message</key>
<string>Headers should be surrounded by blank lines</string>
</dict>
</array>
<key>type</key>
<string>mdl</string>
</dict>
<dict>
<key>category</key>
<string>unknown</string>
<key>check_name</key>
<string>MD022</string>
<key>description</key>
<string>Headers should be surrounded by blank lines</string>
<key>issue_hash_content_of_line_in_context</key>
<string>af90f99a0696affbe85d602fbad3159c</string>
<key>location</key>
<dict>
<key>col</key>
<integer>0</integer>
<key>file</key>
<integer>0</integer>
<key>line</key>
<integer>4</integer>
</dict>
<key>path</key>
<array>
<dict>
<key>depth</key>
<integer>0</integer>
<key>kind</key>
<string>event</string>
<key>location</key>
<dict>
<key>col</key>
<integer>0</integer>
<key>file</key>
<integer>0</integer>
<key>line</key>
<integer>4</integer>
</dict>
<key>message</key>
<string>Headers should be surrounded by blank lines</string>
</dict>
</array>
<key>type</key>
<string>mdl</string>
</dict>
<dict>
<key>category</key>
<string>unknown</string>
<key>check_name</key>
<string>MD025</string>
<key>description</key>
<string>Multiple top level headers in the same document</string>
<key>issue_hash_content_of_line_in_context</key>
<string>4ef5dcbbe4dad37d171efd30bf4c40de</string>
<key>location</key>
<dict>
<key>col</key>
<integer>0</integer>
<key>file</key>
<integer>0</integer>
<key>line</key>
<integer>4</integer>
</dict>
<key>path</key>
<array>
<dict>
<key>depth</key>
<integer>0</integer>
<key>kind</key>
<string>event</string>
<key>location</key>
<dict>
<key>col</key>
<integer>0</integer>
<key>file</key>
<integer>0</integer>
<key>line</key>
<integer>4</integer>
</dict>
<key>message</key>
<string>Multiple top level headers in the same document</string>
</dict>
</array>
<key>type</key>
<string>mdl</string>
</dict>
</array>
<key>files</key>
<array>
<string>files/readme.md</string>
</array>
<key>metadata</key>
<dict>
<key>analyzer</key>
<dict>
<key>name</key>
<string>mdl</string>
</dict>
<key>generated_by</key>
<dict>
<key>name</key>
<string>report-converter</string>
<key>version</key>
<string>x.y.z</string>
</dict>
</dict>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
./files/readme.md:1: MD022 Headers should be surrounded by blank lines
./files/readme.md:4: MD022 Headers should be surrounded by blank lines
./files/readme.md:4: MD025 Multiple top level headers in the same document

A detailed description of the rules is available at https://github.com/markdownlint/markdownlint/blob/master/docs/RULES.md
Loading

0 comments on commit b16365c

Please sign in to comment.