Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle deprecated rules in ClangTidy LLVM 19.1 #2824

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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