[linters] Do not report mutable local variable in weakSelf and strongSelf

Reviewed By: mbouaziz

Differential Revision: D7988399

fbshipit-source-id: aab2d10
master
Dulma Churchill 7 years ago committed by Facebook Github Bot
parent 8615091615
commit 27a7f2e798

@ -132,11 +132,19 @@ let mutable_local_vars_advice context an =
false
in
let is_const = qual_type.qt_is_const || is_const_ref in
let name_is decl name =
match decl with
| Clang_ast_t.VarDecl (_, named_decl_info, _, _) ->
String.equal name named_decl_info.Clang_ast_t.ni_name
| _ ->
false
in
let should_not_report_mutable_local =
CAst_utils.is_syntactically_global_var decl || CAst_utils.is_static_local_var decl
|| is_const || is_of_whitelisted_type qual_type || decl_info.di_is_implicit
|| context.CLintersContext.in_for_loop_declaration
|| CAst_utils.is_std_vector qual_type || CAst_utils.has_block_attribute decl
|| name_is decl "weakSelf" || name_is decl "strongSelf"
in
if should_not_report_mutable_local then None
else

@ -126,4 +126,11 @@ class BarClass {
return nil;
}
- (void)no_mutable_local_variable_in_self_aliases {
__weak auto weakSelf = self; // no error
__strong auto strongSelf = self; // no error
auto comp = [BarComponent new]; // error
}
@end

@ -16,6 +16,7 @@ codetoanalyze/objcpp/linters/componentkit/MutableLocalVariablesTest.mm, BarCompo
codetoanalyze/objcpp/linters/componentkit/MutableLocalVariablesTest.mm, BarComponent_new, 92, MUTABLE_LOCAL_VARIABLE_IN_COMPONENT_FILE, ADVICE, []
codetoanalyze/objcpp/linters/componentkit/MutableLocalVariablesTest.mm, BarComponent_new, 111, MUTABLE_LOCAL_VARIABLE_IN_COMPONENT_FILE, ADVICE, []
codetoanalyze/objcpp/linters/componentkit/MutableLocalVariablesTest.mm, BarComponent_new, 117, MUTABLE_LOCAL_VARIABLE_IN_COMPONENT_FILE, ADVICE, []
codetoanalyze/objcpp/linters/componentkit/MutableLocalVariablesTest.mm, BarComponent_no_mutable_local_variable_in_self_aliases, 133, MUTABLE_LOCAL_VARIABLE_IN_COMPONENT_FILE, ADVICE, []
codetoanalyze/objcpp/linters/componentkit/MutableLocalVariablesTest.mm, FooComponent_newWithString, 52, MUTABLE_LOCAL_VARIABLE_IN_COMPONENT_FILE, ADVICE, []
codetoanalyze/objcpp/linters/componentkit/MutableLocalVariablesTest.mm, FooComponent_newWithString, 57, MUTABLE_LOCAL_VARIABLE_IN_COMPONENT_FILE, ADVICE, []
codetoanalyze/objcpp/linters/componentkit/MutableLocalVariablesTest.mm, FooComponent_newWithString, 60, MUTABLE_LOCAL_VARIABLE_IN_COMPONENT_FILE, ADVICE, []

Loading…
Cancel
Save