Skip to content

Commit e05ec27

Browse files
authored
Ignore frontmatter in MarkdownCheck (#574)
Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
1 parent d6e6688 commit e05ec27

3 files changed

Lines changed: 24 additions & 0 deletions

File tree

custom-checks/checkstyle/src/main/java/org/openhab/tools/analysis/checkstyle/readme/MarkdownCheck.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@
1515
import static org.openhab.tools.analysis.checkstyle.api.CheckConstants.*;
1616

1717
import java.io.File;
18+
import java.util.List;
1819

1920
import org.openhab.tools.analysis.checkstyle.api.AbstractStaticCheck;
2021

2122
import com.puppycrawl.tools.checkstyle.api.CheckstyleException;
2223
import com.puppycrawl.tools.checkstyle.api.FileText;
24+
import com.vladsch.flexmark.ext.yaml.front.matter.YamlFrontMatterExtension;
2325
import com.vladsch.flexmark.parser.Parser;
2426
import com.vladsch.flexmark.util.ast.Node;
2527
import com.vladsch.flexmark.util.data.MutableDataSet;
@@ -54,6 +56,7 @@ private void checkReadMe(FileText fileText) {
5456
MutableDataSet options = new MutableDataSet();
5557
// By setting this option to true, the parser provides line numbers in the original markdown text for each node
5658
options.set(Parser.TRACK_DOCUMENT_LINES, true);
59+
options.set(Parser.EXTENSIONS, List.of(YamlFrontMatterExtension.create()));
5760

5861
Node readmeMarkdownNode = parseMarkdown(fileText, options);
5962
// CallBack is used in order to use the protected log method of the AbstractStaticCheck in the Visitor

custom-checks/checkstyle/src/test/java/org/openhab/tools/analysis/checkstyle/test/MarkdownCheckTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,11 @@ public void testDocFolderWrong() throws Exception {
249249
verifyMarkDownFile("testDocFolderWrong", expectedMessages);
250250
}
251251

252+
@Test
253+
public void testFrontMatterIgnored() throws Exception {
254+
verifyMarkDownFile("testFrontMatterIgnored", noMessagesExpected());
255+
}
256+
252257
private void createValidConfig() {
253258
config = createModuleConfig(MarkdownCheck.class);
254259
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
title: Sample document
3+
description: |
4+
# not a header
5+
* not a list
6+
```
7+
not code formatting
8+
```
9+
children:
10+
- ["doc/test1", "Test1"]
11+
- ["doc/test2", "Test2"]
12+
---
13+
14+
# Actual Header
15+
16+
Body text.

0 commit comments

Comments
 (0)