Skip to content

Commit c637e2a

Browse files
committed
Some reformatting
1 parent cdc8565 commit c637e2a

File tree

12 files changed

+208
-258
lines changed

12 files changed

+208
-258
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Sonar-rust plugin
44
This plugin allows to visualize clippy lints report from the SonarQube UI
55
It is compatible with SonarQube 7.9+
66

7+
Clippy lints are listed : https://rust-lang.github.io/rust-clippy/master/
8+
79
Build plugin
810
-------------
911
`mvn clean package`

src/main/java/org/elegoff/plugins/rust/RustPlugin.java

Lines changed: 30 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -17,39 +17,34 @@
1717
*/
1818
public class RustPlugin implements Plugin {
1919

20-
private static final String EXTERNAL_ANALYZERS_CATEGORY = "External Analyzers";
21-
private static final String RUST_SUBCATEGORY = "Rust";
22-
23-
public static final String FILE_SUFFIXES_KEY = "sonar.rust.file.suffixes";
24-
25-
26-
public RustPlugin() {
27-
// Disable INFO logs for Reflections (see )
28-
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
29-
}
30-
31-
@Override
32-
public void define(Context context) {
33-
context.addExtension(RustLanguage.class);
34-
context.addExtension(RustQualityProfile.class);
35-
36-
// Add plugin settings (file extensions, etc.)
37-
context.addExtensions(RustLanguageSettings.getProperties());
38-
39-
// clippy rules
40-
context.addExtension(ClippySensor.class);
41-
context.addExtensions(
42-
PropertyDefinition.builder(ClippySensor.REPORT_PROPERTY_KEY)
43-
.name("Bandit Report Files")
44-
.description("Paths (absolute or relative) to json files with Bandit issues.")
45-
.category(EXTERNAL_ANALYZERS_CATEGORY)
46-
.subCategory(RUST_SUBCATEGORY)
47-
.onQualifiers(Qualifiers.PROJECT)
48-
.multiValues(true)
49-
.build(),
50-
ClippyRulesDefinition.class);
51-
52-
53-
54-
}
20+
private static final String EXTERNAL_ANALYZERS_CATEGORY = "External Analyzers";
21+
private static final String RUST_SUBCATEGORY = "Rust";
22+
public static final String FILE_SUFFIXES_KEY = "sonar.rust.file.suffixes";
23+
24+
public RustPlugin() {
25+
// Disable INFO logs for Reflections (see )
26+
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
27+
}
28+
29+
@Override
30+
public void define(Context context) {
31+
context.addExtension(RustLanguage.class);
32+
context.addExtension(RustQualityProfile.class);
33+
34+
// Add plugin settings (file extensions, etc.)
35+
context.addExtensions(RustLanguageSettings.getProperties());
36+
37+
// clippy rules
38+
context.addExtension(ClippySensor.class);
39+
context.addExtensions(
40+
PropertyDefinition.builder(ClippySensor.REPORT_PROPERTY_KEY)
41+
.name("Bandit Report Files")
42+
.description("Paths (absolute or relative) to json files with Bandit issues.")
43+
.category(EXTERNAL_ANALYZERS_CATEGORY)
44+
.subCategory(RUST_SUBCATEGORY)
45+
.onQualifiers(Qualifiers.PROJECT)
46+
.multiValues(true)
47+
.build(),
48+
ClippyRulesDefinition.class);
49+
}
5550
}

src/main/java/org/elegoff/plugins/rust/clippy/ClippyJsonReportReader.java

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616

