[clang-tools-extra] r319460 - add new check to find NSError init invocation
Yan Zhang via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 30 11:05:09 PST 2017
Author: wizard
Date: Thu Nov 30 11:05:09 2017
New Revision: 319460
URL: http://llvm.org/viewvc/llvm-project?rev=319460&view=rev
Log:
add new check to find NSError init invocation
Subscribers: klimek, mgorny, cfe-commits
Differential Revision: https://reviews.llvm.org/D40528
Added:
clang-tools-extra/trunk/clang-tidy/objc/AvoidNSErrorInitCheck.cpp
- copied, changed from r319459, clang-tools-extra/trunk/clang-tidy/objc/AvoidNserrorInitCheck.cpp
clang-tools-extra/trunk/clang-tidy/objc/AvoidNSErrorInitCheck.h
- copied, changed from r319459, clang-tools-extra/trunk/clang-tidy/objc/AvoidNserrorInitCheck.h
Removed:
clang-tools-extra/trunk/clang-tidy/objc/AvoidNserrorInitCheck.cpp
clang-tools-extra/trunk/clang-tidy/objc/AvoidNserrorInitCheck.h
Modified:
clang-tools-extra/trunk/docs/ReleaseNotes.rst
Copied: clang-tools-extra/trunk/clang-tidy/objc/AvoidNSErrorInitCheck.cpp (from r319459, clang-tools-extra/trunk/clang-tidy/objc/AvoidNserrorInitCheck.cpp)
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/objc/AvoidNSErrorInitCheck.cpp?p2=clang-tools-extra/trunk/clang-tidy/objc/AvoidNSErrorInitCheck.cpp&p1=clang-tools-extra/trunk/clang-tidy/objc/AvoidNserrorInitCheck.cpp&r1=319459&r2=319460&rev=319460&view=diff
==============================================================================
(empty)
Copied: clang-tools-extra/trunk/clang-tidy/objc/AvoidNSErrorInitCheck.h (from r319459, clang-tools-extra/trunk/clang-tidy/objc/AvoidNserrorInitCheck.h)
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/objc/AvoidNSErrorInitCheck.h?p2=clang-tools-extra/trunk/clang-tidy/objc/AvoidNSErrorInitCheck.h&p1=clang-tools-extra/trunk/clang-tidy/objc/AvoidNserrorInitCheck.h&r1=319459&r2=319460&rev=319460&view=diff
==============================================================================
(empty)
Removed: clang-tools-extra/trunk/clang-tidy/objc/AvoidNserrorInitCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/objc/AvoidNserrorInitCheck.cpp?rev=319459&view=auto
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/objc/AvoidNserrorInitCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/objc/AvoidNserrorInitCheck.cpp (removed)
@@ -1,37 +0,0 @@
-//===--- AvoidNSErrorInitCheck.cpp - clang-tidy----------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "AvoidNSErrorInitCheck.h"
-#include "clang/AST/ASTContext.h"
-#include "clang/ASTMatchers/ASTMatchFinder.h"
-
-using namespace clang::ast_matchers;
-
-namespace clang {
-namespace tidy {
-namespace objc {
-
-void AvoidNSErrorInitCheck::registerMatchers(MatchFinder *Finder) {
- Finder->addMatcher(objcMessageExpr(hasSelector("init"),
- hasReceiverType(asString("NSError *")))
- .bind("nserrorInit"),
- this);
-}
-
-void AvoidNSErrorInitCheck::check(const MatchFinder::MatchResult &Result) {
- const auto *MatchedExpr =
- Result.Nodes.getNodeAs<ObjCMessageExpr>("nserrorInit");
- diag(MatchedExpr->getLocStart(),
- "use errorWithDomain:code:userInfo: or initWithDomain:code:userInfo: to "
- "create a new NSError");
-}
-
-} // namespace objc
-} // namespace tidy
-} // namespace clang
Removed: clang-tools-extra/trunk/clang-tidy/objc/AvoidNserrorInitCheck.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/objc/AvoidNserrorInitCheck.h?rev=319459&view=auto
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/objc/AvoidNserrorInitCheck.h (original)
+++ clang-tools-extra/trunk/clang-tidy/objc/AvoidNserrorInitCheck.h (removed)
@@ -1,36 +0,0 @@
-//===--- AvoidNSErrorInitCheck.h - clang-tidy--------------------*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_AVOIDNSERRORINITCHECK_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_AVOIDNSERRORINITCHECK_H
-
-#include "../ClangTidy.h"
-
-namespace clang {
-namespace tidy {
-namespace objc {
-
-/// Finds usages of [NSSError init]. It is not the proper way of creating
-/// NSError. errorWithDomain:code:userInfo: should be used instead.
-///
-/// For the user-facing documentation see:
-/// http://clang.llvm.org/extra/clang-tidy/checks/objc-avoid-nserror-init.html
-class AvoidNSErrorInitCheck : public ClangTidyCheck {
- public:
- AvoidNSErrorInitCheck(StringRef Name, ClangTidyContext *Context)
- : ClangTidyCheck(Name, Context) {}
- void registerMatchers(ast_matchers::MatchFinder *Finder) override;
- void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
-};
-
-} // namespace objc
-} // namespace tidy
-} // namespace clang
-
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_AVOIDNSERRORINITCHECK_H
Modified: clang-tools-extra/trunk/docs/ReleaseNotes.rst
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/ReleaseNotes.rst?rev=319460&r1=319459&r2=319460&view=diff
==============================================================================
--- clang-tools-extra/trunk/docs/ReleaseNotes.rst (original)
+++ clang-tools-extra/trunk/docs/ReleaseNotes.rst Thu Nov 30 11:05:09 2017
@@ -57,6 +57,11 @@ The improvements are...
Improvements to clang-tidy
--------------------------
+- New `objc-avoid-nserror-init
+ <http://clang.llvm.org/extra/clang-tidy/checks/objc-avoid-nserror-init.html>`_ check
+
+ Add new check to detect the use of [NSError init].
+
- New module `fuchsia` for Fuchsia style checks.
- New module `objc` for Objective-C style checks.
More information about the cfe-commits
mailing list