Skip to content

Commit 9c445aa

Browse files
pynicolasalban-auzeill
authored andcommitted
SONARPY-235 Factorize code between PylintSensor and PylintImportSensor
1 parent ff2289e commit 9c445aa

2 files changed

Lines changed: 3 additions & 20 deletions

File tree

sonar-python-plugin/src/main/java/org/sonar/plugins/python/pylint/PylintImportSensor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ private static void saveIssues(List<Issue> issues, SensorContext context) {
111111
}
112112
}
113113

114-
private static void processRule(Issue pylintIssue, InputFile pyfile, @Nullable ActiveRule rule, SensorContext context) {
114+
public static void processRule(Issue pylintIssue, InputFile pyfile, @Nullable ActiveRule rule, SensorContext context) {
115115
if (rule != null) {
116116
NewIssue newIssue = context
117117
.newIssue()

sonar-python-plugin/src/main/java/org/sonar/plugins/python/pylint/PylintSensor.java

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,19 @@
2323
import java.io.IOException;
2424
import java.util.List;
2525
import org.apache.commons.io.FileUtils;
26-
import org.slf4j.Logger;
27-
import org.slf4j.LoggerFactory;
2826
import org.sonar.api.batch.fs.FilePredicates;
2927
import org.sonar.api.batch.fs.FileSystem;
3028
import org.sonar.api.batch.fs.InputFile;
3129
import org.sonar.api.batch.rule.ActiveRule;
3230
import org.sonar.api.batch.sensor.Sensor;
3331
import org.sonar.api.batch.sensor.SensorContext;
3432
import org.sonar.api.batch.sensor.SensorDescriptor;
35-
import org.sonar.api.batch.sensor.issue.NewIssue;
3633
import org.sonar.api.config.Settings;
3734
import org.sonar.api.rule.RuleKey;
3835
import org.sonar.plugins.python.Python;
3936

4037
public class PylintSensor implements Sensor {
4138

42-
private static final Logger LOG = LoggerFactory.getLogger(PylintSensor.class);
43-
4439
private PylintConfiguration conf;
4540
private Settings settings;
4641

@@ -92,7 +87,7 @@ public void execute(SensorContext sensorContext) {
9287
}
9388
}
9489

95-
protected void analyzeFile(SensorContext context, InputFile file, File out) throws IOException {
90+
private void analyzeFile(SensorContext context, InputFile file, File out) throws IOException {
9691
FileSystem fileSystem = context.fileSystem();
9792

9893
String pylintConfigPath = conf.getPylintConfigPath(fileSystem);
@@ -103,19 +98,7 @@ protected void analyzeFile(SensorContext context, InputFile file, File out) thro
10398

10499
for (Issue pylintIssue : issues) {
105100
ActiveRule rule = context.activeRules().find(RuleKey.of(PylintRuleRepository.REPOSITORY_KEY, pylintIssue.getRuleId()));
106-
107-
if (rule != null) {
108-
NewIssue newIssue = context
109-
.newIssue()
110-
.forRule(rule.ruleKey());
111-
newIssue.at(newIssue.newLocation()
112-
.on(file)
113-
.at(file.selectLine(pylintIssue.getLine()))
114-
.message(pylintIssue.getDescription()));
115-
newIssue.save();
116-
} else {
117-
LOG.warn("Pylint rule '{}' is unknown in Sonar", pylintIssue.getRuleId());
118-
}
101+
PylintImportSensor.processRule(pylintIssue, file, rule, context);
119102
}
120103
}
121104

0 commit comments

Comments
 (0)