From 123154512e8c9c49a3e597dc1aaf42ad40282f57 Mon Sep 17 00:00:00 2001 From: Marcel Schneider Date: Sun, 31 Oct 2021 14:51:36 +0100 Subject: [PATCH 01/16] add parser for CodeChecker files CodeChecker parses *.plist files from clang-tidy and clang static analysis into a human readable text file. Wich is also easier to parse than *.plist files --- .../analysis/parser/CodeCheckerParser.java | 59 +++++++++++++ .../registry/CodeCheckerDescriptor.java | 22 +++++ .../analysis/registry/ParserRegistry.java | 1 + .../CodeCheckerParserWithLinuxPathsTest.java | 55 ++++++++++++ ...CodeCheckerParserWithWindowsPathsTest.java | 73 ++++++++++++++++ .../parser/CodeChecker_with_linux_paths.txt | 59 +++++++++++++ .../parser/CodeChecker_with_windows_paths.txt | 86 +++++++++++++++++++ 7 files changed, 355 insertions(+) create mode 100644 src/main/java/edu/hm/hafner/analysis/parser/CodeCheckerParser.java create mode 100644 src/main/java/edu/hm/hafner/analysis/registry/CodeCheckerDescriptor.java create mode 100644 src/test/java/edu/hm/hafner/analysis/parser/CodeCheckerParserWithLinuxPathsTest.java create mode 100644 src/test/java/edu/hm/hafner/analysis/parser/CodeCheckerParserWithWindowsPathsTest.java create mode 100644 src/test/resources/edu/hm/hafner/analysis/parser/CodeChecker_with_linux_paths.txt create mode 100644 src/test/resources/edu/hm/hafner/analysis/parser/CodeChecker_with_windows_paths.txt diff --git a/src/main/java/edu/hm/hafner/analysis/parser/CodeCheckerParser.java b/src/main/java/edu/hm/hafner/analysis/parser/CodeCheckerParser.java new file mode 100644 index 000000000..a1406d26f --- /dev/null +++ b/src/main/java/edu/hm/hafner/analysis/parser/CodeCheckerParser.java @@ -0,0 +1,59 @@ +package edu.hm.hafner.analysis.parser; + +import java.util.Optional; +import java.util.regex.Matcher; + + +import edu.hm.hafner.analysis.Issue; +import edu.hm.hafner.analysis.IssueBuilder; +import edu.hm.hafner.analysis.LookaheadParser; +import edu.hm.hafner.analysis.Severity; +import edu.hm.hafner.util.LookaheadStream; + +/** + * A parser for the clang-tidy static analysis warnings parsed by Codechecker. + * + * Codechecker parses the *.plist files and converts it into plain text file. + * + * Better for human readers and for using grep and diff + * It also puts the human-readable Severity at the start of a line. + * + */ +public class CodeCheckerParser extends LookaheadParser { + private static final long serialVersionUID = -3015592762345283582L; + private static final String CODE_CHECKER_DEFECT_PATTERN = + "^\\[(CRITICAL|HIGH|MEDIUM|LOW)\\] (.+):(\\d+):(\\d+): (.*?) \\[([^\\s]*?)\\]$"; + + /** + * Creates a new instance of {@link CodeCheckerParser}. + */ + public CodeCheckerParser() { + super(CODE_CHECKER_DEFECT_PATTERN); + } + + @Override + protected Optional createIssue(final Matcher matcher, final LookaheadStream lookahead, + final IssueBuilder builder) { + Severity priority; + if (matcher.group(1).contains("CRITICAL")) { + priority = Severity.ERROR; + } + else if (matcher.group(1).contains("HIGH")) { + priority = Severity.WARNING_HIGH; + } + else if (matcher.group(1).contains("MEDIUM")){ + priority = Severity.WARNING_NORMAL; + } + else { + priority = Severity.WARNING_LOW; + } + return builder.setFileName(matcher.group(2)) + .setSeverity(priority) + .setLineStart(matcher.group(3)) + .setColumnStart(matcher.group(4)) + .setCategory(matcher.group(6)) + .setMessage(matcher.group(5)) + .setType("Warning") + .buildOptional(); + } +} diff --git a/src/main/java/edu/hm/hafner/analysis/registry/CodeCheckerDescriptor.java b/src/main/java/edu/hm/hafner/analysis/registry/CodeCheckerDescriptor.java new file mode 100644 index 000000000..ef64d4137 --- /dev/null +++ b/src/main/java/edu/hm/hafner/analysis/registry/CodeCheckerDescriptor.java @@ -0,0 +1,22 @@ +package edu.hm.hafner.analysis.registry; + +import edu.hm.hafner.analysis.IssueParser; +import edu.hm.hafner.analysis.parser.CodeCheckerParser; + +/** + * A descriptor for the Clang-Tidy compiler. + * + */ +class CodeCheckerDescriptor extends ParserDescriptor { + private static final String ID = "codechecker"; + private static final String NAME = "CodeChecker"; + + CodeCheckerDescriptor() { + super(ID, NAME); + } + + @Override + public IssueParser createParser(final Option... options) { + return new CodeCheckerParser(); + } +} diff --git a/src/main/java/edu/hm/hafner/analysis/registry/ParserRegistry.java b/src/main/java/edu/hm/hafner/analysis/registry/ParserRegistry.java index 9f04bcf0e..f89cef979 100644 --- a/src/main/java/edu/hm/hafner/analysis/registry/ParserRegistry.java +++ b/src/main/java/edu/hm/hafner/analysis/registry/ParserRegistry.java @@ -49,6 +49,7 @@ public class ParserRegistry { new ClangTidyDescriptor(), new CmakeDescriptor(), new CodeAnalysisDescriptor(), + new CodeCheckerDescriptor(), new CodeNarcDescriptor(), new CoolfluxChessccDescriptor(), new CpdDescriptor(), diff --git a/src/test/java/edu/hm/hafner/analysis/parser/CodeCheckerParserWithLinuxPathsTest.java b/src/test/java/edu/hm/hafner/analysis/parser/CodeCheckerParserWithLinuxPathsTest.java new file mode 100644 index 000000000..7adc4a18b --- /dev/null +++ b/src/test/java/edu/hm/hafner/analysis/parser/CodeCheckerParserWithLinuxPathsTest.java @@ -0,0 +1,55 @@ +package edu.hm.hafner.analysis.parser; + +import edu.hm.hafner.analysis.AbstractParserTest; +import edu.hm.hafner.analysis.Report; +import edu.hm.hafner.analysis.Severity; +import edu.hm.hafner.analysis.assertions.SoftAssertions; + +import static edu.hm.hafner.analysis.assertions.Assertions.*; + +class CodeCheckerParserWithLinuxPathsTest extends AbstractParserTest { + private static final String WARNING_TYPE = "Warning"; + + CodeCheckerParserWithLinuxPathsTest() { + super("CodeChecker_with_linux_paths.txt"); + } + + @Override + protected CodeCheckerParser createParser() { + return new CodeCheckerParser(); + } + + @Override + protected void assertThatIssuesArePresent(final Report annotation, final SoftAssertions softly) { + assertThat(annotation).hasSize(3); + + softly.assertThat(annotation.get(0)) + .hasLineStart(17) + .hasColumnStart(8) + .hasFileName("/path/to/projrct/csv2xlslib.Test/parsecmdTest.cpp") + .hasMessage("class 'TheFixture' defines a default destructor but does not define a copy constructor, a copy assignment operator, a move constructor or a move assignment operator") + .hasType(WARNING_TYPE) + .hasCategory("cppcoreguidelines-special-member-functions") + .hasSeverity(Severity.WARNING_LOW); + + softly.assertThat(annotation.get(1)) + .hasLineStart(425) + .hasColumnStart(33) + .hasFileName("/path/to/projrct/extern/lib/workbook.cpp") + .hasMessage("Called C++ object pointer is null") + .hasType(WARNING_TYPE) + .hasCategory("core.CallAndMessage") + .hasSeverity(Severity.WARNING_HIGH); + + softly.assertThat(annotation.get(2)) + .hasLineStart(212) + .hasColumnStart(12) + .hasFileName("/path/to/projrct/extern/lib/HPSF.cpp") + .hasMessage("'signed char' to 'int' conversion; consider casting to 'unsigned char' first.") + .hasType(WARNING_TYPE) + .hasCategory("bugprone-signed-char-misuse") + .hasSeverity(Severity.WARNING_NORMAL); + + } + +} diff --git a/src/test/java/edu/hm/hafner/analysis/parser/CodeCheckerParserWithWindowsPathsTest.java b/src/test/java/edu/hm/hafner/analysis/parser/CodeCheckerParserWithWindowsPathsTest.java new file mode 100644 index 000000000..a2fbccd36 --- /dev/null +++ b/src/test/java/edu/hm/hafner/analysis/parser/CodeCheckerParserWithWindowsPathsTest.java @@ -0,0 +1,73 @@ +package edu.hm.hafner.analysis.parser; + +import edu.hm.hafner.analysis.AbstractParserTest; +import edu.hm.hafner.analysis.Report; +import edu.hm.hafner.analysis.Severity; +import edu.hm.hafner.analysis.assertions.SoftAssertions; + +import static edu.hm.hafner.analysis.assertions.Assertions.*; + +class CodeCheckerParserWithWindowsPathsTest extends AbstractParserTest { + private static final String WARNING_TYPE = "Warning"; + + CodeCheckerParserWithWindowsPathsTest() { + super("CodeChecker_with_windows_paths.txt"); + } + + @Override + protected CodeCheckerParser createParser() { + return new CodeCheckerParser(); + } + + @Override + protected void assertThatIssuesArePresent(final Report annotation, final SoftAssertions softly) { + assertThat(annotation).hasSize(5); + + softly.assertThat(annotation.get(0)) + .hasLineStart(15) + .hasColumnStart(22) + .hasFileName("C:/path/to/project/cmake-build-debug/_deps/checked_cmd-src/Tests/ArgumentsTest.cpp") + .hasMessage("'strncpy' is deprecated: This function or variable may be unsafe. Consider using strncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.") + .hasType(WARNING_TYPE) + .hasCategory("clang-diagnostic-deprecated-declarations") + .hasSeverity(Severity.WARNING_NORMAL); + + softly.assertThat(annotation.get(1)) + .hasLineStart(283) + .hasColumnStart(22) + .hasFileName("C:/Program Files (x86)/path/to/toolchain/include/abcddef") + .hasMessage("'auto' return without trailing return type; deduced return types are a C++14 extension") + .hasType(WARNING_TYPE) + .hasCategory("clang-diagnostic-error") + .hasSeverity(Severity.ERROR); + + softly.assertThat(annotation.get(2)) + .hasLineStart(17) + .hasColumnStart(8) + .hasFileName("C:/path/to/project/csv2xlslib.Test/parsecmdTest.cpp") + .hasMessage("class 'TheFixture' defines a default destructor but does not define a copy constructor, a copy assignment operator, a move constructor or a move assignment operator") + .hasType(WARNING_TYPE) + .hasCategory("cppcoreguidelines-special-member-functions") + .hasSeverity(Severity.WARNING_LOW); + + softly.assertThat(annotation.get(3)) + .hasLineStart(49) + .hasColumnStart(8) + .hasFileName("C:/path/to/project/csv2xlslib.Test/parseCsvStreamTest.cpp") + .hasMessage("class 'Given_an_input_file_with_headline' defines a default destructor but does not define a copy constructor, a copy assignment operator, a move constructor or a move assignment operator") + .hasType(WARNING_TYPE) + .hasCategory("cppcoreguidelines-special-member-functions") + .hasSeverity(Severity.WARNING_LOW); + + softly.assertThat(annotation.get(4)) + .hasLineStart(924) + .hasColumnStart(49) + .hasFileName("C:/path/to/project/extern/lib/formula_expr.cpp") + .hasMessage("suspicious usage of 'sizeof(A*)'; pointer to aggregate") + .hasType(WARNING_TYPE) + .hasCategory("bugprone-sizeof-expression") + .hasSeverity(Severity.WARNING_HIGH); + + } + +} diff --git a/src/test/resources/edu/hm/hafner/analysis/parser/CodeChecker_with_linux_paths.txt b/src/test/resources/edu/hm/hafner/analysis/parser/CodeChecker_with_linux_paths.txt new file mode 100644 index 000000000..86c518270 --- /dev/null +++ b/src/test/resources/edu/hm/hafner/analysis/parser/CodeChecker_with_linux_paths.txt @@ -0,0 +1,59 @@ +Found no defects in csv2xlslibTest.cpp +Found no defects in TestMain.cpp +Found no defects in convertCsvTest.cpp +Found no defects in ReadCellTest.cpp +Found no defects in parsecmd.cpp +Found no defects in OutputFileNameTest.cpp +Found no defects in parseCsvStream.cpp +Found no defects in version.cpp +[LOW] /path/to/projrct/csv2xlslib.Test/parsecmdTest.cpp:17:8: class 'TheFixture' defines a default destructor but does not define a copy constructor, a copy assignment operator, a move constructor or a move assignment operator [cppcoreguidelines-special-member-functions] +struct TheFixture + ^ + +Found 1 defect(s) in parsecmdTest.cpp + +[HIGH] /path/to/projrct/extern/lib/workbook.cpp:425:33: Called C++ object pointer is null [core.CallAndMessage] + const unsigned8_t* pdata = (((CRecord*)m_pCurrentData)->GetRecordDataBuffer()) + m_ContinueIndex*MAX_RECORD_SIZE; + ^ + +Found 1 defect(s) in workbook.cpp + +[MEDIUM] /path/to/projrct/extern/lib/HPSF.cpp:212:12: 'signed char' to 'int' conversion; consider casting to 'unsigned char' first. [bugprone-signed-char-misuse] + int ret = Inflate(SUMMARY_SIZE); // this file will only be this size, ever (zero padded) + ^ + +Found 1 defect(s) in HPSF.cpp + +Found 485 defect(s) in formula.cpp + + +----==== Summary ====---- +------------------------------------- +Filename | Report count +------------------------------------- +formula.cpp | 485 +clara.hpp | 5 +Helpers.h | 3 +OutputDoc.hpp | 3 +formula_expr.cpp | 3 +XlsWorkBook.cpp | 2 +XlsWorkBook.hpp | 2 +extformat.cpp | 2 +mainCPP.cpp | 2 +parseCsvStreamTest.cpp | 2 +HPSF.cpp | 1 +catch.hpp | 1 +formula_cell.cpp | 1 +parsecmdTest.cpp | 1 +workbook.cpp | 1 +------------------------------------- +----------------------- +Severity | Report count +----------------------- +MEDIUM | 493 +LOW | 14 +HIGH | 7 +----------------------- +----=================---- +Total number of reports: 514 +----=================---- diff --git a/src/test/resources/edu/hm/hafner/analysis/parser/CodeChecker_with_windows_paths.txt b/src/test/resources/edu/hm/hafner/analysis/parser/CodeChecker_with_windows_paths.txt new file mode 100644 index 000000000..f771b5882 --- /dev/null +++ b/src/test/resources/edu/hm/hafner/analysis/parser/CodeChecker_with_windows_paths.txt @@ -0,0 +1,86 @@ +Found no defects in conversionTest.cpp +Found no defects in convertCsv.cpp +Found no defects in convertCsvTest.cpp +Found no defects in csv2xls.cpp +Found no defects in csv2xlslibTest.cpp +Found no defects in csv2xls_compound_types.cpp +Found no defects in OutputDoc.cpp +Found no defects in OutputFileNameTest.cpp +Found no defects in overnew.cpp +Found no defects in parsecmd.cpp +Found no defects in parseCsvFile.cpp +Found no defects in parseCsvStream.cpp +Found no defects in readBuffer.cpp +Found no defects in ReadCellTest.cpp +Found no defects in TestMain.cpp +Found no defects in version.cpp +[MEDIUM] C:\path\to\project\cmake-build-debug\_deps\checked_cmd-src\Tests\ArgumentsTest.cpp:15:22: 'strncpy' is deprecated: This function or variable may be unsafe. Consider using strncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. [clang-diagnostic-deprecated-declarations] + std::strncpy(result.back().get(), item.c_str(), item.size()+1); + ^ + +Found 1 defect(s) in ArgumentsTest.cpp + +[CRITICAL] C:\Program Files (x86)\path\to\toolchain\include\abcddef:283:22: 'auto' return without trailing return type; deduced return types are a C++14 extension [clang-diagnostic-error] +_NODISCARD constexpr auto _Unfancy(_Ptrty _Ptr) noexcept { // converts from a fancy pointer to a plain pointer + ^ + +Found 1 defect(s) in xstddef + +[LOW] C:\path\to\project\csv2xlslib.Test\parsecmdTest.cpp:17:8: class 'TheFixture' defines a default destructor but does not define a copy constructor, a copy assignment operator, a move constructor or a move assignment operator [cppcoreguidelines-special-member-functions] +struct TheFixture + ^ + +Found 1 defect(s) in parsecmdTest.cpp + +[LOW] C:\path\to\project\csv2xlslib.Test\parseCsvStreamTest.cpp:49:8: class 'Given_an_input_file_with_headline' defines a default destructor but does not define a copy constructor, a copy assignment operator, a move constructor or a move assignment operator [cppcoreguidelines-special-member-functions] +struct Given_an_input_file_with_headline + ^ + +Found 2 defect(s) in parseCsvStreamTest.cpp + +[HIGH] C:\path\to\project\extern\lib\formula_expr.cpp:924:49: suspicious usage of 'sizeof(A*)'; pointer to aggregate [bugprone-sizeof-expression] + arg_arr = (expression_node_t **)calloc(count, sizeof(arg_arr[0])); + ^ + + +Found 246 defect(s) in doctest.h + + +----==== Summary ====---- +------------------------------------- +Filename | Report count +------------------------------------- +doctest.h | 246 +doctest.h | 18 +xutility | 18 +doctest_fwd.h | 11 +doctest.cpp | 8 +clara.hpp | 5 +Helpers.h | 3 +OutputDoc.hpp | 3 +formula_expr.cpp | 3 +HPSF.cpp | 2 +XlsWorkBook.cpp | 2 +XlsWorkBook.hpp | 2 +extformat.cpp | 2 +parseCsvStreamTest.cpp | 2 +winnt.h | 2 +ArgumentsTest.cpp | 1 +catch.hpp | 1 +filesystem | 1 +parsecmdTest.cpp | 1 +stdio.h | 1 +xlsys.h | 1 +xstddef | 1 +------------------------------------- +----------------------- +Severity | Report count +----------------------- +MEDIUM | 254 +LOW | 36 +HIGH | 24 +CRITICAL | 20 +----------------------- +----=================---- +Total number of reports: 334 +----=================---- From 11a7526fd9f4aeaf22803a7a2390c9387cf56708 Mon Sep 17 00:00:00 2001 From: Marcel Schneider Date: Sun, 31 Oct 2021 20:44:00 +0100 Subject: [PATCH 02/16] change ID to CodeChecker --- .../edu/hm/hafner/analysis/registry/CodeCheckerDescriptor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/edu/hm/hafner/analysis/registry/CodeCheckerDescriptor.java b/src/main/java/edu/hm/hafner/analysis/registry/CodeCheckerDescriptor.java index ef64d4137..59a9ef385 100644 --- a/src/main/java/edu/hm/hafner/analysis/registry/CodeCheckerDescriptor.java +++ b/src/main/java/edu/hm/hafner/analysis/registry/CodeCheckerDescriptor.java @@ -8,7 +8,7 @@ * */ class CodeCheckerDescriptor extends ParserDescriptor { - private static final String ID = "codechecker"; + private static final String ID = "CodeChecker"; private static final String NAME = "CodeChecker"; CodeCheckerDescriptor() { From ea4c8d7cdeefe7d5529c36e7abb06f802a5f495a Mon Sep 17 00:00:00 2001 From: Marcel Schneider Date: Fri, 12 Nov 2021 20:58:27 +0100 Subject: [PATCH 03/16] update the comment to Codechecker --- .../edu/hm/hafner/analysis/registry/CodeCheckerDescriptor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/edu/hm/hafner/analysis/registry/CodeCheckerDescriptor.java b/src/main/java/edu/hm/hafner/analysis/registry/CodeCheckerDescriptor.java index 59a9ef385..683dd36e5 100644 --- a/src/main/java/edu/hm/hafner/analysis/registry/CodeCheckerDescriptor.java +++ b/src/main/java/edu/hm/hafner/analysis/registry/CodeCheckerDescriptor.java @@ -4,7 +4,7 @@ import edu.hm.hafner.analysis.parser.CodeCheckerParser; /** - * A descriptor for the Clang-Tidy compiler. + * A descriptor for the Codechecker parser. * */ class CodeCheckerDescriptor extends ParserDescriptor { From 85827203537ccf58c5a248cd72e0fba3c02efb14 Mon Sep 17 00:00:00 2001 From: Marcel Schneider Date: Fri, 12 Nov 2021 21:39:21 +0100 Subject: [PATCH 04/16] fix code style --- .../java/edu/hm/hafner/analysis/parser/CodeCheckerParser.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/edu/hm/hafner/analysis/parser/CodeCheckerParser.java b/src/main/java/edu/hm/hafner/analysis/parser/CodeCheckerParser.java index a1406d26f..5f0f264d5 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/CodeCheckerParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/CodeCheckerParser.java @@ -41,7 +41,7 @@ protected Optional createIssue(final Matcher matcher, final LookaheadStre else if (matcher.group(1).contains("HIGH")) { priority = Severity.WARNING_HIGH; } - else if (matcher.group(1).contains("MEDIUM")){ + else if (matcher.group(1).contains("MEDIUM")) { priority = Severity.WARNING_NORMAL; } else { From 8f0050c6061b3957681c6e60880b4847f5ec2a96 Mon Sep 17 00:00:00 2001 From: Marcel Schneider Date: Sun, 14 Nov 2021 13:53:04 +0100 Subject: [PATCH 05/16] combine test cases into single file --- ...hsTest.java => CodeCheckerParserTest.java} | 52 +++++++++++++++--- .../CodeCheckerParserWithLinuxPathsTest.java | 55 ------------------- 2 files changed, 43 insertions(+), 64 deletions(-) rename src/test/java/edu/hm/hafner/analysis/parser/{CodeCheckerParserWithWindowsPathsTest.java => CodeCheckerParserTest.java} (63%) delete mode 100644 src/test/java/edu/hm/hafner/analysis/parser/CodeCheckerParserWithLinuxPathsTest.java diff --git a/src/test/java/edu/hm/hafner/analysis/parser/CodeCheckerParserWithWindowsPathsTest.java b/src/test/java/edu/hm/hafner/analysis/parser/CodeCheckerParserTest.java similarity index 63% rename from src/test/java/edu/hm/hafner/analysis/parser/CodeCheckerParserWithWindowsPathsTest.java rename to src/test/java/edu/hm/hafner/analysis/parser/CodeCheckerParserTest.java index a2fbccd36..a553694f1 100644 --- a/src/test/java/edu/hm/hafner/analysis/parser/CodeCheckerParserWithWindowsPathsTest.java +++ b/src/test/java/edu/hm/hafner/analysis/parser/CodeCheckerParserTest.java @@ -1,5 +1,7 @@ package edu.hm.hafner.analysis.parser; +import org.junit.jupiter.api.Test; + import edu.hm.hafner.analysis.AbstractParserTest; import edu.hm.hafner.analysis.Report; import edu.hm.hafner.analysis.Severity; @@ -7,11 +9,11 @@ import static edu.hm.hafner.analysis.assertions.Assertions.*; -class CodeCheckerParserWithWindowsPathsTest extends AbstractParserTest { +class CodeCheckerParserTest extends AbstractParserTest { private static final String WARNING_TYPE = "Warning"; - CodeCheckerParserWithWindowsPathsTest() { - super("CodeChecker_with_windows_paths.txt"); + CodeCheckerParserTest() { + super("CodeChecker_with_linux_paths.txt"); } @Override @@ -21,9 +23,42 @@ protected CodeCheckerParser createParser() { @Override protected void assertThatIssuesArePresent(final Report annotation, final SoftAssertions softly) { - assertThat(annotation).hasSize(5); + assertThat(annotation).hasSize(3); softly.assertThat(annotation.get(0)) + .hasLineStart(17) + .hasColumnStart(8) + .hasFileName("/path/to/projrct/csv2xlslib.Test/parsecmdTest.cpp") + .hasMessage("class 'TheFixture' defines a default destructor but does not define a copy constructor, a copy assignment operator, a move constructor or a move assignment operator") + .hasType(WARNING_TYPE) + .hasCategory("cppcoreguidelines-special-member-functions") + .hasSeverity(Severity.WARNING_LOW); + + softly.assertThat(annotation.get(1)) + .hasLineStart(425) + .hasColumnStart(33) + .hasFileName("/path/to/projrct/extern/lib/workbook.cpp") + .hasMessage("Called C++ object pointer is null") + .hasType(WARNING_TYPE) + .hasCategory("core.CallAndMessage") + .hasSeverity(Severity.WARNING_HIGH); + + softly.assertThat(annotation.get(2)) + .hasLineStart(212) + .hasColumnStart(12) + .hasFileName("/path/to/projrct/extern/lib/HPSF.cpp") + .hasMessage("'signed char' to 'int' conversion; consider casting to 'unsigned char' first.") + .hasType(WARNING_TYPE) + .hasCategory("bugprone-signed-char-misuse") + .hasSeverity(Severity.WARNING_NORMAL); + + } + + @Test + void shouldParseWindowsPaths(){ + Report annotation = parse("CodeChecker_with_windows_paths.txt"); + assertThat(annotation).hasSize(5); + assertThat(annotation.get(0)) .hasLineStart(15) .hasColumnStart(22) .hasFileName("C:/path/to/project/cmake-build-debug/_deps/checked_cmd-src/Tests/ArgumentsTest.cpp") @@ -32,7 +67,7 @@ protected void assertThatIssuesArePresent(final Report annotation, final SoftAss .hasCategory("clang-diagnostic-deprecated-declarations") .hasSeverity(Severity.WARNING_NORMAL); - softly.assertThat(annotation.get(1)) + assertThat(annotation.get(1)) .hasLineStart(283) .hasColumnStart(22) .hasFileName("C:/Program Files (x86)/path/to/toolchain/include/abcddef") @@ -41,7 +76,7 @@ protected void assertThatIssuesArePresent(final Report annotation, final SoftAss .hasCategory("clang-diagnostic-error") .hasSeverity(Severity.ERROR); - softly.assertThat(annotation.get(2)) + assertThat(annotation.get(2)) .hasLineStart(17) .hasColumnStart(8) .hasFileName("C:/path/to/project/csv2xlslib.Test/parsecmdTest.cpp") @@ -50,7 +85,7 @@ protected void assertThatIssuesArePresent(final Report annotation, final SoftAss .hasCategory("cppcoreguidelines-special-member-functions") .hasSeverity(Severity.WARNING_LOW); - softly.assertThat(annotation.get(3)) + assertThat(annotation.get(3)) .hasLineStart(49) .hasColumnStart(8) .hasFileName("C:/path/to/project/csv2xlslib.Test/parseCsvStreamTest.cpp") @@ -59,7 +94,7 @@ protected void assertThatIssuesArePresent(final Report annotation, final SoftAss .hasCategory("cppcoreguidelines-special-member-functions") .hasSeverity(Severity.WARNING_LOW); - softly.assertThat(annotation.get(4)) + assertThat(annotation.get(4)) .hasLineStart(924) .hasColumnStart(49) .hasFileName("C:/path/to/project/extern/lib/formula_expr.cpp") @@ -69,5 +104,4 @@ protected void assertThatIssuesArePresent(final Report annotation, final SoftAss .hasSeverity(Severity.WARNING_HIGH); } - } diff --git a/src/test/java/edu/hm/hafner/analysis/parser/CodeCheckerParserWithLinuxPathsTest.java b/src/test/java/edu/hm/hafner/analysis/parser/CodeCheckerParserWithLinuxPathsTest.java deleted file mode 100644 index 7adc4a18b..000000000 --- a/src/test/java/edu/hm/hafner/analysis/parser/CodeCheckerParserWithLinuxPathsTest.java +++ /dev/null @@ -1,55 +0,0 @@ -package edu.hm.hafner.analysis.parser; - -import edu.hm.hafner.analysis.AbstractParserTest; -import edu.hm.hafner.analysis.Report; -import edu.hm.hafner.analysis.Severity; -import edu.hm.hafner.analysis.assertions.SoftAssertions; - -import static edu.hm.hafner.analysis.assertions.Assertions.*; - -class CodeCheckerParserWithLinuxPathsTest extends AbstractParserTest { - private static final String WARNING_TYPE = "Warning"; - - CodeCheckerParserWithLinuxPathsTest() { - super("CodeChecker_with_linux_paths.txt"); - } - - @Override - protected CodeCheckerParser createParser() { - return new CodeCheckerParser(); - } - - @Override - protected void assertThatIssuesArePresent(final Report annotation, final SoftAssertions softly) { - assertThat(annotation).hasSize(3); - - softly.assertThat(annotation.get(0)) - .hasLineStart(17) - .hasColumnStart(8) - .hasFileName("/path/to/projrct/csv2xlslib.Test/parsecmdTest.cpp") - .hasMessage("class 'TheFixture' defines a default destructor but does not define a copy constructor, a copy assignment operator, a move constructor or a move assignment operator") - .hasType(WARNING_TYPE) - .hasCategory("cppcoreguidelines-special-member-functions") - .hasSeverity(Severity.WARNING_LOW); - - softly.assertThat(annotation.get(1)) - .hasLineStart(425) - .hasColumnStart(33) - .hasFileName("/path/to/projrct/extern/lib/workbook.cpp") - .hasMessage("Called C++ object pointer is null") - .hasType(WARNING_TYPE) - .hasCategory("core.CallAndMessage") - .hasSeverity(Severity.WARNING_HIGH); - - softly.assertThat(annotation.get(2)) - .hasLineStart(212) - .hasColumnStart(12) - .hasFileName("/path/to/projrct/extern/lib/HPSF.cpp") - .hasMessage("'signed char' to 'int' conversion; consider casting to 'unsigned char' first.") - .hasType(WARNING_TYPE) - .hasCategory("bugprone-signed-char-misuse") - .hasSeverity(Severity.WARNING_NORMAL); - - } - -} From 6e07f31457741a29dd0933c572c4d5d897c8e037 Mon Sep 17 00:00:00 2001 From: Marcel Schneider Date: Sun, 14 Nov 2021 13:55:19 +0100 Subject: [PATCH 06/16] use `report` instead of annotation --- .../parser/CodeCheckerParserTest.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/test/java/edu/hm/hafner/analysis/parser/CodeCheckerParserTest.java b/src/test/java/edu/hm/hafner/analysis/parser/CodeCheckerParserTest.java index a553694f1..f9f12fc0c 100644 --- a/src/test/java/edu/hm/hafner/analysis/parser/CodeCheckerParserTest.java +++ b/src/test/java/edu/hm/hafner/analysis/parser/CodeCheckerParserTest.java @@ -22,10 +22,10 @@ protected CodeCheckerParser createParser() { } @Override - protected void assertThatIssuesArePresent(final Report annotation, final SoftAssertions softly) { - assertThat(annotation).hasSize(3); + protected void assertThatIssuesArePresent(final Report report, final SoftAssertions softly) { + assertThat(report).hasSize(3); - softly.assertThat(annotation.get(0)) + softly.assertThat(report.get(0)) .hasLineStart(17) .hasColumnStart(8) .hasFileName("/path/to/projrct/csv2xlslib.Test/parsecmdTest.cpp") @@ -34,7 +34,7 @@ protected void assertThatIssuesArePresent(final Report annotation, final SoftAss .hasCategory("cppcoreguidelines-special-member-functions") .hasSeverity(Severity.WARNING_LOW); - softly.assertThat(annotation.get(1)) + softly.assertThat(report.get(1)) .hasLineStart(425) .hasColumnStart(33) .hasFileName("/path/to/projrct/extern/lib/workbook.cpp") @@ -43,7 +43,7 @@ protected void assertThatIssuesArePresent(final Report annotation, final SoftAss .hasCategory("core.CallAndMessage") .hasSeverity(Severity.WARNING_HIGH); - softly.assertThat(annotation.get(2)) + softly.assertThat(report.get(2)) .hasLineStart(212) .hasColumnStart(12) .hasFileName("/path/to/projrct/extern/lib/HPSF.cpp") @@ -56,9 +56,9 @@ protected void assertThatIssuesArePresent(final Report annotation, final SoftAss @Test void shouldParseWindowsPaths(){ - Report annotation = parse("CodeChecker_with_windows_paths.txt"); - assertThat(annotation).hasSize(5); - assertThat(annotation.get(0)) + Report report = parse("CodeChecker_with_windows_paths.txt"); + assertThat(report).hasSize(5); + assertThat(report.get(0)) .hasLineStart(15) .hasColumnStart(22) .hasFileName("C:/path/to/project/cmake-build-debug/_deps/checked_cmd-src/Tests/ArgumentsTest.cpp") @@ -67,7 +67,7 @@ void shouldParseWindowsPaths(){ .hasCategory("clang-diagnostic-deprecated-declarations") .hasSeverity(Severity.WARNING_NORMAL); - assertThat(annotation.get(1)) + assertThat(report.get(1)) .hasLineStart(283) .hasColumnStart(22) .hasFileName("C:/Program Files (x86)/path/to/toolchain/include/abcddef") @@ -76,7 +76,7 @@ void shouldParseWindowsPaths(){ .hasCategory("clang-diagnostic-error") .hasSeverity(Severity.ERROR); - assertThat(annotation.get(2)) + assertThat(report.get(2)) .hasLineStart(17) .hasColumnStart(8) .hasFileName("C:/path/to/project/csv2xlslib.Test/parsecmdTest.cpp") @@ -85,7 +85,7 @@ void shouldParseWindowsPaths(){ .hasCategory("cppcoreguidelines-special-member-functions") .hasSeverity(Severity.WARNING_LOW); - assertThat(annotation.get(3)) + assertThat(report.get(3)) .hasLineStart(49) .hasColumnStart(8) .hasFileName("C:/path/to/project/csv2xlslib.Test/parseCsvStreamTest.cpp") @@ -94,7 +94,7 @@ void shouldParseWindowsPaths(){ .hasCategory("cppcoreguidelines-special-member-functions") .hasSeverity(Severity.WARNING_LOW); - assertThat(annotation.get(4)) + assertThat(report.get(4)) .hasLineStart(924) .hasColumnStart(49) .hasFileName("C:/path/to/project/extern/lib/formula_expr.cpp") From 2c92aaedc0157459334a4e6378accaf094416c06 Mon Sep 17 00:00:00 2001 From: Marcel Schneider Date: Sun, 14 Nov 2021 13:58:05 +0100 Subject: [PATCH 07/16] No need to define a type if there is just one thing --- .../edu/hm/hafner/analysis/parser/CodeCheckerParser.java | 1 - .../hm/hafner/analysis/parser/CodeCheckerParserTest.java | 8 -------- 2 files changed, 9 deletions(-) diff --git a/src/main/java/edu/hm/hafner/analysis/parser/CodeCheckerParser.java b/src/main/java/edu/hm/hafner/analysis/parser/CodeCheckerParser.java index 5f0f264d5..2a0d28529 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/CodeCheckerParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/CodeCheckerParser.java @@ -53,7 +53,6 @@ else if (matcher.group(1).contains("MEDIUM")) { .setColumnStart(matcher.group(4)) .setCategory(matcher.group(6)) .setMessage(matcher.group(5)) - .setType("Warning") .buildOptional(); } } diff --git a/src/test/java/edu/hm/hafner/analysis/parser/CodeCheckerParserTest.java b/src/test/java/edu/hm/hafner/analysis/parser/CodeCheckerParserTest.java index f9f12fc0c..2f45dc894 100644 --- a/src/test/java/edu/hm/hafner/analysis/parser/CodeCheckerParserTest.java +++ b/src/test/java/edu/hm/hafner/analysis/parser/CodeCheckerParserTest.java @@ -30,7 +30,6 @@ protected void assertThatIssuesArePresent(final Report report, final SoftAsserti .hasColumnStart(8) .hasFileName("/path/to/projrct/csv2xlslib.Test/parsecmdTest.cpp") .hasMessage("class 'TheFixture' defines a default destructor but does not define a copy constructor, a copy assignment operator, a move constructor or a move assignment operator") - .hasType(WARNING_TYPE) .hasCategory("cppcoreguidelines-special-member-functions") .hasSeverity(Severity.WARNING_LOW); @@ -39,7 +38,6 @@ protected void assertThatIssuesArePresent(final Report report, final SoftAsserti .hasColumnStart(33) .hasFileName("/path/to/projrct/extern/lib/workbook.cpp") .hasMessage("Called C++ object pointer is null") - .hasType(WARNING_TYPE) .hasCategory("core.CallAndMessage") .hasSeverity(Severity.WARNING_HIGH); @@ -48,7 +46,6 @@ protected void assertThatIssuesArePresent(final Report report, final SoftAsserti .hasColumnStart(12) .hasFileName("/path/to/projrct/extern/lib/HPSF.cpp") .hasMessage("'signed char' to 'int' conversion; consider casting to 'unsigned char' first.") - .hasType(WARNING_TYPE) .hasCategory("bugprone-signed-char-misuse") .hasSeverity(Severity.WARNING_NORMAL); @@ -63,7 +60,6 @@ void shouldParseWindowsPaths(){ .hasColumnStart(22) .hasFileName("C:/path/to/project/cmake-build-debug/_deps/checked_cmd-src/Tests/ArgumentsTest.cpp") .hasMessage("'strncpy' is deprecated: This function or variable may be unsafe. Consider using strncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.") - .hasType(WARNING_TYPE) .hasCategory("clang-diagnostic-deprecated-declarations") .hasSeverity(Severity.WARNING_NORMAL); @@ -72,7 +68,6 @@ void shouldParseWindowsPaths(){ .hasColumnStart(22) .hasFileName("C:/Program Files (x86)/path/to/toolchain/include/abcddef") .hasMessage("'auto' return without trailing return type; deduced return types are a C++14 extension") - .hasType(WARNING_TYPE) .hasCategory("clang-diagnostic-error") .hasSeverity(Severity.ERROR); @@ -81,7 +76,6 @@ void shouldParseWindowsPaths(){ .hasColumnStart(8) .hasFileName("C:/path/to/project/csv2xlslib.Test/parsecmdTest.cpp") .hasMessage("class 'TheFixture' defines a default destructor but does not define a copy constructor, a copy assignment operator, a move constructor or a move assignment operator") - .hasType(WARNING_TYPE) .hasCategory("cppcoreguidelines-special-member-functions") .hasSeverity(Severity.WARNING_LOW); @@ -90,7 +84,6 @@ void shouldParseWindowsPaths(){ .hasColumnStart(8) .hasFileName("C:/path/to/project/csv2xlslib.Test/parseCsvStreamTest.cpp") .hasMessage("class 'Given_an_input_file_with_headline' defines a default destructor but does not define a copy constructor, a copy assignment operator, a move constructor or a move assignment operator") - .hasType(WARNING_TYPE) .hasCategory("cppcoreguidelines-special-member-functions") .hasSeverity(Severity.WARNING_LOW); @@ -99,7 +92,6 @@ void shouldParseWindowsPaths(){ .hasColumnStart(49) .hasFileName("C:/path/to/project/extern/lib/formula_expr.cpp") .hasMessage("suspicious usage of 'sizeof(A*)'; pointer to aggregate") - .hasType(WARNING_TYPE) .hasCategory("bugprone-sizeof-expression") .hasSeverity(Severity.WARNING_HIGH); From 5aa72edb6795967ebd9d8ee39245d20a7ae74342 Mon Sep 17 00:00:00 2001 From: Marcel Schneider Date: Sun, 14 Nov 2021 14:01:20 +0100 Subject: [PATCH 08/16] make ID lower case with dash as separator --- .../edu/hm/hafner/analysis/registry/CodeCheckerDescriptor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/edu/hm/hafner/analysis/registry/CodeCheckerDescriptor.java b/src/main/java/edu/hm/hafner/analysis/registry/CodeCheckerDescriptor.java index 683dd36e5..6c0ec4487 100644 --- a/src/main/java/edu/hm/hafner/analysis/registry/CodeCheckerDescriptor.java +++ b/src/main/java/edu/hm/hafner/analysis/registry/CodeCheckerDescriptor.java @@ -8,7 +8,7 @@ * */ class CodeCheckerDescriptor extends ParserDescriptor { - private static final String ID = "CodeChecker"; + private static final String ID = "code-checker"; private static final String NAME = "CodeChecker"; CodeCheckerDescriptor() { From 03854eda67efc1fdcde3b11a2537d2fdb608805a Mon Sep 17 00:00:00 2001 From: Marcel Schneider Date: Sun, 14 Nov 2021 14:27:04 +0100 Subject: [PATCH 09/16] use named groups in regex --- .../analysis/parser/CodeCheckerParser.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/edu/hm/hafner/analysis/parser/CodeCheckerParser.java b/src/main/java/edu/hm/hafner/analysis/parser/CodeCheckerParser.java index 2a0d28529..432050ee2 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/CodeCheckerParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/CodeCheckerParser.java @@ -22,7 +22,7 @@ public class CodeCheckerParser extends LookaheadParser { private static final long serialVersionUID = -3015592762345283582L; private static final String CODE_CHECKER_DEFECT_PATTERN = - "^\\[(CRITICAL|HIGH|MEDIUM|LOW)\\] (.+):(\\d+):(\\d+): (.*?) \\[([^\\s]*?)\\]$"; + "^\\[(?CRITICAL|HIGH|MEDIUM|LOW)\\] (?.+):(?\\d+):(?\\d+): (?.*?) \\[(?[^\\s]*?)\\]$"; /** * Creates a new instance of {@link CodeCheckerParser}. @@ -35,24 +35,24 @@ public CodeCheckerParser() { protected Optional createIssue(final Matcher matcher, final LookaheadStream lookahead, final IssueBuilder builder) { Severity priority; - if (matcher.group(1).contains("CRITICAL")) { + if (matcher.group("severity").contains("CRITICAL")) { priority = Severity.ERROR; } - else if (matcher.group(1).contains("HIGH")) { + else if (matcher.group("severity").contains("HIGH")) { priority = Severity.WARNING_HIGH; } - else if (matcher.group(1).contains("MEDIUM")) { + else if (matcher.group("severity").contains("MEDIUM")) { priority = Severity.WARNING_NORMAL; } else { priority = Severity.WARNING_LOW; } - return builder.setFileName(matcher.group(2)) + return builder.setFileName(matcher.group("path")) .setSeverity(priority) - .setLineStart(matcher.group(3)) - .setColumnStart(matcher.group(4)) - .setCategory(matcher.group(6)) - .setMessage(matcher.group(5)) + .setLineStart(matcher.group("line")) + .setColumnStart(matcher.group("column")) + .setCategory(matcher.group("category")) + .setMessage(matcher.group("message")) .buildOptional(); } } From 0a616b29ad8fdfe96f1986b6602ec22ae9b11bd3 Mon Sep 17 00:00:00 2001 From: Marcel Schneider Date: Sun, 14 Nov 2021 14:38:46 +0100 Subject: [PATCH 10/16] fix code style --- .../edu/hm/hafner/analysis/parser/CodeCheckerParserTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/edu/hm/hafner/analysis/parser/CodeCheckerParserTest.java b/src/test/java/edu/hm/hafner/analysis/parser/CodeCheckerParserTest.java index 2f45dc894..3dc24245d 100644 --- a/src/test/java/edu/hm/hafner/analysis/parser/CodeCheckerParserTest.java +++ b/src/test/java/edu/hm/hafner/analysis/parser/CodeCheckerParserTest.java @@ -52,7 +52,7 @@ protected void assertThatIssuesArePresent(final Report report, final SoftAsserti } @Test - void shouldParseWindowsPaths(){ + void shouldParseWindowsPaths() { Report report = parse("CodeChecker_with_windows_paths.txt"); assertThat(report).hasSize(5); assertThat(report.get(0)) From 5af5868d8aeebbcce114ebe12b669f907ca5e118 Mon Sep 17 00:00:00 2001 From: Marcel Schneider Date: Sun, 14 Nov 2021 14:39:29 +0100 Subject: [PATCH 11/16] remove unused private field --- .../edu/hm/hafner/analysis/parser/CodeCheckerParserTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/java/edu/hm/hafner/analysis/parser/CodeCheckerParserTest.java b/src/test/java/edu/hm/hafner/analysis/parser/CodeCheckerParserTest.java index 3dc24245d..570ce1d72 100644 --- a/src/test/java/edu/hm/hafner/analysis/parser/CodeCheckerParserTest.java +++ b/src/test/java/edu/hm/hafner/analysis/parser/CodeCheckerParserTest.java @@ -10,7 +10,6 @@ import static edu.hm.hafner.analysis.assertions.Assertions.*; class CodeCheckerParserTest extends AbstractParserTest { - private static final String WARNING_TYPE = "Warning"; CodeCheckerParserTest() { super("CodeChecker_with_linux_paths.txt"); From 9417a1336e33e7036fa4da3cad6b9ec7c925121e Mon Sep 17 00:00:00 2001 From: Marcel Schneider Date: Sun, 14 Nov 2021 21:50:53 +0100 Subject: [PATCH 12/16] extract method `getSeverity` --- .../analysis/parser/CodeCheckerParser.java | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/main/java/edu/hm/hafner/analysis/parser/CodeCheckerParser.java b/src/main/java/edu/hm/hafner/analysis/parser/CodeCheckerParser.java index 432050ee2..e9a540c79 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/CodeCheckerParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/CodeCheckerParser.java @@ -34,25 +34,30 @@ public CodeCheckerParser() { @Override protected Optional createIssue(final Matcher matcher, final LookaheadStream lookahead, final IssueBuilder builder) { - Severity priority; - if (matcher.group("severity").contains("CRITICAL")) { - priority = Severity.ERROR; - } - else if (matcher.group("severity").contains("HIGH")) { - priority = Severity.WARNING_HIGH; - } - else if (matcher.group("severity").contains("MEDIUM")) { - priority = Severity.WARNING_NORMAL; - } - else { - priority = Severity.WARNING_LOW; - } + Severity severity = getSeverity(matcher.group("severity")); return builder.setFileName(matcher.group("path")) - .setSeverity(priority) + .setSeverity(severity) .setLineStart(matcher.group("line")) .setColumnStart(matcher.group("column")) .setCategory(matcher.group("category")) .setMessage(matcher.group("message")) .buildOptional(); } + + private Severity getSeverity(final String severityText) { + Severity severity; + if (severityText.contains("CRITICAL")) { + severity = Severity.ERROR; + } + else if (severityText.contains("HIGH")) { + severity = Severity.WARNING_HIGH; + } + else if (severityText.contains("MEDIUM")) { + severity = Severity.WARNING_NORMAL; + } + else { + severity = Severity.WARNING_LOW; + } + return severity; + } } From 54265f4ae48bcba06b104abe9b6cd66c1de1140b Mon Sep 17 00:00:00 2001 From: Marcel Schneider Date: Sun, 14 Nov 2021 22:10:35 +0100 Subject: [PATCH 13/16] remove state in `getSeverity` --- .../analysis/parser/CodeCheckerParser.java | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/src/main/java/edu/hm/hafner/analysis/parser/CodeCheckerParser.java b/src/main/java/edu/hm/hafner/analysis/parser/CodeCheckerParser.java index e9a540c79..34611f2d0 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/CodeCheckerParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/CodeCheckerParser.java @@ -45,19 +45,10 @@ protected Optional createIssue(final Matcher matcher, final LookaheadStre } private Severity getSeverity(final String severityText) { - Severity severity; - if (severityText.contains("CRITICAL")) { - severity = Severity.ERROR; - } - else if (severityText.contains("HIGH")) { - severity = Severity.WARNING_HIGH; - } - else if (severityText.contains("MEDIUM")) { - severity = Severity.WARNING_NORMAL; - } - else { - severity = Severity.WARNING_LOW; - } - return severity; + if (severityText.contains("CRITICAL")) { return Severity.ERROR; } + if (severityText.contains("HIGH" )) { return Severity.WARNING_HIGH; } + if (severityText.contains("MEDIUM" )) { return Severity.WARNING_NORMAL;} + + return Severity.WARNING_LOW; } } From d34a47b7bfd60ec5d5f61555781168b3f2798035 Mon Sep 17 00:00:00 2001 From: Marcel Schneider Date: Sun, 14 Nov 2021 22:19:55 +0100 Subject: [PATCH 14/16] try to make code style checker happy and still preserve readability --- .../edu/hm/hafner/analysis/parser/CodeCheckerParser.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/edu/hm/hafner/analysis/parser/CodeCheckerParser.java b/src/main/java/edu/hm/hafner/analysis/parser/CodeCheckerParser.java index 34611f2d0..140ead318 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/CodeCheckerParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/CodeCheckerParser.java @@ -45,9 +45,9 @@ protected Optional createIssue(final Matcher matcher, final LookaheadStre } private Severity getSeverity(final String severityText) { - if (severityText.contains("CRITICAL")) { return Severity.ERROR; } - if (severityText.contains("HIGH" )) { return Severity.WARNING_HIGH; } - if (severityText.contains("MEDIUM" )) { return Severity.WARNING_NORMAL;} + if (severityText.contains("CRITICAL")) return Severity.ERROR; + if (severityText.contains("HIGH")) return Severity.WARNING_HIGH; + if (severityText.contains("MEDIUM")) return Severity.WARNING_NORMAL; return Severity.WARNING_LOW; } From 2f914b5a8322a5acb444b3ab2d6f4a9893b2d4ac Mon Sep 17 00:00:00 2001 From: Marcel Schneider Date: Sun, 14 Nov 2021 22:30:11 +0100 Subject: [PATCH 15/16] [code style] 'if' construct must use '{}'s. there are cases where automated code style checkers hurt readability --- .../hafner/analysis/parser/CodeCheckerParser.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/java/edu/hm/hafner/analysis/parser/CodeCheckerParser.java b/src/main/java/edu/hm/hafner/analysis/parser/CodeCheckerParser.java index 140ead318..c63cf49a8 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/CodeCheckerParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/CodeCheckerParser.java @@ -45,10 +45,16 @@ protected Optional createIssue(final Matcher matcher, final LookaheadStre } private Severity getSeverity(final String severityText) { - if (severityText.contains("CRITICAL")) return Severity.ERROR; - if (severityText.contains("HIGH")) return Severity.WARNING_HIGH; - if (severityText.contains("MEDIUM")) return Severity.WARNING_NORMAL; - + + if (severityText.contains("CRITICAL")) { + return Severity.ERROR; + } + if (severityText.contains("HIGH")) { + return Severity.WARNING_HIGH; + } + if (severityText.contains("MEDIUM")) { + return Severity.WARNING_NORMAL; + } return Severity.WARNING_LOW; } } From 201cf54de7e545d0334ca27bbe716fb3f8729477 Mon Sep 17 00:00:00 2001 From: Marcel Schneider Date: Sun, 14 Nov 2021 22:31:30 +0100 Subject: [PATCH 16/16] update supported formats --- SUPPORTED-FORMATS.md | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/SUPPORTED-FORMATS.md b/SUPPORTED-FORMATS.md index b9447ff4f..b6e056d6e 100644 --- a/SUPPORTED-FORMATS.md +++ b/SUPPORTED-FORMATS.md @@ -1,4 +1,4 @@ - + # Supported Report Formats The static analysis model supports the following report formats. @@ -403,6 +403,20 @@ If your tool is supported, but some properties are missing (icon, URL, etc.), pl - + + + code-checker + + + - + + + CodeChecker + + + - + + codenarc