-
-
Save njames93/b99b0a8dcf88fdedf009da21f4d586a5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Adds the Diagnostic name to the Original name using ', ' as a seperator, but | |
/// makes sure the diagnostic names are sorted alphabetically | |
static std::string appendDuplicatedDiagName(StringRef Name, | |
StringRef AppendName) { | |
constexpr StringRef Delimiter = ", "; | |
SmallVector<StringRef, 2> Split; | |
Name.split(Split, Delimiter, -1, false); | |
Split.push_back(AppendName); | |
llvm::sort(Split); | |
return llvm::join(Split, Delimiter); | |
} | |
void ClangTidyDiagnosticConsumer::removeDuplicatedFixesOfAliasCheckers() { | |
using UniqueErrorSet = | |
std::set<ClangTidyError *, LessClangTidyErrorWithoutDiagnosticName>; | |
llvm::SmallSet<ClangTidyError *, 8> RemoveErrors; | |
UniqueErrorSet UniqueErrors; | |
for (auto &Error : Errors) { | |
std::pair<UniqueErrorSet::iterator, bool> Inserted = | |
UniqueErrors.insert(&Error); | |
// If we already have an error like this, just with the different | |
// DiagnosticName, remove its Fix since we don't need same fix twice | |
if (!Inserted.second) { | |
ClangTidyError *FirstError = *Inserted.first; | |
if (Error.Message.Fix == FirstError->Message.Fix) { | |
// Flag to remove the second error from diagnostics and join the diag | |
// names. | |
RemoveErrors.insert(&Error); | |
FirstError->DiagnosticName = appendDuplicatedDiagName( | |
FirstError->DiagnosticName, Error.DiagnosticName); | |
} else { | |
// Same Error message, but conflicting fix its. Ignore this case, | |
// clang-tidy will detect the conflict and issue warnings. | |
} | |
} | |
} | |
if (!RemoveErrors.empty()) { | |
Errors.erase(std::remove_if(Errors.begin(), Errors.end(), | |
[&](ClangTidyError &Error) { | |
return RemoveErrors.count(&Error) > 0; | |
}), | |
Errors.end()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment