clang-tools 22.0.0git
AvoidNSErrorInitCheck.cpp
Go to the documentation of this file.
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-exception
6//
7//===----------------------------------------------------------------------===//
8
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::objc
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
void registerMatchers(ast_matchers::MatchFinder *Finder) override