blob: d92414c1c1c0cc7b0b578d69be388427f0e12b25 [file] [log] [blame]
Yan Zhang8c348b32017-11-30 19:05:08 +00001//===--- AvoidNSErrorInitCheck.cpp - clang-tidy----------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "AvoidNSErrorInitCheck.h"
11#include "clang/AST/ASTContext.h"
12#include "clang/ASTMatchers/ASTMatchFinder.h"
13
14using namespace clang::ast_matchers;
15
16namespace clang {
17namespace tidy {
18namespace objc {
19
20void AvoidNSErrorInitCheck::registerMatchers(MatchFinder *Finder) {
21 Finder->addMatcher(objcMessageExpr(hasSelector("init"),
22 hasReceiverType(asString("NSError *")))
23 .bind("nserrorInit"),
24 this);
25}
26
27void AvoidNSErrorInitCheck::check(const MatchFinder::MatchResult &Result) {
28 const auto *MatchedExpr =
29 Result.Nodes.getNodeAs<ObjCMessageExpr>("nserrorInit");
30 diag(MatchedExpr->getLocStart(),
31 "use errorWithDomain:code:userInfo: or initWithDomain:code:userInfo: to "
32 "create a new NSError");
33}
34
35} // namespace objc
36} // namespace tidy
37} // namespace clang