Skip to content

Commit

Permalink
Merge pull request #706 from ferkulat/add_parser_for_codechecker
Browse files Browse the repository at this point in the history
Add parser for codechecker
  • Loading branch information
uhafner authored Nov 14, 2021
2 parents 349a05c + 201cf54 commit 6274c3b
Show file tree
Hide file tree
Showing 7 changed files with 341 additions and 1 deletion.
16 changes: 15 additions & 1 deletion SUPPORTED-FORMATS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!--- DO NOT EDIT - Generated by ParserRegistry at 2021-10-09T20:30:47.205683-->
<!--- DO NOT EDIT - Generated by ParserRegistry at 2021-11-14T22:16:18.254581-->
# Supported Report Formats

The static analysis model supports the following report formats.
Expand Down Expand Up @@ -403,6 +403,20 @@ If your tool is supported, but some properties are missing (icon, URL, etc.), pl
-
</td>
</tr>
<tr>
<td>
code-checker
</td>
<td>
-
</td>
<td>
CodeChecker
</td>
<td>
-
</td>
</tr>
<tr>
<td>
codenarc
Expand Down
60 changes: 60 additions & 0 deletions src/main/java/edu/hm/hafner/analysis/parser/CodeCheckerParser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
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 =
"^\\[(?<severity>CRITICAL|HIGH|MEDIUM|LOW)\\] (?<path>.+):(?<line>\\d+):(?<column>\\d+): (?<message>.*?) \\[(?<category>[^\\s]*?)\\]$";

/**
* Creates a new instance of {@link CodeCheckerParser}.
*/
public CodeCheckerParser() {
super(CODE_CHECKER_DEFECT_PATTERN);
}

@Override
protected Optional<Issue> createIssue(final Matcher matcher, final LookaheadStream lookahead,
final IssueBuilder builder) {
Severity severity = getSeverity(matcher.group("severity"));
return builder.setFileName(matcher.group("path"))
.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) {

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;
}
}
Original file line number Diff line number Diff line change
@@ -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 Codechecker parser.
*
*/
class CodeCheckerDescriptor extends ParserDescriptor {
private static final String ID = "code-checker";
private static final String NAME = "CodeChecker";

CodeCheckerDescriptor() {
super(ID, NAME);
}

@Override
public IssueParser createParser(final Option... options) {
return new CodeCheckerParser();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public class ParserRegistry {
new ClangTidyDescriptor(),
new CmakeDescriptor(),
new CodeAnalysisDescriptor(),
new CodeCheckerDescriptor(),
new CodeNarcDescriptor(),
new CoolfluxChessccDescriptor(),
new CpdDescriptor(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
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;
import edu.hm.hafner.analysis.assertions.SoftAssertions;

import static edu.hm.hafner.analysis.assertions.Assertions.*;

class CodeCheckerParserTest extends AbstractParserTest {

CodeCheckerParserTest() {
super("CodeChecker_with_linux_paths.txt");
}

@Override
protected CodeCheckerParser createParser() {
return new CodeCheckerParser();
}

@Override
protected void assertThatIssuesArePresent(final Report report, final SoftAssertions softly) {
assertThat(report).hasSize(3);

softly.assertThat(report.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")
.hasCategory("cppcoreguidelines-special-member-functions")
.hasSeverity(Severity.WARNING_LOW);

softly.assertThat(report.get(1))
.hasLineStart(425)
.hasColumnStart(33)
.hasFileName("/path/to/projrct/extern/lib/workbook.cpp")
.hasMessage("Called C++ object pointer is null")
.hasCategory("core.CallAndMessage")
.hasSeverity(Severity.WARNING_HIGH);

softly.assertThat(report.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.")
.hasCategory("bugprone-signed-char-misuse")
.hasSeverity(Severity.WARNING_NORMAL);

}

@Test
void shouldParseWindowsPaths() {
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")
.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.")
.hasCategory("clang-diagnostic-deprecated-declarations")
.hasSeverity(Severity.WARNING_NORMAL);

assertThat(report.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")
.hasCategory("clang-diagnostic-error")
.hasSeverity(Severity.ERROR);

assertThat(report.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")
.hasCategory("cppcoreguidelines-special-member-functions")
.hasSeverity(Severity.WARNING_LOW);

assertThat(report.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")
.hasCategory("cppcoreguidelines-special-member-functions")
.hasSeverity(Severity.WARNING_LOW);

assertThat(report.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")
.hasCategory("bugprone-sizeof-expression")
.hasSeverity(Severity.WARNING_HIGH);

}
}
Original file line number Diff line number Diff line change
@@ -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
----=================----
Original file line number Diff line number Diff line change
@@ -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
----=================----

0 comments on commit 6274c3b

Please sign in to comment.