clang-tools
22.0.0git
llvm-project
clang-tools-extra
clang-tidy
objc
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
9
#include "
AvoidNSErrorInitCheck.h
"
10
#include "clang/ASTMatchers/ASTMatchFinder.h"
11
12
using namespace
clang::ast_matchers
;
13
14
namespace
clang::tidy::objc
{
15
16
void
AvoidNSErrorInitCheck::registerMatchers
(MatchFinder *Finder) {
17
Finder->addMatcher(objcMessageExpr(hasSelector(
"init"
),
18
hasReceiverType(asString(
"NSError *"
)))
19
.bind(
"nserrorInit"
),
20
this
);
21
}
22
23
void
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
AvoidNSErrorInitCheck.h
clang::tidy::objc::AvoidNSErrorInitCheck::check
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
Definition
AvoidNSErrorInitCheck.cpp:23
clang::tidy::objc::AvoidNSErrorInitCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Definition
AvoidNSErrorInitCheck.cpp:16
clang::ast_matchers
Definition
AbseilMatcher.h:13
clang::tidy::objc
Definition
AssertEquals.cpp:16
Generated on
for clang-tools by
1.14.0