[linters] Take instancesRespondToSelector into account to avoid FPs

Reviewed By: akotulski

Differential Revision: D5380878

fbshipit-source-id: cf6f803
master
Dulma Churchill 8 years ago committed by Facebook Github Bot
parent 3aa68e23d9
commit 144e062684

@ -100,10 +100,11 @@ let parse_ctl_files linters_def_files : CFrontend_errors.linter list =
let rec get_responds_to_selector stmt = let rec get_responds_to_selector stmt =
let open Clang_ast_t in let open Clang_ast_t in
let responToSelectorMethods = ["respondsToSelector:"; "instancesRespondToSelector:"] in
match stmt with match stmt with
| ObjCMessageExpr (_, [_; ObjCSelectorExpr (_, _, _, method_name)], _, mdi) | ObjCMessageExpr (_, [_; ObjCSelectorExpr (_, _, _, method_name)], _, mdi)
| ObjCMessageExpr (_, [ObjCSelectorExpr (_, _, _, method_name)], _, mdi) | ObjCMessageExpr (_, [ObjCSelectorExpr (_, _, _, method_name)], _, mdi)
when String.equal mdi.Clang_ast_t.omei_selector "respondsToSelector:" -> when List.mem ~equal:String.equal responToSelectorMethods mdi.Clang_ast_t.omei_selector ->
[method_name] [method_name]
| BinaryOperator (_, [stmt1;stmt2], _, bo_info) | BinaryOperator (_, [stmt1;stmt2], _, bo_info)
when PVariant.(=) bo_info.Clang_ast_t.boi_kind `LAnd -> when PVariant.(=) bo_info.Clang_ast_t.boi_kind `LAnd ->

@ -1,7 +1,8 @@
codetoanalyze/objc/ioslints/unavailable_api_allowed_cases.m, Unavailable_api_allowed_cases_m2, 123, UNAVAILABLE_API_IN_SUPPORTED_IOS_SDK, [] codetoanalyze/objc/ioslints/unavailable_api_allowed_cases.m, Unavailable_api_allowed_cases_m2, 136, UNAVAILABLE_API_IN_SUPPORTED_IOS_SDK, []
codetoanalyze/objc/ioslints/unavailable_api_allowed_cases.m, Unavailable_api_allowed_cases_m3:, 131, UNAVAILABLE_API_IN_SUPPORTED_IOS_SDK, [] codetoanalyze/objc/ioslints/unavailable_api_allowed_cases.m, Unavailable_api_allowed_cases_m3:, 144, UNAVAILABLE_API_IN_SUPPORTED_IOS_SDK, []
codetoanalyze/objc/ioslints/unavailable_api_allowed_cases.m, Unavailable_api_allowed_cases_uifont_without_respondstoselector:, 105, UNAVAILABLE_API_IN_SUPPORTED_IOS_SDK, [] codetoanalyze/objc/ioslints/unavailable_api_allowed_cases.m, Unavailable_api_allowed_cases_uifont_without_respondstoselector:, 118, UNAVAILABLE_API_IN_SUPPORTED_IOS_SDK, []
codetoanalyze/objc/ioslints/unavailable_api_allowed_cases.m, Unavailable_api_allowed_cases_with_responds_to_selector_in_else:, 71, UNAVAILABLE_API_IN_SUPPORTED_IOS_SDK, [] codetoanalyze/objc/ioslints/unavailable_api_allowed_cases.m, Unavailable_api_allowed_cases_with_responds_to_selector_in_else:, 71, UNAVAILABLE_API_IN_SUPPORTED_IOS_SDK, []
codetoanalyze/objc/ioslints/unavailable_api_allowed_cases.m, Unavailable_api_allowed_cases_without_instances_responds_to_selector, 95, UNAVAILABLE_API_IN_SUPPORTED_IOS_SDK, []
codetoanalyze/objc/ioslints/unavailable_api_allowed_cases.m, Unavailable_api_allowed_cases_without_responds_to_selector:, 64, UNAVAILABLE_API_IN_SUPPORTED_IOS_SDK, [] codetoanalyze/objc/ioslints/unavailable_api_allowed_cases.m, Unavailable_api_allowed_cases_without_responds_to_selector:, 64, UNAVAILABLE_API_IN_SUPPORTED_IOS_SDK, []
codetoanalyze/objc/ioslints/unavailable_api_in_supported_ios_sdk.m, OpenURLOptionsFromSourceApplication, 26, UNAVAILABLE_API_IN_SUPPORTED_IOS_SDK, [] codetoanalyze/objc/ioslints/unavailable_api_in_supported_ios_sdk.m, OpenURLOptionsFromSourceApplication, 26, UNAVAILABLE_API_IN_SUPPORTED_IOS_SDK, []
codetoanalyze/objc/ioslints/unavailable_api_in_supported_ios_sdk.m, Unavailable_api_in_supported_ios_sdk_test:and:, 19, UNAVAILABLE_API_IN_SUPPORTED_IOS_SDK, [] codetoanalyze/objc/ioslints/unavailable_api_in_supported_ios_sdk.m, Unavailable_api_in_supported_ios_sdk_test:and:, 19, UNAVAILABLE_API_IN_SUPPORTED_IOS_SDK, []

@ -82,6 +82,19 @@
} }
} }
// no bug
- (void)with_instances_responds_to_selector {
if ([[UICollectionView class]
instancesRespondToSelector:@selector(setPrefetchingEnabled:)]) {
[[UICollectionView appearance] setPrefetchingEnabled:NO];
}
}
// bug
- (void)without_instances_responds_to_selector {
[[UICollectionView appearance] setPrefetchingEnabled:NO];
}
// no bug // no bug
- (void)with_responds_to_selector_two_selectors: - (void)with_responds_to_selector_two_selectors:
(Unavailable_api_allowed_cases*)a { (Unavailable_api_allowed_cases*)a {

Loading…
Cancel
Save