32 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#include "AvoidNSErrorInitCheck.h"10#include "clang/ASTMatchers/ASTMatchFinder.h"11 12using namespace clang::ast_matchers;13 14namespace clang::tidy::objc {15 16void AvoidNSErrorInitCheck::registerMatchers(MatchFinder *Finder) {17 Finder->addMatcher(objcMessageExpr(hasSelector("init"),18 hasReceiverType(asString("NSError *")))19 .bind("nserrorInit"),20 this);21}22 23void AvoidNSErrorInitCheck::check(const MatchFinder::MatchResult &Result) {24 const auto *MatchedExpr =25 Result.Nodes.getNodeAs<ObjCMessageExpr>("nserrorInit");26 diag(MatchedExpr->getBeginLoc(),27 "use errorWithDomain:code:userInfo: or initWithDomain:code:userInfo: to "28 "create a new NSError");29}30 31} // namespace clang::tidy::objc32