Extended check on n-th parameter to cpp method calls

Reviewed By: jvillard

Differential Revision: D15940525

fbshipit-source-id: 1b4b5d9ed
master
Dino Distefano 6 years ago committed by Facebook Github Bot
parent b14580d88b
commit 571ae7774a

@ -842,6 +842,13 @@ let transition_via_specified_parameter ~pos an key =
in
let apply_decl arg = Decl arg in
let apply_stmt arg = Stmt arg in
let compute_nodes parameters =
let parameter_of_corresp_key =
if pos then parameter_of_corresp_pos else invalid_param_name_use ()
in
let arg_stmt_opt = parameter_of_corresp_key parameters key in
node_opt_to_ast_node_list apply_stmt arg_stmt_opt
in
match an with
| Stmt (ObjCMessageExpr (_, stmt_list, _, omei)) ->
let method_name = omei.omei_selector in
@ -851,11 +858,9 @@ let transition_via_specified_parameter ~pos an key =
let arg_stmt_opt = parameter_of_corresp_key stmt_list key in
node_opt_to_ast_node_list apply_stmt arg_stmt_opt
| Stmt (CallExpr (_, _ :: args, _)) ->
let parameter_of_corresp_key =
if pos then parameter_of_corresp_pos else invalid_param_name_use ()
in
let arg_stmt_opt = parameter_of_corresp_key args key in
node_opt_to_ast_node_list apply_stmt arg_stmt_opt
compute_nodes args
| Stmt (CXXMemberCallExpr (_, stmt_list, _)) ->
compute_nodes stmt_list
| Decl (ObjCMethodDecl (_, named_decl_info, omdi)) ->
let method_name = named_decl_info.ni_name in
let parameter_of_corresp_key =

@ -0,0 +1,19 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <Foundation/Foundation.h>
#include "One.h"
@interface BadRegexInPointNameForPerfLogging : NSObject
void testRegexSafe();
@end
@implementation BadRegexInPointNameForPerfLogging
void testRegexSafe() {
std::shared_ptr<One> one = std::make_shared<One>();
one->test(1, "Sample");
}
@end

@ -0,0 +1,13 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include "One.h"
#include <string>
void One::test(int markerId, const std::string& name) {
// do nothing
}
int main() { return 0; }

@ -0,0 +1,11 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include <string>
class One {
public:
void test(int markerId, const std::string& name);
};

@ -1,3 +1,4 @@
codetoanalyze/objcpp/linters-for-test-only/BadRegexInPointNameForPerfLogging.mm, testRegexSafe, 17, TEST_PROPERTY_ON_NTH_PARAMETER, no_bucket, WARNING, []
codetoanalyze/objcpp/linters-for-test-only/ReferenceTest.mm, ReferenceTest::newWithAction, 25, TEST_REFERENCE, no_bucket, WARNING, []
codetoanalyze/objcpp/linters-for-test-only/ReferenceTest.mm, ReferenceTest::newWithAction, 42, TEST_REFERENCE, no_bucket, WARNING, []
codetoanalyze/objcpp/linters-for-test-only/ReferenceTest.mm, ReferenceTest::newWithActionRef, 22, TEST_REFERENCE, no_bucket, WARNING, []

@ -233,3 +233,18 @@ DEFINE-CHECKER ONLY_ONE_CLASS_METHOD = {
SET mode = "ON";
};
DEFINE-CHECKER TEST_PROPERTY_ON_NTH_PARAMETER = {
LET check_prop =
WHEN
HOLDS-NEXT WITH-TRANSITION ParameterPos "2"
(has_value("Sample") HOLDS-EVENTUALLY)
HOLDS-IN-NODE CXXMemberCallExpr;
SET report_when =
call_cxx_method("test") AND check_prop;
SET message = "The second parameter is the string Sample";
};

Loading…
Cancel
Save