Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for package and module in Pylint #100

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/main/java/edu/hm/hafner/analysis/parser/PyLintParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "(?<path>.*):(?<line>\\d+): \\[(?<category>\\D\\d*)(?:\\((?<symbol>.*)\\), )?.*?\\] (?<message>.*)";
private static final String PYLINT_PATTERN = "(?<path>[^:]*)(?:\\:(?<module>.*))?:(?<line>\\d+): \\[(?<category>\\D\\d*)(?:\\((?<symbol>.*)\\), )?.*?\\] (?<message>.*)";

private static final String UNKNOWN_CAT = "pylint-unknown";

Expand All @@ -41,6 +41,21 @@ protected Optional<Issue> 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(".")));
}
else {
builder.setPackageName("-");
}
builder.setModuleName(moduleName);
}
else {
builder.setPackageName("-")
.setModuleName("-");
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you need:

else {
   builder.setPackageName("-").setModuleName("-");
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The builder is not cleared between warnings.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aaa, that confirms what I was seeing, effectively. I had the impression something wasn't cleared, but didn't knew what it was. I'll adjust this, thanks :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

return builder.setFileName(matcher.group("path"))
.setLineStart(matcher.group("line"))
.setMessage(matcher.group("message"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Issue> iterator = report.iterator();
SoftAssertions.assertSoftly(softly -> {
Expand Down Expand Up @@ -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("-");
});
}

Expand Down
2 changes: 2 additions & 0 deletions src/test/resources/edu/hm/hafner/analysis/parser/pyLint.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)