[linters] Adding example of checking a parameter for empty struct

Reviewed By: jvillard

Differential Revision: D5678330

fbshipit-source-id: 3d1891f
master
Dulma Churchill 7 years ago committed by Facebook Github Bot
parent a34fcebc59
commit df1063b9eb

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

@ -4,7 +4,8 @@ codetoanalyze/objcpp/linters-for-test-only/ReferenceTest.mm, ReferenceTest_newWi
codetoanalyze/objcpp/linters-for-test-only/ReferenceTest.mm, ReferenceTest_newWithActionRef:, 40, TEST_REFERENCE, [] codetoanalyze/objcpp/linters-for-test-only/ReferenceTest.mm, ReferenceTest_newWithActionRef:, 40, TEST_REFERENCE, []
codetoanalyze/objcpp/linters-for-test-only/ReferenceTest.mm, ReferenceTest_newWithConstAction:, 21, TEST_REFERENCE, [] codetoanalyze/objcpp/linters-for-test-only/ReferenceTest.mm, ReferenceTest_newWithConstAction:, 21, TEST_REFERENCE, []
codetoanalyze/objcpp/linters-for-test-only/ReferenceTest.mm, ReferenceTest_newWithConstAction:, 36, TEST_REFERENCE, [] codetoanalyze/objcpp/linters-for-test-only/ReferenceTest.mm, ReferenceTest_newWithConstAction:, 36, TEST_REFERENCE, []
codetoanalyze/objcpp/linters-for-test-only/TestParamterLabelsChecks.mm, anotherButtonComponent, 33, TEST_PARAMETER_LABEL, [] codetoanalyze/objcpp/linters-for-test-only/TestParamterLabelsChecks.mm, anotherButtonComponent, 34, TEST_PARAMETER_LABEL, []
codetoanalyze/objcpp/linters-for-test-only/TestParamterLabelsChecks.mm, anotherButtonComponent, 33, TEST_PARAMETER_LABEL_REGEXP, [] codetoanalyze/objcpp/linters-for-test-only/TestParamterLabelsChecks.mm, anotherButtonComponent, 34, TEST_PARAMETER_LABEL_REGEXP, []
codetoanalyze/objcpp/linters-for-test-only/TestParamterLabelsChecks.mm, buttonComponent, 28, TEST_PARAMETER_LABEL, [] codetoanalyze/objcpp/linters-for-test-only/TestParamterLabelsChecks.mm, buttonComponent, 29, TEST_PARAMETER_LABEL, []
codetoanalyze/objcpp/linters-for-test-only/TestParamterLabelsChecks.mm, buttonComponent, 28, TEST_PARAMETER_LABEL_REGEXP, [] 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, []

@ -35,3 +35,23 @@ DEFINE-CHECKER TEST_PARAMETER_LABEL_REGEXP = {
HOLDS-IN-NODE ObjCMessageExpr; HOLDS-IN-NODE ObjCMessageExpr;
SET message = "Found method with parameter labeled with `number` and with type `int`"; SET message = "Found method with parameter labeled with `number` and with type `int`";
}; };
DEFINE-CHECKER TEST_PARAMETER_LABEL_EMPTY_STRUCT = {
LET is_empty_init_list =
WHEN ((is_node("ImplicitValueInitExpr")) HOLDS-EVERYWHERE-NEXT)
HOLDS-IN-NODE InitListExpr;
LET is_empty_struct =
WHEN ((is_empty_init_list) HOLDS-EVERYWHERE-NEXT)
HOLDS-IN-NODE CXXBindTemporaryExpr;
LET method_has_parameter_type =
WHEN
HOLDS-NEXT WITH-TRANSITION ParameterName "newWithStruct"
(is_empty_struct)
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 struct to the parameter `newWithStruct` of method `new...`";
};

Loading…
Cancel
Save