19static const std::map<std::string, std::string> &
NameMap() {
20 static std::map<std::string, std::string> map{
21 {
"XCTAssertEqual",
"XCTAssertEqualObjects"},
22 {
"XCTAssertNotEqual",
"XCTAssertNotEqualObjects"},
29 for (
const auto &pair :
NameMap()) {
31 binaryOperator(anyOf(hasOperatorName(
"!="), hasOperatorName(
"==")),
32 isExpandedFromMacro(pair.first),
33 anyOf(hasLHS(hasType(qualType(
34 hasCanonicalType(asString(
"NSString *"))))),
35 hasRHS(hasType(qualType(
36 hasCanonicalType(asString(
"NSString *"))))))
45 for (
const auto &pair :
NameMap()) {
46 if (
const auto *root = result.Nodes.getNodeAs<BinaryOperator>(pair.first)) {
47 SourceManager *sm = result.SourceManager;
49 auto macro_callsite = sm->getImmediateMacroCallerLoc(
50 sm->getImmediateMacroCallerLoc(root->getBeginLoc()));
51 diag(macro_callsite,
"use " + pair.second +
" for comparing objects")
52 << FixItHint::CreateReplacement(
53 clang::CharSourceRange::getCharRange(
55 macro_callsite.getLocWithOffset(pair.first.length())),
DiagnosticBuilder diag(SourceLocation Loc, StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning)
Add a diagnostic with the check's name.
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
static const std::map< std::string, std::string > & NameMap()