-
Notifications
You must be signed in to change notification settings - Fork 388
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2829 from csordasmarton/markdownlint_support
[report-converter] Support Markdownlint
- Loading branch information
Showing
12 changed files
with
378 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
tools/report-converter/codechecker_report_converter/markdownlint/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
# | ||
# ------------------------------------------------------------------------- |
34 changes: 34 additions & 0 deletions
34
tools/report-converter/codechecker_report_converter/markdownlint/analyzer_result.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
61 changes: 61 additions & 0 deletions
61
tools/report-converter/codechecker_report_converter/markdownlint/output_parser.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, '' |
5 changes: 5 additions & 0 deletions
5
tools/report-converter/tests/unit/mdl_output_test_files/Makefile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
5 changes: 5 additions & 0 deletions
5
tools/report-converter/tests/unit/mdl_output_test_files/files/readme.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
151 changes: 151 additions & 0 deletions
151
tools/report-converter/tests/unit/mdl_output_test_files/readme.expected.plist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
5 changes: 5 additions & 0 deletions
5
tools/report-converter/tests/unit/mdl_output_test_files/readme.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.