Skip to content

Commit

Permalink
Merge pull request #2824 from guwirth/clang-2816
Browse files Browse the repository at this point in the history
Handle deprecated rules in ClangTidy LLVM 19.1
  • Loading branch information
guwirth authored Dec 9, 2024
2 parents 6023753 + b69ea06 commit f75e8ea
Show file tree
Hide file tree
Showing 5 changed files with 175 additions and 558 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

}
Loading

0 comments on commit f75e8ea

Please sign in to comment.