1717
public class ClippyJsonReportReader {
1818
private final JSONParser jsonParser = new JSONParser();
19-
private final Consumer<Issue> consumer;
19+
private final Consumer<ClippyIssue> consumer;
2020
private static final Logger LOG = Loggers.get(ClippyJsonReportReader.class);
2121

22-
public static class Issue {
22+
public static class ClippyIssue {
2323
@Nullable
2424
String filePath;
2525
@Nullable
@@ -38,11 +38,11 @@ public static class Issue {
3838
String severity;
3939
}
4040

41-
private ClippyJsonReportReader(Consumer<Issue> consumer) {
41+
private ClippyJsonReportReader(Consumer<ClippyIssue> consumer) {
4242
this.consumer = consumer;
4343
}
4444

45-
static void read(InputStream in, Consumer<Issue> consumer) throws IOException, ParseException {
45+
static void read(InputStream in, Consumer<ClippyIssue> consumer) throws IOException, ParseException {
4646
new ClippyJsonReportReader(consumer).read(in);
4747
}
4848

@@ -55,33 +55,33 @@ private void read(InputStream in) throws IOException, ParseException {
5555
}
5656

5757
private void onResult(JSONObject result) {
58-
Issue issue = new Issue();
58+
ClippyIssue clippyIssue = new ClippyIssue();
5959

6060
JSONObject message = (JSONObject) result.get("message");
6161
if (message == null) return;
6262
JSONObject code = (JSONObject) message.get("code");
6363
if (code == null) return;
64-
issue.ruleKey = (String) code.get("code");
64+
clippyIssue.ruleKey = (String) code.get("code");
6565

66-
LOG.debug("Clippy rule found : " + issue.ruleKey);
66+
LOG.debug("Clippy rule found : " + clippyIssue.ruleKey);
6767

6868

6969
JSONArray spans = (JSONArray) message.get("spans");
70-
if ((spans == null)||spans.size()==0) return;
70+
if ((spans == null) || spans.size() == 0) return;
7171
JSONObject span = (JSONObject) spans.get(0);
72-
issue.filePath = (String) span.get("file_name");
72+
clippyIssue.filePath = (String) span.get("file_name");
7373

7474

75-
issue.message = (String) message.get("message");
75+
clippyIssue.message = (String) message.get("message");
7676

77-
issue.lineNumberStart = toInteger(span.get("line_start")) ;
78-
issue.lineNumberEnd = toInteger(span.get("line_end"));
79-
issue.colNumberStart = toInteger(span.get("column_start"));
80-
issue.colNumberEnd = toInteger(span.get("column_end")) ;
77+
clippyIssue.lineNumberStart = toInteger(span.get("line_start"));
78+
clippyIssue.lineNumberEnd = toInteger(span.get("line_end"));
79+
clippyIssue.colNumberStart = toInteger(span.get("column_start"));
80+
clippyIssue.colNumberEnd = toInteger(span.get("column_end"));
8181

82-
issue.severity = (String) message.get("level");
82+
clippyIssue.severity = (String) message.get("level");
8383

84-
consumer.accept(issue);
84+
consumer.accept(clippyIssue);
8585
}
8686

8787
private static Integer toInteger(Object value) {
@@ -91,15 +91,15 @@ private static Integer toInteger(Object value) {
9191
return null;
9292
}
9393

94-
public static InputStream toJSON(File rawReport) throws IOException{
95-
String BEGIN="{\"results\": [";
96-
String END="]}";
94+
public static InputStream toJSON(File rawReport) throws IOException {
95+
String BEGIN = "{\"results\": [";
96+
String END = "]}";
9797

9898
if (rawReport == null) {
9999
throw new FileNotFoundException();
100100
}
101101

102-
StringBuffer sb = new StringBuffer(BEGIN);
102+
StringBuffer sb = new StringBuffer(BEGIN);
103103

104104
//read text report line by line
105105
String reportPath = rawReport.getAbsolutePath();
@@ -108,22 +108,17 @@ public static InputStream toJSON(File rawReport) throws IOException{
108108
reader = new BufferedReader(new FileReader(
109109
reportPath));
110110
String line = reader.readLine();
111-
String separator="";
111+
String separator = "";
112112
while (line != null) {
113-
114-
// read next line
115-
116113
//a valid Clippy result needs to be a valid json String
117-
if (line.startsWith("{") && line.endsWith("}")){
114+
if (line.startsWith("{") && line.endsWith("}")) {
118115
sb.append(separator).append(line);
119-
separator= ",";
116+
separator = ",";
120117
}
121118
line = reader.readLine();
122119
}
123120
reader.close();
124-
125-
sb.append(END);
126-
121+
sb.append(END);
127122
InputStream in = new ByteArrayInputStream(sb.toString().getBytes());
128123
return in;
129124
}

src/main/java/org/elegoff/plugins/rust/clippy/ClippyRulesDefinition.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,10 @@
1414
public class ClippyRulesDefinition implements RulesDefinition {
1515

1616
private static final String RULES_JSON = "org/elegoff/l10n/rust/rules/rust/clippy/rules.json";
17-
18-
1917
private static final String RULE_REPOSITORY_LANGUAGE = RustLanguage.KEY;
20-
2118
private static final List<String> TEXT_FILE_EXTENSIONS = Arrays.asList(".rs");
22-
2319
static final ExternalRuleLoader RULE_LOADER = new ExternalRuleLoader(LINTER_KEY, LINTER_NAME, RULES_JSON, RULE_REPOSITORY_LANGUAGE);
2420

25-
26-
2721
@Override
2822
public void define(Context context) {
2923
RULE_LOADER.createExternalRuleRepository(context);

0 commit comments

Comments
 (0)