diff --git a/src/main/java/edu/hm/hafner/analysis/parser/PyLintParser.java b/src/main/java/edu/hm/hafner/analysis/parser/PyLintParser.java index 667758207..53b2cdaaf 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/PyLintParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/PyLintParser.java @@ -19,7 +19,7 @@ public class PyLintParser extends RegexpLineParser { private static final long serialVersionUID = 4464053085862883240L; // the default pattern matches "--output-format=parseable" output. - private static final String PYLINT_PATTERN = "(?.*):(?\\d+): \\[(?\\D\\d*)(?:\\((?.*)\\), )?.*?\\] (?.*)"; + private static final String PYLINT_PATTERN = "(?[^:]*)(?:\\:(?.*))?:(?\\d+): \\[(?\\D\\d*)(?:\\((?.*)\\), )?.*?\\] (?.*)"; private static final String UNKNOWN_CAT = "pylint-unknown"; @@ -41,6 +41,14 @@ protected Optional createIssue(final Matcher matcher, final IssueBuilder builder.setSeverity(mapPriority(category)); builder.setCategory(StringUtils.firstNonBlank(matcher.group("symbol"), category, UNKNOWN_CAT)); + final String moduleName = matcher.group("module"); + if (moduleName != null) { + if (moduleName.contains(".")) { + builder.setPackageName(moduleName.substring(0, moduleName.lastIndexOf("."))); + } + builder.setModuleName(moduleName); + } + return builder.setFileName(matcher.group("path")) .setLineStart(matcher.group("line")) .setMessage(matcher.group("message")) diff --git a/src/test/java/edu/hm/hafner/analysis/parser/PylintParserTest.java b/src/test/java/edu/hm/hafner/analysis/parser/PylintParserTest.java index fcbf087b3..f9aa478de 100644 --- a/src/test/java/edu/hm/hafner/analysis/parser/PylintParserTest.java +++ b/src/test/java/edu/hm/hafner/analysis/parser/PylintParserTest.java @@ -168,7 +168,7 @@ protected void assertThatIssuesArePresent(final Report report, final SoftAsserti void shouldParseReportWithoutSymbol() { Report report = parse("pyLint.txt"); - assertThat(report).hasSize(6); + assertThat(report).hasSize(8); Iterator iterator = report.iterator(); SoftAssertions.assertSoftly(softly -> { @@ -219,6 +219,24 @@ void shouldParseReportWithoutSymbol() { .hasFileName("trunk/src/python/tv.py") .hasCategory("W0102") .hasSeverity(Severity.WARNING_NORMAL); + softly.assertThat(iterator.next()) + .hasLineStart(1) + .hasLineEnd(1) + .hasMessage("Unused import os (unused-import)") + .hasFileName("trunk/src/python_package/module_name.py") + .hasCategory("W0611") + .hasSeverity(Severity.WARNING_NORMAL) + .hasModuleName("python_package.module_name") + .hasPackageName("python_package"); + softly.assertThat(iterator.next()) + .hasLineStart(1) + .hasLineEnd(1) + .hasMessage("Unused import os (unused-import)") + .hasFileName("trunk/src/module_name_no_package.py") + .hasCategory("W0611") + .hasSeverity(Severity.WARNING_NORMAL) + .hasModuleName("module_name_no_package") + .hasPackageName(null); }); } diff --git a/src/test/resources/edu/hm/hafner/analysis/parser/pyLint.txt b/src/test/resources/edu/hm/hafner/analysis/parser/pyLint.txt index c7a07bf9f..1d608b471 100644 --- a/src/test/resources/edu/hm/hafner/analysis/parser/pyLint.txt +++ b/src/test/resources/edu/hm/hafner/analysis/parser/pyLint.txt @@ -4,3 +4,5 @@ trunk/src/python/tv.py:35: [C0111, Episode] Missing docstring trunk/src/python/tv.py:39: [E0213, Episode.__init__] Method should have "self" as first argument trunk/src/python/tv.py:5: [F0401, ] Unable to import 'deadbeef' trunk/src/python/tv.py:39: [W0102, Episode.__init__] Dangerous default value "[]" as argument +trunk/src/python_package/module_name.py:python_package.module_name:1: [W0611, ] Unused import os (unused-import) +trunk/src/module_name_no_package.py:module_name_no_package:1: [W0611, ] Unused import os (unused-import)