diff --git a/cxx-sensors/src/main/java/org/sonar/cxx/sensors/clangtidy/ClangTidyParser.java b/cxx-sensors/src/main/java/org/sonar/cxx/sensors/clangtidy/ClangTidyParser.java index 69dfc6813..4451c67a0 100644 --- a/cxx-sensors/src/main/java/org/sonar/cxx/sensors/clangtidy/ClangTidyParser.java +++ b/cxx-sensors/src/main/java/org/sonar/cxx/sensors/clangtidy/ClangTidyParser.java @@ -119,7 +119,7 @@ private static void parseRuleIds(LineData data) { int pos = data.info.lastIndexOf('['); if (pos != -1) { for (var ruleId : data.info.substring(pos + 1, data.info.length() - 1).split(",")) { - ruleId = ruleId.trim(); + ruleId = mapDeprecatedRules(ruleId.trim()); if (data.ruleId == null) { data.ruleId = ruleId; } else { @@ -142,6 +142,76 @@ private static void parseRuleIds(LineData data) { } } + private static String mapDeprecatedRules(String ruleId) { + + // TODO: put data into hashmap + switch (ruleId) { + + // C++11 (0x) + case "clang-diagnostic-c++0x-compat": + return "clang-diagnostic-c++11-compat"; + case "clang-diagnostic-c++0x-extensions": + return "clang-diagnostic-c++11-extensions"; + case "clang-diagnostic-pre-c++0x-compat": + return "clang-diagnostic-pre-c++11-compat"; + case "clang-diagnostic-pre-c++0x-compat-pedantic": + return "clang-diagnostic-pre-c++11-compat-pedantic"; + + // C++14 (1y) + case "clang-diagnostic-c++1y-compat": + return "clang-diagnostic-c++14-compat"; + case "clang-diagnostic-c++1y-extensions": + return "clang-diagnostic-c++14-extensions"; + case "clang-diagnostic-pre-c++1y-compat": + return "clang-diagnostic-pre-c++14-compat"; + case "clang-diagnostic-pre-c++1y-compat-pedantic": + return "clang-diagnostic-pre-c++14-compat-pedantic"; + + // C++17 (1z) + case "clang-diagnostic-c++1z-compat": + return "clang-diagnostic-c++17-compat"; + case "clang-diagnostic-c++1z-extensions": + return "clang-diagnostic-c++17-extensions"; + case "clang-diagnostic-pre-c++1z-compat": + return "clang-diagnostic-pre-c++17-compat"; + case "clang-diagnostic-pre-c++1z-compat-pedantic": + return "clang-diagnostic-pre-c++17-compat-pedantic"; + + // C++20 (2a) + case "clang-diagnostic-c++2a-compat": + return "clang-diagnostic-c++20-compat"; + case "clang-diagnostic-c++2a-extensions": + return "clang-diagnostic-c++20-extensions"; + case "clang-diagnostic-pre-c++2a-compat": + return "clang-diagnostic-pre-c++20-compat"; + case "clang-diagnostic-pre-c++2a-compat-pedantic": + return "clang-diagnostic-pre-c++20-compat-pedantic"; + + // C++23 (2b) + case "clang-diagnostic-c++2b-compat": + return "clang-diagnostic-c++23-compat"; + case "clang-diagnostic-c++2b-extensions": + return "clang-diagnostic-c++23-extensions"; + case "clang-diagnostic-pre-c++2b-compat": + return "clang-diagnostic-pre-c++23-compat"; + case "clang-diagnostic-pre-c++2b-compat-pedantic": + return "clang-diagnostic-pre-c++23-compat-pedantic"; + + // C++26 (2c) + case "clang-diagnostic-c++2c-compat": + return "clang-diagnostic-c++26-compat"; + case "clang-diagnostic-c++2c-extensions": + return "clang-diagnostic-c++26-extensions"; + case "clang-diagnostic-pre-c++2c-compat": + return "clang-diagnostic-pre-c++26-compat"; + case "clang-diagnostic-pre-c++2c-compat-pedantic": + return "clang-diagnostic-pre-c++26-compat-pedantic"; + + default: + return ruleId; + } + } + private static String getDefaultRuleId(String level) { return map.getOrDefault(level, "clang-diagnostic-unknown"); } diff --git a/cxx-sensors/src/main/java/org/sonar/cxx/sensors/clangtidy/CxxClangTidyRuleRepository.java b/cxx-sensors/src/main/java/org/sonar/cxx/sensors/clangtidy/CxxClangTidyRuleRepository.java index 53cc538c6..8796b77e9 100644 --- a/cxx-sensors/src/main/java/org/sonar/cxx/sensors/clangtidy/CxxClangTidyRuleRepository.java +++ b/cxx-sensors/src/main/java/org/sonar/cxx/sensors/clangtidy/CxxClangTidyRuleRepository.java @@ -42,7 +42,95 @@ public CxxClangTidyRuleRepository(ServerFileSystem fileSystem, RulesDefinitionXm @Override public void prepareRule(NewRule rule) { - rule.addDeprecatedRuleKey("ClangTidy", rule.key()); // V1.3 repository name + // V1.3 repository name + rule.addDeprecatedRuleKey("ClangTidy", rule.key()); + + switch (rule.key()) { + + // C++11 (0x) + case "clang-diagnostic-c++11-compat": + rule.addDeprecatedRuleKey(KEY, "clang-diagnostic-c++0x-compat"); + break; + case "clang-diagnostic-c++11-extensions": + rule.addDeprecatedRuleKey(KEY, "clang-diagnostic-c++0x-extensions"); + break; + case "clang-diagnostic-pre-c++11-compat": + rule.addDeprecatedRuleKey(KEY, "clang-diagnostic-pre-c++0x-compat"); + break; + case "clang-diagnostic-pre-c++11-compat-pedantic": + rule.addDeprecatedRuleKey(KEY, "clang-diagnostic-pre-c++0x-compat-pedantic"); + break; + + // C++14 (1y) + case "clang-diagnostic-c++14-compat": + rule.addDeprecatedRuleKey(KEY, "clang-diagnostic-c++1y-compat"); + break; + case "clang-diagnostic-c++14-extensions": + rule.addDeprecatedRuleKey(KEY, "clang-diagnostic-c++1y-extensions"); + break; + case "clang-diagnostic-pre-c++14-compat": + rule.addDeprecatedRuleKey(KEY, "clang-diagnostic-pre-c++1y-compat"); + break; + case "clang-diagnostic-pre-c++14-compat-pedantic": + rule.addDeprecatedRuleKey(KEY, "clang-diagnostic-pre-c++1y-compat-pedantic"); + break; + + // C++17 (1z) + case "clang-diagnostic-c++17-compat": + rule.addDeprecatedRuleKey(KEY, "clang-diagnostic-c++1z-compat"); + break; + case "clang-diagnostic-c++17-extensions": + rule.addDeprecatedRuleKey(KEY, "clang-diagnostic-c++1z-extensions"); + break; + case "clang-diagnostic-pre-c++17-compat": + rule.addDeprecatedRuleKey(KEY, "clang-diagnostic-pre-c++1z-compat"); + break; + case "clang-diagnostic-pre-c++17-compat-pedantic": + rule.addDeprecatedRuleKey(KEY, "clang-diagnostic-pre-c++1z-compat-pedantic"); + break; + + // C++20 (2a) + case "clang-diagnostic-c++20-compat": + rule.addDeprecatedRuleKey(KEY, "clang-diagnostic-c++2a-compat"); + break; + case "clang-diagnostic-c++20-extensions": + rule.addDeprecatedRuleKey(KEY, "clang-diagnostic-c++2a-extensions"); + break; + case "clang-diagnostic-pre-c++20-compat": + rule.addDeprecatedRuleKey(KEY, "clang-diagnostic-pre-c++2a-compat"); + break; + case "clang-diagnostic-pre-c++20-compat-pedantic": + rule.addDeprecatedRuleKey(KEY, "clang-diagnostic-pre-c++2a-compat-pedantic"); + break; + + // C++23 (2b) + case "clang-diagnostic-c++23-compat": + rule.addDeprecatedRuleKey(KEY, "clang-diagnostic-c++2b-compat"); + break; + case "clang-diagnostic-c++23-extensions": + rule.addDeprecatedRuleKey(KEY, "clang-diagnostic-c++2b-extensions"); + break; + case "clang-diagnostic-pre-c++23-compat": + rule.addDeprecatedRuleKey(KEY, "clang-diagnostic-pre-c++2b-compat"); + break; + case "clang-diagnostic-pre-c++23-compat-pedantic": + rule.addDeprecatedRuleKey(KEY, "clang-diagnostic-pre-c++2b-compat-pedantic"); + break; + + // C++26 (2c) + case "clang-diagnostic-c++26-compat": + rule.addDeprecatedRuleKey(KEY, "clang-diagnostic-c++2c-compat"); + break; + case "clang-diagnostic-c++26-extensions": + rule.addDeprecatedRuleKey(KEY, "clang-diagnostic-c++2c-extensions"); + break; + case "clang-diagnostic-pre-c++26-compat": + rule.addDeprecatedRuleKey(KEY, "clang-diagnostic-pre-c++2c-compat"); + break; + case "clang-diagnostic-pre-c++26-compat-pedantic": + rule.addDeprecatedRuleKey(KEY, "clang-diagnostic-pre-c++2c-compat-pedantic"); + break; + } } } diff --git a/cxx-sensors/src/main/resources/clangtidy.xml b/cxx-sensors/src/main/resources/clangtidy.xml index 4e3ab11c7..883374709 100644 --- a/cxx-sensors/src/main/resources/clangtidy.xml +++ b/cxx-sensors/src/main/resources/clangtidy.xml @@ -21046,178 +21046,6 @@ Derived(); // and so temporary construction is okay INFO - - clang-diagnostic-c++0x-compat - clang-diagnostic-c++0x-compat - - Diagnostic text:

- -

References

-

Diagnostic flags in Clang

]]> -
- CRITICAL -
- - clang-diagnostic-c++0x-extensions - clang-diagnostic-c++0x-extensions - - Diagnostic text:

- -

References

-

Diagnostic flags in Clang

]]> -
- INFO -
- - clang-diagnostic-c++0x-narrowing - clang-diagnostic-c++0x-narrowing - - Diagnostic text:

- -

References

-

Diagnostic flags in Clang

]]> -
- CRITICAL -
clang-diagnostic-c++11-compat clang-diagnostic-c++11-compat @@ -22155,132 +21983,6 @@ Derived(); // and so temporary construction is okay INFO - - clang-diagnostic-c++1y-extensions - clang-diagnostic-c++1y-extensions - - Diagnostic text:

- -

References

-

Diagnostic flags in Clang

]]> -
- INFO -
- - clang-diagnostic-c++1z-compat - clang-diagnostic-c++1z-compat - - Diagnostic text:

- -

References

-

Diagnostic flags in Clang

]]> -
- INFO -
- - clang-diagnostic-c++1z-compat-mangling - clang-diagnostic-c++1z-compat-mangling - - Diagnostic text:

- -

References

-

Diagnostic flags in Clang

]]> -
- INFO -
- - clang-diagnostic-c++1z-extensions - clang-diagnostic-c++1z-extensions - - Diagnostic text:

- -

References

-

Diagnostic flags in Clang

]]> -
- INFO -
clang-diagnostic-c++20-attribute-extensions clang-diagnostic-c++20-attribute-extensions @@ -22538,195 +22240,6 @@ Derived(); // and so temporary construction is okay INFO - - clang-diagnostic-c++2a-compat - clang-diagnostic-c++2a-compat - - Diagnostic text:

