Author: Rashmi Mudduluru Date: 2022-05-10T14:53:47-07:00 New Revision: e1902e880c695e5dd569db4985ec22a56c311c81
URL: https://github.com/llvm/llvm-project/commit/e1902e880c695e5dd569db4985ec22a56c311c81 DIFF: https://github.com/llvm/llvm-project/commit/e1902e880c695e5dd569db4985ec22a56c311c81.diff LOG: adding checker for NSDateFormatter Added: clang-tools-extra/clang-tidy/objc/NsdateformatterCheck.cpp clang-tools-extra/clang-tidy/objc/NsdateformatterCheck.h clang-tools-extra/docs/clang-tidy/checks/objc-NSDateFormatter.rst clang-tools-extra/test/clang-tidy/checkers/objc-NSDateFormatter.cpp Modified: clang-tools-extra/clang-tidy/add_new_check.py clang-tools-extra/clang-tidy/objc/CMakeLists.txt clang-tools-extra/clang-tidy/objc/ObjCTidyModule.cpp clang-tools-extra/docs/ReleaseNotes.rst clang-tools-extra/docs/clang-tidy/checks/list.rst Removed: ################################################################################ diff --git a/clang-tools-extra/clang-tidy/add_new_check.py b/clang-tools-extra/clang-tidy/add_new_check.py old mode 100644 new mode 100755 diff --git a/clang-tools-extra/clang-tidy/objc/CMakeLists.txt b/clang-tools-extra/clang-tidy/objc/CMakeLists.txt index 1129c6aa729f8..b64fbc386542d 100644 --- a/clang-tools-extra/clang-tidy/objc/CMakeLists.txt +++ b/clang-tools-extra/clang-tidy/objc/CMakeLists.txt @@ -10,6 +10,7 @@ add_clang_library(clangTidyObjCModule ForbiddenSubclassingCheck.cpp MissingHashCheck.cpp NSInvocationArgumentLifetimeCheck.cpp + NsdateformatterCheck.cpp ObjCTidyModule.cpp PropertyDeclarationCheck.cpp SuperSelfCheck.cpp diff --git a/clang-tools-extra/clang-tidy/objc/NsdateformatterCheck.cpp b/clang-tools-extra/clang-tidy/objc/NsdateformatterCheck.cpp new file mode 100644 index 0000000000000..ec1832e5f375b --- /dev/null +++ b/clang-tools-extra/clang-tidy/objc/NsdateformatterCheck.cpp @@ -0,0 +1,37 @@ +//===--- NsdateformatterCheck.cpp - clang-tidy ----------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "NsdateformatterCheck.h" +#include "clang/AST/ASTContext.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" + +using namespace clang::ast_matchers; + +namespace clang { +namespace tidy { +namespace objc { + +void NsdateformatterCheck::registerMatchers(MatchFinder *Finder) { + // FIXME: Add matchers. + Finder->addMatcher(functionDecl().bind("x"), this); +} + +void NsdateformatterCheck::check(const MatchFinder::MatchResult &Result) { + // FIXME: Add callback implementation. + const auto *MatchedDecl = Result.Nodes.getNodeAs<FunctionDecl>("x"); + if (!MatchedDecl->getIdentifier() || MatchedDecl->getName().startswith("awesome_")) + return; + diag(MatchedDecl->getLocation(), "function %0 is insufficiently awesome") + << MatchedDecl; + diag(MatchedDecl->getLocation(), "insert 'awesome'", DiagnosticIDs::Note) + << FixItHint::CreateInsertion(MatchedDecl->getLocation(), "awesome_"); +} + +} // namespace objc +} // namespace tidy +} // namespace clang diff --git a/clang-tools-extra/clang-tidy/objc/NsdateformatterCheck.h b/clang-tools-extra/clang-tidy/objc/NsdateformatterCheck.h new file mode 100644 index 0000000000000..e85abbe12dead --- /dev/null +++ b/clang-tools-extra/clang-tidy/objc/NsdateformatterCheck.h @@ -0,0 +1,34 @@ +//===--- NsdateformatterCheck.h - clang-tidy --------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_NSDATEFORMATTERCHECK_H +#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_NSDATEFORMATTERCHECK_H + +#include "../ClangTidyCheck.h" + +namespace clang { +namespace tidy { +namespace objc { + +/// FIXME: Write a short description. +/// +/// For the user-facing documentation see: +/// http://clang.llvm.org/extra/clang-tidy/checks/objc-NSDateFormatter.html +class NsdateformatterCheck : public ClangTidyCheck { +public: + NsdateformatterCheck(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_NSDATEFORMATTERCHECK_H diff --git a/clang-tools-extra/clang-tidy/objc/ObjCTidyModule.cpp b/clang-tools-extra/clang-tidy/objc/ObjCTidyModule.cpp index 3a5bf7dc31ac2..47b5f88d50428 100644 --- a/clang-tools-extra/clang-tidy/objc/ObjCTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/objc/ObjCTidyModule.cpp @@ -15,6 +15,7 @@ #include "ForbiddenSubclassingCheck.h" #include "MissingHashCheck.h" #include "NSInvocationArgumentLifetimeCheck.h" +#include "NsdateformatterCheck.h" #include "PropertyDeclarationCheck.h" #include "SuperSelfCheck.h" @@ -27,6 +28,8 @@ namespace objc { class ObjCModule : public ClangTidyModule { public: void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override { + CheckFactories.registerCheck<NsdateformatterCheck>( + "objc-NSDateFormatter"); CheckFactories.registerCheck<AvoidNSErrorInitCheck>( "objc-avoid-nserror-init"); CheckFactories.registerCheck<AssertEquals>("objc-assert-equals"); diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 00124b0cad75d..605b3d73e6459 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -124,6 +124,11 @@ New checks Replaces groups of adjacent macros with an unscoped anonymous enum. +- New :doc:`objc-NSDateFormatter + <clang-tidy/checks/objc-NSDateFormatter>` check. + + FIXME: add release notes. + - New :doc:`portability-std-allocator-const <clang-tidy/checks/portability-std-allocator-const>` check. Report use of ``std::vector<const T>`` (and similar containers of const diff --git a/clang-tools-extra/docs/clang-tidy/checks/list.rst b/clang-tools-extra/docs/clang-tidy/checks/list.rst index cfab8a01e42d3..e4ef99f155d19 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/list.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/list.rst @@ -84,7 +84,7 @@ Clang-Tidy Checks `bugprone-posix-return <bugprone-posix-return.html>`_, "Yes" `bugprone-redundant-branch-condition <bugprone-redundant-branch-condition.html>`_, "Yes" `bugprone-reserved-identifier <bugprone-reserved-identifier.html>`_, "Yes" - `bugprone-shared-ptr-array-mismatch <bugprone-shared-ptr-array-mismatch.html>`_, "Yes" + `bugprone-shared-ptr-array-mismatch <bugprone-shared-ptr-array-mismatch.html>`_, `bugprone-signal-handler <bugprone-signal-handler.html>`_, `bugprone-signed-char-misuse <bugprone-signed-char-misuse.html>`_, `bugprone-sizeof-container <bugprone-sizeof-container.html>`_, @@ -105,7 +105,7 @@ Clang-Tidy Checks `bugprone-terminating-continue <bugprone-terminating-continue.html>`_, "Yes" `bugprone-throw-keyword-missing <bugprone-throw-keyword-missing.html>`_, `bugprone-too-small-loop-variable <bugprone-too-small-loop-variable.html>`_, - `bugprone-unchecked-optional-access <bugprone-unchecked-optional-access.html>`_, "Yes" + `bugprone-unchecked-optional-access <bugprone-unchecked-optional-access.html>`_, `bugprone-undefined-memory-manipulation <bugprone-undefined-memory-manipulation.html>`_, `bugprone-undelegated-constructor <bugprone-undelegated-constructor.html>`_, `bugprone-unhandled-exception-at-new <bugprone-unhandled-exception-at-new.html>`_, @@ -114,7 +114,7 @@ Clang-Tidy Checks `bugprone-unused-return-value <bugprone-unused-return-value.html>`_, `bugprone-use-after-move <bugprone-use-after-move.html>`_, `bugprone-virtual-near-miss <bugprone-virtual-near-miss.html>`_, "Yes" - `cert-dcl21-cpp <cert-dcl21-cpp.html>`_, "Yes" + `cert-dcl21-cpp <cert-dcl21-cpp.html>`_, `cert-dcl50-cpp <cert-dcl50-cpp.html>`_, `cert-dcl58-cpp <cert-dcl58-cpp.html>`_, `cert-env33-c <cert-env33-c.html>`_, @@ -263,6 +263,7 @@ Clang-Tidy Checks `modernize-use-using <modernize-use-using.html>`_, "Yes" `mpi-buffer-deref <mpi-buffer-deref.html>`_, "Yes" `mpi-type-mismatch <mpi-type-mismatch.html>`_, "Yes" + `objc-NSDateFormatter <objc-NSDateFormatter.html>`_, "Yes" `objc-assert-equals <objc-assert-equals.html>`_, "Yes" `objc-avoid-nserror-init <objc-avoid-nserror-init.html>`_, `objc-dealloc-in-category <objc-dealloc-in-category.html>`_, diff --git a/clang-tools-extra/docs/clang-tidy/checks/objc-NSDateFormatter.rst b/clang-tools-extra/docs/clang-tidy/checks/objc-NSDateFormatter.rst new file mode 100644 index 0000000000000..1350c9d0d2447 --- /dev/null +++ b/clang-tools-extra/docs/clang-tidy/checks/objc-NSDateFormatter.rst @@ -0,0 +1,6 @@ +.. title:: clang-tidy - objc-NSDateFormatter + +objc-NSDateFormatter +==================== + +FIXME: Describe what patterns does the check detect and why. Give examples. diff --git a/clang-tools-extra/test/clang-tidy/checkers/objc-NSDateFormatter.cpp b/clang-tools-extra/test/clang-tidy/checkers/objc-NSDateFormatter.cpp new file mode 100644 index 0000000000000..b6129aaf50919 --- /dev/null +++ b/clang-tools-extra/test/clang-tidy/checkers/objc-NSDateFormatter.cpp @@ -0,0 +1,14 @@ +// RUN: %check_clang_tidy %s objc-NSDateFormatter %t + +// FIXME: Add something that triggers the check here. +void f(); +// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'f' is insufficiently awesome [objc-NSDateFormatter] + +// FIXME: Verify the applied fix. +// * Make the CHECK patterns specific enough and try to make verified lines +// unique to avoid incorrect matches. +// * Use {{}} for regular expressions. +// CHECK-FIXES: {{^}}void awesome_f();{{$}} + +// FIXME: Add something that doesn't trigger the check here. +void awesome_f2(); _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits