[linters] Add an example of checking for an empty map in the argument of a method call

Reviewed By: ikenwoo

Differential Revision: D5678779

fbshipit-source-id: 90ecb0d
master
Dulma Churchill 8 years ago committed by Facebook Github Bot
parent b15e4846c3
commit 0b5c992a93

@ -25,7 +25,7 @@ struct SomeStruct {
SomeButton* buttonComponent(void);
SomeButton* buttonComponent(void) {
// flagging passing empty struct
// flagging passing empty struct and map
return [SomeButton newWithStruct:{} map:{} object:nil number:0];
};

@ -7,5 +7,6 @@ codetoanalyze/objcpp/linters-for-test-only/ReferenceTest.mm, ReferenceTest_newWi
codetoanalyze/objcpp/linters-for-test-only/TestParamterLabelsChecks.mm, anotherButtonComponent, 34, TEST_PARAMETER_LABEL, []
codetoanalyze/objcpp/linters-for-test-only/TestParamterLabelsChecks.mm, anotherButtonComponent, 34, TEST_PARAMETER_LABEL_REGEXP, []
codetoanalyze/objcpp/linters-for-test-only/TestParamterLabelsChecks.mm, buttonComponent, 29, TEST_PARAMETER_LABEL, []
codetoanalyze/objcpp/linters-for-test-only/TestParamterLabelsChecks.mm, buttonComponent, 29, TEST_PARAMETER_LABEL_EMPTY_MAP, []
codetoanalyze/objcpp/linters-for-test-only/TestParamterLabelsChecks.mm, buttonComponent, 29, TEST_PARAMETER_LABEL_EMPTY_STRUCT, []
codetoanalyze/objcpp/linters-for-test-only/TestParamterLabelsChecks.mm, buttonComponent, 29, TEST_PARAMETER_LABEL_REGEXP, []

@ -55,3 +55,27 @@ DEFINE-CHECKER TEST_PARAMETER_LABEL_EMPTY_STRUCT = {
HOLDS-IN-NODE ObjCMessageExpr;
SET message = "Do not pass empty struct to the parameter `newWithStruct` of method `new...`";
};
DEFINE-CHECKER TEST_PARAMETER_LABEL_EMPTY_MAP = {
//This means the node has no children.
LET constructor_with_no_parameters =
WHEN (FALSE HOLDS-EVERYWHERE-NEXT) HOLDS-IN-NODE CXXConstructExpr;
LET temp_expr =
WHEN (constructor_with_no_parameters HOLDS-EVERYWHERE-NEXT) HOLDS-IN-NODE CXXBindTemporaryExpr;
LET is_empty_map =
WHEN (temp_expr HOLDS-EVERYWHERE-NEXT) HOLDS-IN-NODE MaterializeTemporaryExpr;
LET method_has_parameter_type =
WHEN
HOLDS-NEXT WITH-TRANSITION ParameterName "map"
(is_empty_map)
HOLDS-IN-NODE ObjCMessageExpr;
SET report_when =
WHEN
method_has_parameter_type
AND call_method(REGEXP("^new.*:$"))
HOLDS-IN-NODE ObjCMessageExpr;
SET message = "Do not pass empty map to the parameter `map` of method `new...`";
};

Loading…
Cancel
Save