- -

References

-

Diagnostic flags in Clang

]]> -
- INFO -
- - clang-diagnostic-c++2a-compat-pedantic - clang-diagnostic-c++2a-compat-pedantic - - Diagnostic text:

- -

References

-

Diagnostic flags in Clang

]]> -
- INFO -
- - clang-diagnostic-c++2a-extensions - clang-diagnostic-c++2a-extensions - - Diagnostic text:

- -

References

-

Diagnostic flags in Clang

]]> -
- INFO -
- - clang-diagnostic-c++2b-extensions - clang-diagnostic-c++2b-extensions - - Diagnostic text:

- -

References

-

Diagnostic flags in Clang

]]> -
- INFO -
- - clang-diagnostic-c++2c-compat - clang-diagnostic-c++2c-compat - - Diagnostic text:

- -

References

-

Diagnostic flags in Clang

]]> -
- INFO -
- - clang-diagnostic-c++2c-extensions - clang-diagnostic-c++2c-extensions - - Diagnostic text:

- -

References

-

Diagnostic flags in Clang

]]> -
- INFO -
clang-diagnostic-c++98-c++11-c++14-c++17-compat clang-diagnostic-c++98-c++11-c++14-c++17-compat @@ -32784,74 +32297,6 @@ Derived(); // and so temporary construction is okay INFO - - clang-diagnostic-pre-c++2b-compat - clang-diagnostic-pre-c++2b-compat - - Diagnostic text:

- -

References

-

Diagnostic flags in Clang

]]> -
- INFO -
- - clang-diagnostic-pre-c++2b-compat-pedantic - clang-diagnostic-pre-c++2b-compat-pedantic - - Diagnostic text:

- -

References

-

Diagnostic flags in Clang

]]> -
- INFO -
- - clang-diagnostic-pre-c++2c-compat - clang-diagnostic-pre-c++2c-compat - - Diagnostic text:

- -

References

-

Diagnostic flags in Clang

]]> -
- INFO -
- - clang-diagnostic-pre-c++2c-compat-pedantic - clang-diagnostic-pre-c++2c-compat-pedantic - - Diagnostic text:

- -

References

-

Diagnostic flags in Clang

]]> -
- INFO -
clang-diagnostic-pre-c11-compat clang-diagnostic-pre-c11-compat diff --git a/cxx-sensors/src/main/resources/rules.xsd b/cxx-sensors/src/main/resources/rules.xsd index 7694fe346..b8caed80b 100644 --- a/cxx-sensors/src/main/resources/rules.xsd +++ b/cxx-sensors/src/main/resources/rules.xsd @@ -62,6 +62,20 @@ + + + + + + + + + + diff --git a/cxx-sensors/src/test/java/org/sonar/cxx/sensors/clangtidy/CxxClangTidyRuleRepositoryTest.java b/cxx-sensors/src/test/java/org/sonar/cxx/sensors/clangtidy/CxxClangTidyRuleRepositoryTest.java index bb964af03..eb6fe8c6b 100644 --- a/cxx-sensors/src/test/java/org/sonar/cxx/sensors/clangtidy/CxxClangTidyRuleRepositoryTest.java +++ b/cxx-sensors/src/test/java/org/sonar/cxx/sensors/clangtidy/CxxClangTidyRuleRepositoryTest.java @@ -36,7 +36,7 @@ void createRulesTest() { def.define(context); RulesDefinition.Repository repo = context.repository(CxxClangTidyRuleRepository.KEY); - assertThat(repo.rules()).hasSize(1572); + assertThat(repo.rules()).hasSize(1555); } }