Hello @ ganncamp
Source : Java project
Actual :
- We use SonarQbue for code quality and coverage.
- We received Severity issues, and so on, while analyzing the sonar report.
- The report issue count is quite high
- Those issues we are fixing manually
Expectation :
- I would like to fix the issue like Severities automatically using any libraries or tools
- Without manual work, we are expecting to fix the issue
Below are my ideas to fix 
- Using Sonar web api (SonarQube) to get the issue list (https://company.sonar.com/api/issues/search?severities=MINOR&componentKeys=AJI252-api&branch=develop&statuses=OPEN)
- Through java code,
a) I am going to iterate the issue list.
b) Inside the loop, I have written some logics based on rule to replace the code using line number, which is taken from list of JSON
c) It is working fine
Sample Code below,
{
“total”: 2593,
“p”: 1,
“ps”: 100,
“paging”: {
“pageIndex”: 1,
“pageSize”: 100,
“total”: 2593
},
“effortTotal”: 9719,
“issues”: [
{
“key”: “uytututyhhh”,
“rule”: “java:S2333”,
“severity”: “MINOR”,
“component”: “project-123-api:src/main/java/com/action/TestServie.java”,
“project”: “project-123-api”,
“line”: 20,
“hash”: “2a16eb52daca1405aef84621a1768287”,
“textRange”: {
“startLine”: 20,
“endLine”: 20,
“startOffset”: 1,
“endOffset”: 7
},
“flows”: ,
“status”: “OPEN”,
“message”: “"public" is redundant in this context.”,
“effort”: “2min”,
“debt”: “2min”,
“author”: “”,
“tags”: [
“clumsy”,
“finding”
],
“creationDate”: “2023-07-21T07:07:18+0000”,
“updateDate”: “2023-07-21T07:07:18+0000”,
“type”: “CODE_SMELL”,
“scope”: “MAIN”,
“quickFixAvailable”: false,
“messageFormattings”:
}
]
}
void startChangeTheOriginalData(String ruleId, String filePath, int lineNumber) {
switch (ruleId) {
case RuleIdConstants.MINOR_JAVA_S1858:
FileToStringReplace fileReplace = new FileToStringReplace();
fileReplace.startApplyRuleS1858(filePath, lineNumber);
break;
default:
break;
}
}
String wordToReplace = "";
String newWord = "";
Path path = Path.of(filePath);
try (Stream<String> stream = Files.lines(path)) {
List<String> lines = stream.collect(Collectors.toList());
List<String> modifiedLines = new ArrayList<>();
logics here........................
Files.write(Path.of(filePath), modifiedLines, StandardOpenOption.TRUNCATE_EXISTING);
} catch (Exception e) {
}
private static String replaceWord(String line, String wordToReplace, String newWord) {
//logic here
return line ;
Please check above code logics whether its correct or wrong ,
Please suggest any good solution to fix the automatic way …
Thanks you …