Skip to content

SONARPY-749 Add new style importing of Pylint reports#808

Merged
guillaume-dequenne merged 7 commits intoMMF-1778from
SONARPY-749
Jul 9, 2020
Merged

SONARPY-749 Add new style importing of Pylint reports#808
guillaume-dequenne merged 7 commits intoMMF-1778from
SONARPY-749

Conversation

@guillaume-dequenne
Copy link
Copy Markdown
Contributor

No description provided.

@guillaume-dequenne guillaume-dequenne force-pushed the SONARPY-749 branch 6 times, most recently from 988bbf6 to 4d1aa19 Compare July 8, 2020 12:17
@guillaume-dequenne guillaume-dequenne changed the title temp commit new pylint SONARPY-749 Add new style importing of Pylint reports Jul 8, 2020
@guillaume-dequenne guillaume-dequenne force-pushed the SONARPY-749 branch 2 times, most recently from 595bd54 to 7dbd8df Compare July 8, 2020 14:53
Copy link
Copy Markdown
Contributor

@gyula-sallai-sonarsource gyula-sallai-sonarsource left a comment

Choose a reason for hiding this comment

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

Mostly minor comments on the implementation, I will take another look at the tests tomorrow.

private static final String RULES_JSON = "org/sonar/plugins/python/pylint/rules.json";

private static final ExternalRuleLoader RULE_LOADER = new ExternalRuleLoader(PylintSensor.LINTER_KEY, PylintSensor.LINTER_NAME, RULES_JSON, Python.KEY);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nitpick I would drop this extra empty line.

private static final Pattern PATTERN_LEGACY = Pattern.compile("(.+):(\\d+): \\[(.*)\\] (.*)");

protected Issue parseLine(String line) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nitpick I would drop this empty line.

Comment on lines +32 to +33
private static final Pattern PYLINT_DEFAULT = Pattern.compile("(.+):(\\d+):(\\d+): (\\S+): (.*)");
private static final Pattern PATTERN_LEGACY = Pattern.compile("(.+):(\\d+): \\[(.*)\\] (.*)");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The naming is a little inconsistent for me, I would prefer something like DEFAULT_PATTERN and LEGACY_PATTERN, or PYLINT_DEFAULT and PYLINT_LEGACY.

String message = m.group(5);
return new Issue(filePath, ruleKey, message, lineNumber, columnNumber);
}
m = PYLINT_PATTERN.matcher(line);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would add a comment here that justifies why are we using a Pylint pattern here (maybe also worth explaining that even though we have the same pattern in PylintReportReader, the implementation is slightly different).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

After having a second look at this, the different formats are only subtly different and I decided to simply make a more generic version of the regexes and logic in TextReportReader rather than keep the 2 implementations.

Comment on lines +82 to +83
logger().error("No issues information will be saved as the report file '{}' can't be read. " +
e.getClass().getSimpleName() + ": " + e.getMessage(), reportPath, e);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's a little weird to me that we are mixing string formatting and string concatenation here.

Comment on lines +218 to +220
} catch (IOException e) {
throw new IllegalStateException(e);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not sure I understand why we are doing this, executeSensorImporting has already declared that it may throw IOException

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

After double checking it seems that it's because this method is called in a forEach statement, and because of that the IOException it might throw would not be handled by the executeSensorImporting throw declaration.

Copy link
Copy Markdown
Contributor

@gyula-sallai-sonarsource gyula-sallai-sonarsource left a comment

Choose a reason for hiding this comment

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

LGTM, left some subjective comments. Feel free to disregard both of them if you disagree.

*/
public class TextReportReader {

private final int reportOffset;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nitpick I would add an empty line here just to indicate that this is an instance field. Maybe also would move it below the static fields.

private static final Logger LOG = Loggers.get(Flake8ReportReader.class);
private static final Pattern DEFAULT_PATTERN = Pattern.compile("(.+):(\\d+):(\\d+): (\\S+) (.*)");
private static final Pattern PYLINT_PATTERN = Pattern.compile("(.+):(\\d+): \\[(.*)\\] (.*)");
public TextReportReader(int columnStartIndex) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

minor, subjective Having to call this constructor with some magic numbers seems a little off to me. I think it would look nicer if we introduced integer constants and used them something like this:

new TextReportReader(TextReportReader.COLUMN_ZERO_BASED)
new TextReportReader(TextReportReader.COLUMN_ONE_BASED)

Feel free to disregard if you feel that this is too much.

@sonarsource-next
Copy link
Copy Markdown

Kudos, SonarQube Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots (100.0% reviewed)
Code Smell A 0 Code Smells

100.0% 100.0% Coverage
0.0% 0.0% Duplication

@guillaume-dequenne guillaume-dequenne merged this pull request into MMF-1778 Jul 9, 2020
@guillaume-dequenne guillaume-dequenne deleted the SONARPY-749 branch July 9, 2020 12:22
hashicorp-vault-sonar-prod Bot pushed a commit that referenced this pull request Jan 28, 2026
GitOrigin-RevId: 1b88d9f35afcb9554ab9357c4c6cdbdc986e7454
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants