From 1845834d39079243f2ad2328ce5578336f57b5b2 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Morin Date: Sun, 24 Feb 2019 18:48:33 -0500 Subject: [PATCH 1/3] Add support for package and module in Pylint --- .../hafner/analysis/parser/PyLintParser.java | 10 +++++++++- .../analysis/parser/PylintParserTest.java | 20 ++++++++++++++++++- .../edu/hm/hafner/analysis/parser/pyLint.txt | 2 ++ 3 files changed, 30 insertions(+), 2 deletions(-) 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) From 6c12eb192b2c817d4984b3d1520ffc8a65e1e6de Mon Sep 17 00:00:00 2001 From: Jean-Christophe Morin Date: Sat, 2 Mar 2019 10:27:31 -0500 Subject: [PATCH 2/3] fix tests --- .../java/edu/hm/hafner/analysis/parser/PyLintParser.java | 5 +++++ .../java/edu/hm/hafner/analysis/parser/PylintParserTest.java | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) 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 53b2cdaaf..d88b571f0 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/PyLintParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/PyLintParser.java @@ -45,8 +45,13 @@ protected Optional createIssue(final Matcher matcher, final IssueBuilder if (moduleName != null) { if (moduleName.contains(".")) { builder.setPackageName(moduleName.substring(0, moduleName.lastIndexOf("."))); + } else { + builder.setPackageName("-"); } builder.setModuleName(moduleName); + } else { + builder.setPackageName("-") + .setModuleName("-"); } return builder.setFileName(matcher.group("path")) 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 f9aa478de..10b7cb413 100644 --- a/src/test/java/edu/hm/hafner/analysis/parser/PylintParserTest.java +++ b/src/test/java/edu/hm/hafner/analysis/parser/PylintParserTest.java @@ -236,7 +236,7 @@ void shouldParseReportWithoutSymbol() { .hasCategory("W0611") .hasSeverity(Severity.WARNING_NORMAL) .hasModuleName("module_name_no_package") - .hasPackageName(null); + .hasPackageName("-"); }); } From 38f0909cddb3a36ccbb8bd127dac9e0d7bdd9279 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Morin Date: Sat, 2 Mar 2019 13:09:30 -0500 Subject: [PATCH 3/3] Move else on new line --- .../java/edu/hm/hafner/analysis/parser/PyLintParser.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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 d88b571f0..f80b05d68 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/PyLintParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/PyLintParser.java @@ -45,11 +45,13 @@ protected Optional createIssue(final Matcher matcher, final IssueBuilder if (moduleName != null) { if (moduleName.contains(".")) { builder.setPackageName(moduleName.substring(0, moduleName.lastIndexOf("."))); - } else { + } + else { builder.setPackageName("-"); } builder.setModuleName(moduleName); - } else { + } + else { builder.setPackageName("-") .setModuleName("-"); }