diff --git a/python-checks/src/main/resources/org/sonar/l10n/py/rules/python/Agent_quality_profile.json b/python-checks/src/main/resources/org/sonar/l10n/py/rules/python/Agent_quality_profile.json new file mode 100644 index 000000000..e077650fc --- /dev/null +++ b/python-checks/src/main/resources/org/sonar/l10n/py/rules/python/Agent_quality_profile.json @@ -0,0 +1,220 @@ +{ + "name": "Agent Quality Profile", + "ruleKeys": [ + "S104", + "S1045", + "S107", + "S108", + "S1142", + "S1143", + "S1172", + "S1244", + "S134", + "S138", + "S1523", + "S1656", + "S1700", + "S1716", + "S1717", + "S1751", + "S1763", + "S1764", + "S1862", + "S2053", + "S2068", + "S2077", + "S2115", + "S2159", + "S2190", + "S2201", + "S2245", + "S2257", + "S2275", + "S2612", + "S2711", + "S2712", + "S2733", + "S2734", + "S2755", + "S2757", + "S2823", + "S2876", + "S3329", + "S3358", + "S3403", + "S3699", + "S3776", + "S3827", + "S3862", + "S3923", + "S3981", + "S3984", + "S3985", + "S4143", + "S4423", + "S4426", + "S4433", + "S4502", + "S4721", + "S4784", + "S4787", + "S4790", + "S4792", + "S4823", + "S4828", + "S4829", + "S4830", + "S5042", + "S5247", + "S5300", + "S5332", + "S5344", + "S5439", + "S5443", + "S5445", + "S5527", + "S5542", + "S5547", + "S5549", + "S5607", + "S5632", + "S5642", + "S5644", + "S5659", + "S5707", + "S5708", + "S5714", + "S5717", + "S5719", + "S5722", + "S5724", + "S5756", + "S5796", + "S5807", + "S5828", + "S5845", + "S5850", + "S5852", + "S5855", + "S5856", + "S5868", + "S5905", + "S5915", + "S5953", + "S5994", + "S5996", + "S6001", + "S6002", + "S6249", + "S6265", + "S6270", + "S6275", + "S6281", + "S6302", + "S6303", + "S6304", + "S6308", + "S6317", + "S6319", + "S6323", + "S6327", + "S6328", + "S6329", + "S6330", + "S6332", + "S6333", + "S6377", + "S6418", + "S6437", + "S6463", + "S6468", + "S6540", + "S6543", + "S6552", + "S6560", + "S6662", + "S6663", + "S6709", + "S6714", + "S6725", + "S6727", + "S6729", + "S6734", + "S6735", + "S6740", + "S6741", + "S6779", + "S6781", + "S6785", + "S6786", + "S6799", + "S6863", + "S6882", + "S6883", + "S6887", + "S6890", + "S6894", + "S6900", + "S6903", + "S6908", + "S6911", + "S6918", + "S6919", + "S6925", + "S6928", + "S6929", + "S6971", + "S6972", + "S6973", + "S6974", + "S6978", + "S6982", + "S6984", + "S6985", + "S7483", + "S7484", + "S7487", + "S7488", + "S7489", + "S7490", + "S7493", + "S7497", + "S7499", + "S7501", + "S7502", + "S7506", + "S7507", + "S7514", + "S7515", + "S7608", + "S7609", + "S7613", + "S7617", + "S7618", + "S7619", + "S7620", + "S7621", + "S7625", + "S7931", + "S7932", + "S7942", + "S7943", + "S8370", + "S8371", + "S8374", + "S8375", + "S8385", + "S8389", + "S8392", + "S8396", + "S8400", + "S8401", + "S8405", + "S8409", + "S8411", + "S8414", + "S905", + "S930", + "S935" + ] +} \ No newline at end of file diff --git a/python-commons/src/main/java/org/sonar/plugins/python/PythonAgentQualityProfile.java b/python-commons/src/main/java/org/sonar/plugins/python/PythonAgentQualityProfile.java new file mode 100644 index 000000000..c21fa6a77 --- /dev/null +++ b/python-commons/src/main/java/org/sonar/plugins/python/PythonAgentQualityProfile.java @@ -0,0 +1,60 @@ +/* + * SonarQube Python Plugin + * Copyright (C) 2011-2025 SonarSource Sàrl + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the Sonar Source-Available License Version 1, as published by SonarSource SA. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the Sonar Source-Available License for more details. + * + * You should have received a copy of the Sonar Source-Available License + * along with this program; if not, see https://sonarsource.com/license/ssal/ + */ +package org.sonar.plugins.python; + +import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition; +import org.sonar.plugins.python.editions.RepositoryInfoProvider; +import org.sonar.plugins.python.editions.RepositoryInfoProvider.RepositoryInfo; +import org.sonarsource.analyzer.commons.BuiltInQualityProfileJsonLoader; + +/** + * Agent Quality Profile - Built-in profile focused on security, reliability, and code complexity + * + * This profile activates rules that help maintain code quality for AI agents by focusing on: + * - Security vulnerabilities and security hotspots + * - Reliability issues (bugs) + * - Code complexity metrics (cognitive complexity, cyclomatic complexity, etc.) + */ +public class PythonAgentQualityProfile implements BuiltInQualityProfilesDefinition { + + static final String PROFILE_NAME = "Agent Quality Profile"; + static final String AGENT_PROFILE_LOCATION = "org/sonar/l10n/py/rules/python/Agent_quality_profile.json"; + + private final RepositoryInfoProvider[] editionMetadataProviders; + + public PythonAgentQualityProfile(RepositoryInfoProvider[] editionMetadataProviders) { + this.editionMetadataProviders = editionMetadataProviders; + } + + @Override + public void define(Context context) { + NewBuiltInQualityProfile profile = context.createBuiltInQualityProfile(PROFILE_NAME, Python.KEY); + + for (RepositoryInfoProvider repositoryInfoProvider : editionMetadataProviders) { + registerRulesForEdition(repositoryInfoProvider, profile); + } + + profile.done(); + } + + private static void registerRulesForEdition(RepositoryInfoProvider repositoryInfoProvider, NewBuiltInQualityProfile profile) { + RepositoryInfo repositoryInfo = repositoryInfoProvider.getInfo(); + // Load the Agent Quality Profile instead of Sonar way profile + BuiltInQualityProfileJsonLoader.load(profile, repositoryInfo.repositoryKey(), AGENT_PROFILE_LOCATION); + profile.activeRules().removeIf(rule -> repositoryInfo.disabledRules().contains(rule.ruleKey())); + } +} diff --git a/python-commons/src/main/java/org/sonar/plugins/python/PythonExtensions.java b/python-commons/src/main/java/org/sonar/plugins/python/PythonExtensions.java index bd67a8950..4145c3d30 100644 --- a/python-commons/src/main/java/org/sonar/plugins/python/PythonExtensions.java +++ b/python-commons/src/main/java/org/sonar/plugins/python/PythonExtensions.java @@ -76,6 +76,7 @@ public static void addCommonExtensions(Plugin.Context context) { Python.class, PythonProfile.class, + PythonAgentQualityProfile.class, PythonSensor.class, PythonRuleRepository.class,