2323import java .io .IOException ;
2424import java .util .List ;
2525import org .apache .commons .io .FileUtils ;
26- import org .slf4j .Logger ;
27- import org .slf4j .LoggerFactory ;
2826import org .sonar .api .batch .fs .FilePredicates ;
2927import org .sonar .api .batch .fs .FileSystem ;
3028import org .sonar .api .batch .fs .InputFile ;
3129import org .sonar .api .batch .rule .ActiveRule ;
3230import org .sonar .api .batch .sensor .Sensor ;
3331import org .sonar .api .batch .sensor .SensorContext ;
3432import org .sonar .api .batch .sensor .SensorDescriptor ;
35- import org .sonar .api .batch .sensor .issue .NewIssue ;
3633import org .sonar .api .config .Settings ;
3734import org .sonar .api .rule .RuleKey ;
3835import org .sonar .plugins .python .Python ;
3936
4037public 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