SONARPY-749 Add new style importing of Pylint reports#808
SONARPY-749 Add new style importing of Pylint reports#808guillaume-dequenne merged 7 commits intoMMF-1778from
Conversation
988bbf6 to
4d1aa19
Compare
595bd54 to
7dbd8df
Compare
7dbd8df to
1132d03
Compare
gyula-sallai-sonarsource
left a comment
There was a problem hiding this comment.
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); | ||
|
|
There was a problem hiding this comment.
nitpick I would drop this extra empty line.
| private static final Pattern PATTERN_LEGACY = Pattern.compile("(.+):(\\d+): \\[(.*)\\] (.*)"); | ||
|
|
||
| protected Issue parseLine(String line) { | ||
|
|
There was a problem hiding this comment.
nitpick I would drop this empty line.
| private static final Pattern PYLINT_DEFAULT = Pattern.compile("(.+):(\\d+):(\\d+): (\\S+): (.*)"); | ||
| private static final Pattern PATTERN_LEGACY = Pattern.compile("(.+):(\\d+): \\[(.*)\\] (.*)"); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
| logger().error("No issues information will be saved as the report file '{}' can't be read. " + | ||
| e.getClass().getSimpleName() + ": " + e.getMessage(), reportPath, e); |
There was a problem hiding this comment.
It's a little weird to me that we are mixing string formatting and string concatenation here.
| } catch (IOException e) { | ||
| throw new IllegalStateException(e); | ||
| } |
There was a problem hiding this comment.
Not sure I understand why we are doing this, executeSensorImporting has already declared that it may throw IOException
There was a problem hiding this comment.
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.
ab3802f to
f62318c
Compare
f62318c to
380f8f2
Compare
gyula-sallai-sonarsource
left a comment
There was a problem hiding this comment.
LGTM, left some subjective comments. Feel free to disregard both of them if you disagree.
| */ | ||
| public class TextReportReader { | ||
|
|
||
| private final int reportOffset; |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
25b12a9 to
fa01f66
Compare
|
Kudos, SonarQube Quality Gate passed!
|
GitOrigin-RevId: 1b88d9f35afcb9554ab9357c4c6cdbdc986e7454
No description provided.