From e77ca182a5a6562c8f8f8be5063a055ecb287755 Mon Sep 17 00:00:00 2001 From: Dino Distefano Date: Tue, 23 May 2017 05:19:12 -0700 Subject: [PATCH] Added a lint for namespace Reviewed By: dulmarod Differential Revision: D5103566 fbshipit-source-id: 4092e73 --- .../objc/linters-for-test-only/Makefile | 5 +++-- .../objc/linters-for-test-only/issues.exp | 1 + .../linters-for-test-only/linters_example.al | 13 ++++++++++++- .../objc/linters-for-test-only/namespace.mm | 16 ++++++++++++++++ 4 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 infer/tests/codetoanalyze/objc/linters-for-test-only/namespace.mm diff --git a/infer/tests/codetoanalyze/objc/linters-for-test-only/Makefile b/infer/tests/codetoanalyze/objc/linters-for-test-only/Makefile index b176c649c..d5f76c19b 100644 --- a/infer/tests/codetoanalyze/objc/linters-for-test-only/Makefile +++ b/infer/tests/codetoanalyze/objc/linters-for-test-only/Makefile @@ -8,13 +8,14 @@ TESTS_DIR = ../../.. ANALYZER = linters -CLANG_OPTIONS = -x objective-c -fobjc-arc -c -INFER_OPTIONS = --linters-def-file linters_example.al --no-filtering --debug-exceptions --project-root $(TESTS_DIR) --no-failures-allowed +CLANG_OPTIONS = -fobjc-arc -c +INFER_OPTIONS = --cxx --linters-def-file linters_example.al --no-filtering --debug-exceptions --project-root $(TESTS_DIR) --no-failures-allowed INFERPRINT_OPTIONS = --issues-tests SOURCES = \ $(wildcard *.m) \ $(wildcard */*.m) \ + $(wildcard *.mm) \ $(wildcard *.c) \ include $(TESTS_DIR)/clang.make diff --git a/infer/tests/codetoanalyze/objc/linters-for-test-only/issues.exp b/infer/tests/codetoanalyze/objc/linters-for-test-only/issues.exp index ea04607fb..63e44252e 100644 --- a/infer/tests/codetoanalyze/objc/linters-for-test-only/issues.exp +++ b/infer/tests/codetoanalyze/objc/linters-for-test-only/issues.exp @@ -1,6 +1,7 @@ codetoanalyze/objc/linters-for-test-only/implicit_cast.c, main, 10, TEST_VAR_TYPE_CHECK, [] codetoanalyze/objc/linters-for-test-only/implicit_cast.c, main, 11, TEST_IMPLICIT_CAST_CHECK, [] codetoanalyze/objc/linters-for-test-only/implicit_cast.c, main, 11, TEST_VAR_TYPE_CHECK, [] +codetoanalyze/objc/linters-for-test-only/namespace.mm, Linters_dummy_method, 9, TEST_NAMESPACE_NAME, [] codetoanalyze/objc/linters-for-test-only/subclassing.m, A_foo:, 13, TEST_BUILTIN_TYPE, [] codetoanalyze/objc/linters-for-test-only/subclassing.m, A_foo:, 13, TEST_RETURN_METHOD, [] codetoanalyze/objc/linters-for-test-only/subclassing.m, A_foo:, 19, TEST_BUILTIN_TYPE, [] diff --git a/infer/tests/codetoanalyze/objc/linters-for-test-only/linters_example.al b/infer/tests/codetoanalyze/objc/linters-for-test-only/linters_example.al index 9cee3a5d4..4fd97d603 100644 --- a/infer/tests/codetoanalyze/objc/linters-for-test-only/linters_example.al +++ b/infer/tests/codetoanalyze/objc/linters-for-test-only/linters_example.al @@ -178,8 +178,19 @@ DEFINE-CHECKER TEST_NTH_PARAM_TYPE_CHECK = { SET report_when = WHEN objc_method_has_nth_parameter_of_type("2", "REGEXP('This.+')*") - HOLDS-IN-NODE ObjCMethodDecl; + HOLDS-IN-NODE ObjCMethodDecl; SET message = "Found a method with nth parameter of type...."; }; + +DEFINE-CHECKER TEST_NAMESPACE_NAME = { + + SET report_when = + WHEN + declaration_has_name(REGEXP("FirstNam*")) + HOLDS-IN-NODE NamespaceDecl; + + SET message = "Found a namespace with name...."; + +}; diff --git a/infer/tests/codetoanalyze/objc/linters-for-test-only/namespace.mm b/infer/tests/codetoanalyze/objc/linters-for-test-only/namespace.mm new file mode 100644 index 000000000..230a18f97 --- /dev/null +++ b/infer/tests/codetoanalyze/objc/linters-for-test-only/namespace.mm @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2017 - present Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ +namespace FirstNameSpace { +namespace SecodNameSpace { +class C { + void m(); +}; +} +void SecodNameSpace::C::m() {} +}