SONARJAVA-6205 Add an agentic focused quality profile for Java#5531
SONARJAVA-6205 Add an agentic focused quality profile for Java#5531dorian-burihabwa-sonarsource wants to merge 5 commits intomasterfrom
Conversation
37eb8d7 to
0dab089
Compare
SummaryThis PR introduces a new quality profile "Sonar agentic AI" tailored for AI and agentic use cases in Java, while refactoring common profile logic to eliminate duplication. Key changes:
What reviewers should knowStart here:
Key differences from "Sonar way":
About the refactoring:
Testing:
Dependencies:
|
0dab089 to
31312fc
Compare
rombirli
left a comment
There was a problem hiding this comment.
LGTM! I just have two questions about external rules inclusion mechanism and the purpose of profileRegistrars
| for (ProfileRegistrar profileRegistrar : profileRegistrars) { | ||
| profileRegistrar.register(ruleKeys::addAll); | ||
| } |
There was a problem hiding this comment.
In test JavaAgenticWayProfileTest, profileRegistrars is always null and this part is never covered, is there a reason ?
| public void define(Context context) { | ||
| NewBuiltInQualityProfile agenticWay = context.createBuiltInQualityProfile("AI Quality Profile", Java.KEY); | ||
| Set<RuleKey> ruleKeys = QualityProfileUtils.registerRulesFromJson( | ||
| "/org/sonar/l10n/java/rules/java/Agentic_way_profile.json", |
There was a problem hiding this comment.
This string constant could be extracted in a constant SONAR_AGENTIC_WAY_PATH like SONAR_WAY_PATH in JavaSonarWayProfile
| ruleKeys.forEach(ruleKey -> agenticWay.activateRule(ruleKey.repository(), ruleKey.rule())); | ||
| agenticWay.done(); | ||
| } |
There was a problem hiding this comment.
These lines and the creation of agenticWay (or sonarWay) are repeated in JavaSonarWayProfile, maybe it could be refactored in QualityProfileUtils
static void createQualityProfile(String title, Set<RuleKey> ruleKeys) {
NewBuiltInQualityProfile way = context.createBuiltInQualityProfile(title, Java.KEY);
ruleKeys.forEach(ruleKey -> way.activateRule(ruleKey.repository(), ruleKey.rule()));
way.done();
}
}There was a problem hiding this comment.
Is there a reason this mechanism to include external rules is not present in JavaAgenticWayProfile? (Why the implementations diverge? Is there a justification?)
rombirli
left a comment
There was a problem hiding this comment.
Agentic_way_profile.json seems to be wrong
e818473 to
35e7ca4
Compare
rombirli
left a comment
There was a problem hiding this comment.
LGTM i get the exact same json quality profile file, I still have 2 refactoring proposals :
- use tsv format instead of csv to get rid of csv library (so we can simply split with '\t' instead of ';')
- use a single class that take qp name and json path instead of duplicated logic (we could also get rid of qualityprofileutils.java and put everything in this class)
| return fileName.substring(0, fileName.lastIndexOf('.')); | ||
| }) | ||
| .collect(Collectors.toSet()); | ||
| } |
There was a problem hiding this comment.
Path.endsWith(String) does not work like String.endsWith(String). On a Path, it checks whether the path ends with a complete path segment named exactly "_profile.json", not whether the filename string ends with that suffix. This predicate is always false, so profile JSON files (Sonar_way_profile.json, Agentic_way_profile.json, etc.) are never excluded from keysOfImplementedRules.
The bug is harmless today because profile filenames won't appear as rule IDs in the CSV, but the filter silently does nothing. Fix:
.filter(path -> !path.getFileName().toString().endsWith("_profile.json"))- Mark as noise
| Path.of("Path", "to", "your", "input.csv"), | ||
| RULE_DESCRIPTION_DIRECTORY.resolve("Agentic_way_profile.json"), | ||
| "AI Quality Profile" | ||
| ); |
There was a problem hiding this comment.
generate_ai_quality_profile() is missing @Test. In JUnit 5, @Disabled without @Test is a no-op — the framework never discovers the method, so the annotation provides no documentation value and could mislead a future developer into thinking this was intentionally skipped rather than just a utility method. Either add @Test so @Disabled works as intended, or remove @Disabled and leave it as a plain utility method with a descriptive Javadoc comment.
- Mark as noise
06e2ee5 to
b890cc6
Compare
Refactored to re-use the same code to initialize quality profiles assuming that all DBD and security rules should be part of the new quality profile.
b890cc6 to
7ed374a
Compare
|





No description provided.