Skip to content

Commit 3bbf205

Browse files
authored
MarkdownCheck improvements (#432)
1 parent 235666c commit 3bbf205

14 files changed

Lines changed: 25 additions & 117 deletions

File tree

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

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
import java.io.File;
1818

19-
import org.eclipse.pde.core.build.IBuild;
20-
import org.eclipse.pde.core.build.IBuildEntry;
2119
import org.openhab.tools.analysis.checkstyle.api.AbstractStaticCheck;
2220

2321
import com.puppycrawl.tools.checkstyle.api.CheckstyleException;
@@ -34,53 +32,26 @@
3432
* <li>missing empty lines before and after lists.
3533
* </ul>
3634
*
37-
* Checks the build.properties for:
38-
* <ul>
39-
* <li>the README.MD shouldn't be added in build.properties.
40-
* <li>the doc folder shouldn't be added in build.properties.
41-
* </ul>
4235
* <a href="https://www.openhab.org/docs/developer/guidelines.html">openHAB Coding Guidelines</a>
4336
*
4437
* @author Erdoan Hadzhiyusein - Initial contribution
4538
* @author Lyubomir Papazov - Change the Markdown parser to flexmark
4639
*/
4740
public class MarkdownCheck extends AbstractStaticCheck {
48-
private static final String ADDED_README_FILE_IN_BUILD_PROPERTIES_MSG = "README.MD file must not be added to the bin.includes property";
49-
private static final String ADDED_DOC_FOLDER_IN_BUILD_PROPERTIES_MSG = "The doc folder must not be added to the bin.includes property";
50-
private static final String DOC_FOLDER_NAME = "doc";
5141

5242
public MarkdownCheck() {
53-
setFileExtensions(MARKDONW_EXTENSION, PROPERTIES_EXTENSION);
43+
setFileExtensions(MARKDONW_EXTENSION);
5444
}
5545

5646
@Override
5747
protected void processFiltered(File file, FileText fileText) throws CheckstyleException {
5848
switch (file.getName()) {
59-
case BUILD_PROPERTIES_FILE_NAME:
60-
checkBuildProperties(fileText);
61-
break;
6249
case README_MD_FILE_NAME:
6350
checkReadMe(fileText);
6451
break;
6552
}
6653
}
6754

68-
private void checkBuildProperties(FileText fileText) throws CheckstyleException {
69-
// The check will not log an errors if build properties file is missing
70-
// We have other check regarding this case - RequiredFilesCheck
71-
IBuild buildPropertiesEntry = parseBuildProperties(fileText);
72-
boolean isReadMeIncluded = checkBuildPropertiesEntry(buildPropertiesEntry, BIN_INCLUDES_PROPERTY_NAME,
73-
README_MD_FILE_NAME);
74-
if (isReadMeIncluded) {
75-
log(0, ADDED_README_FILE_IN_BUILD_PROPERTIES_MSG);
76-
}
77-
boolean isDocFolderIncluded = checkBuildPropertiesEntry(buildPropertiesEntry, BIN_INCLUDES_PROPERTY_NAME,
78-
DOC_FOLDER_NAME);
79-
if (isDocFolderIncluded) {
80-
log(0, ADDED_DOC_FOLDER_IN_BUILD_PROPERTIES_MSG);
81-
}
82-
}
83-
8455
private void checkReadMe(FileText fileText) {
8556
MutableDataSet options = new MutableDataSet();
8657
// By setting this option to true, the parser provides line numbers in the original markdown text for each node
@@ -97,13 +68,4 @@ public void log(int line, String message) {
9768
MarkdownVisitor visitor = new MarkdownVisitor(callBack, fileText);
9869
visitor.visit(readmeMarkdownNode);
9970
}
100-
101-
/**
102-
* Checks whether the given value is added in the build.properties file.
103-
*/
104-
private boolean checkBuildPropertiesEntry(IBuild buildPropertiesFile, String property, String value)
105-
throws CheckstyleException {
106-
IBuildEntry binIncludes = buildPropertiesFile.getEntry(property);
107-
return binIncludes != null && binIncludes.contains(value);
108-
}
10971
}

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,13 @@ private void checkEmptyLineAfterList(ListBlock listBlock) {
147147
if (isListEnd) {
148148
String[] lastListItemlines = lastListItemContent.getChars().toString().split(REGEX_NEW_LINES);
149149
if (lastListItemlines.length > 1) {
150-
// Log the one-based line where there is an empty line
151-
callback.log(lastListItemContent.getLineNumber(), EMPTY_LINE_AFTER_LIST_MSG);
150+
for (int i = 1; i < lastListItemlines.length; i++) {
151+
if (!lastListItemlines[i].startsWith(" ")) {
152+
// Log the one-based line where there is an empty line
153+
callback.log(lastListItemContent.getLineNumber(), EMPTY_LINE_AFTER_LIST_MSG);
154+
break;
155+
}
156+
}
152157
}
153158
}
154159
}

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

Lines changed: 5 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import static org.openhab.tools.analysis.checkstyle.api.CheckConstants.README_MD_FILE_NAME;
1717

1818
import java.io.File;
19-
import java.io.IOException;
2019

2120
import org.junit.jupiter.api.BeforeEach;
2221
import org.junit.jupiter.api.Test;
@@ -32,8 +31,6 @@
3231
* @author Lyubomir Papazov - Added more tests
3332
*/
3433
public class MarkdownCheckTest extends AbstractStaticCheckTest {
35-
private static final String ADDED_README_IN_BUILD_PROPERTIES_MSG = "README.MD file must not be added to the bin.includes property";
36-
private static final String ADDED_DOC_FOLDER_IN_BUILD_PROPERTIES_MSG = "The doc folder must not be added to the bin.includes property";
3734
private DefaultConfiguration config;
3835

3936
@BeforeEach
@@ -86,6 +83,11 @@ public void testEmptyLineAfterList() throws Exception {
8683
verifyMarkDownFile("testEmptyLineAfterList", expectedMessages);
8784
}
8885

86+
@Test
87+
public void testListWithParagraphs() throws Exception {
88+
verifyMarkDownFile("testListWithParagraphs", noMessagesExpected());
89+
}
90+
8991
@Test
9092
public void testListAtEndOfFile() throws Exception {
9193
verifyMarkDownFile("testListAtEndOfFile", noMessagesExpected());
@@ -225,40 +227,6 @@ public void testLinkAsHeader() throws Exception {
225227
verifyMarkDownFile("testLinkAsHeader", noMessagesExpected());
226228
}
227229

228-
@Test
229-
public void testReadMeAddedInBuildProperties() throws Exception {
230-
String[] expectedMessages = generateExpectedMessages(0, ADDED_README_IN_BUILD_PROPERTIES_MSG);
231-
String testDirectoryName = "testAddedReadMeInBuildProperties";
232-
233-
// The message is logged for the build.properties file
234-
verifyBuildProperties(expectedMessages, testDirectoryName);
235-
}
236-
237-
@Test
238-
public void testAddedDummyDocInBuildProperties() throws Exception {
239-
String testDirectoryName = "testAddedDummyDocInBuildProperties";
240-
verifyBuildProperties(noMessagesExpected(), testDirectoryName);
241-
}
242-
243-
@Test
244-
public void testDocFolderAddedInBuildProperties() throws Exception {
245-
String[] expectedMessages = generateExpectedMessages(0, ADDED_DOC_FOLDER_IN_BUILD_PROPERTIES_MSG);
246-
String testDirectoryName = "testAddedDocFolderInBuildProperties";
247-
248-
// The message is logged for the build.properties file
249-
verifyBuildProperties(expectedMessages, testDirectoryName);
250-
}
251-
252-
@Test
253-
public void testAddedReadmeAndDocInBuildProperties() throws Exception {
254-
String[] expectedMessages = generateExpectedMessages(0, ADDED_README_IN_BUILD_PROPERTIES_MSG, 0,
255-
ADDED_DOC_FOLDER_IN_BUILD_PROPERTIES_MSG);
256-
String testDirectoryName = "testAddedReadmeAndDocInBuildProperties";
257-
258-
// The message is logged for the build.properties file
259-
verifyBuildProperties(expectedMessages, testDirectoryName);
260-
}
261-
262230
@Test
263231
public void testOpenhabBindingExec() throws Exception {
264232
String testDirectoryName = "org.openhab.binding.exec";
@@ -281,13 +249,6 @@ public void testDocFolderWrong() throws Exception {
281249
verifyMarkDownFile("testDocFolderWrong", expectedMessages);
282250
}
283251

284-
private void verifyBuildProperties(String[] expectedMessages, String testDirectoryName)
285-
throws IOException, Exception {
286-
String testDirectoryAbsolutePath = getPath(testDirectoryName);
287-
String messageFilePath = testDirectoryAbsolutePath + File.separator + "build.properties";
288-
verify(createChecker(config), messageFilePath, expectedMessages);
289-
}
290-
291252
private void createValidConfig() {
292253
config = createModuleConfig(MarkdownCheck.class);
293254
}

custom-checks/checkstyle/src/test/resources/checkstyle/markdownCheckTest/testAddedDocFolderInBuildProperties/build.properties

Lines changed: 0 additions & 3 deletions
This file was deleted.

custom-checks/checkstyle/src/test/resources/checkstyle/markdownCheckTest/testAddedDocFolderInBuildProperties/doc/dummyFile.txt

Whitespace-only changes.

custom-checks/checkstyle/src/test/resources/checkstyle/markdownCheckTest/testAddedDummyDocInBuildProperties/build.properties

Lines changed: 0 additions & 4 deletions
This file was deleted.

custom-checks/checkstyle/src/test/resources/checkstyle/markdownCheckTest/testAddedDummyDocInBuildProperties/dummydoc.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

custom-checks/checkstyle/src/test/resources/checkstyle/markdownCheckTest/testAddedReadMeInBuildProperties/README.md

Lines changed: 0 additions & 2 deletions
This file was deleted.

custom-checks/checkstyle/src/test/resources/checkstyle/markdownCheckTest/testAddedReadMeInBuildProperties/build.properties

Lines changed: 0 additions & 8 deletions
This file was deleted.

custom-checks/checkstyle/src/test/resources/checkstyle/markdownCheckTest/testAddedReadmeAndDocInBuildProperties/README.md

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)