[linters] Do not report mutable local variable in components advice on static locals

Reviewed By: jberdine

Differential Revision: D5397446

fbshipit-source-id: eeeb9b4
master
Dulma Churchill 7 years ago committed by Facebook Github Bot
parent 34d6a43cdb
commit 4a6652faef

@ -124,7 +124,8 @@ let mutable_local_vars_advice context an =
let is_const = qual_type.qt_is_const || is_const_ref in let is_const = qual_type.qt_is_const || is_const_ref in
let condition = let condition =
is_ck_context context an && not (CAst_utils.is_syntactically_global_var decl) is_ck_context context an && not (CAst_utils.is_syntactically_global_var decl)
&& not is_const && not (is_of_whitelisted_type qual_type) && not decl_info.di_is_implicit && not (CAst_utils.is_static_local_var decl) && not is_const
&& not (is_of_whitelisted_type qual_type) && not decl_info.di_is_implicit
in in
if condition then if condition then
Some Some

@ -235,6 +235,9 @@ let is_syntactically_global_var decl =
| _ | _
-> false -> false
let is_static_local_var decl =
match decl with Clang_ast_t.VarDecl (_, _, _, vdi) -> vdi.vdi_is_static_local | _ -> false
let is_const_expr_var decl = let is_const_expr_var decl =
match decl with Clang_ast_t.VarDecl (_, _, _, vdi) -> vdi.vdi_is_const_expr | _ -> false match decl with Clang_ast_t.VarDecl (_, _, _, vdi) -> vdi.vdi_is_const_expr | _ -> false

@ -89,6 +89,9 @@ val exists_eventually_st : ('a -> Clang_ast_t.stmt -> bool) -> 'a -> Clang_ast_t
val is_syntactically_global_var : Clang_ast_t.decl -> bool val is_syntactically_global_var : Clang_ast_t.decl -> bool
(** true if a declaration is a global variable *) (** true if a declaration is a global variable *)
val is_static_local_var : Clang_ast_t.decl -> bool
(** true if a declaration is a static local variable *)
val is_const_expr_var : Clang_ast_t.decl -> bool val is_const_expr_var : Clang_ast_t.decl -> bool
(** true if a declaration is a constexpr variable *) (** true if a declaration is a constexpr variable *)

@ -56,6 +56,7 @@
// Objc types // Objc types
NSString* a = @"lol"; // error NSString* a = @"lol"; // error
NSString* const b = @"lol"; // no error NSString* const b = @"lol"; // no error
static NSString* st = @"lol"; // no error
const NSString* c = @"lol"; // error const NSString* c = @"lol"; // error
const NSString* const d = @"lol"; // no error const NSString* const d = @"lol"; // no error

@ -12,15 +12,15 @@ codetoanalyze/objcpp/linters/componentkit/MultipleFactoryMethodsTest.h, Linters_
codetoanalyze/objcpp/linters/componentkit/MultipleFactoryMethodsTest.h, Linters_dummy_method, 58, COMPONENT_WITH_MULTIPLE_FACTORY_METHODS, [] codetoanalyze/objcpp/linters/componentkit/MultipleFactoryMethodsTest.h, Linters_dummy_method, 58, COMPONENT_WITH_MULTIPLE_FACTORY_METHODS, []
codetoanalyze/objcpp/linters/componentkit/MultipleFactoryMethodsTest.h, Linters_dummy_method, 59, COMPONENT_WITH_MULTIPLE_FACTORY_METHODS, [] codetoanalyze/objcpp/linters/componentkit/MultipleFactoryMethodsTest.h, Linters_dummy_method, 59, COMPONENT_WITH_MULTIPLE_FACTORY_METHODS, []
codetoanalyze/objcpp/linters/componentkit/MultipleFactoryMethodsTest.h, Linters_dummy_method, 60, COMPONENT_WITH_MULTIPLE_FACTORY_METHODS, [] codetoanalyze/objcpp/linters/componentkit/MultipleFactoryMethodsTest.h, Linters_dummy_method, 60, COMPONENT_WITH_MULTIPLE_FACTORY_METHODS, []
codetoanalyze/objcpp/linters/componentkit/MutableLocalVariablesTest.mm, BarComponent_new, 89, MUTABLE_LOCAL_VARIABLE_IN_COMPONENT_FILE, [] codetoanalyze/objcpp/linters/componentkit/MutableLocalVariablesTest.mm, BarComponent_new, 90, MUTABLE_LOCAL_VARIABLE_IN_COMPONENT_FILE, []
codetoanalyze/objcpp/linters/componentkit/MutableLocalVariablesTest.mm, BarComponent_new, 91, MUTABLE_LOCAL_VARIABLE_IN_COMPONENT_FILE, [] codetoanalyze/objcpp/linters/componentkit/MutableLocalVariablesTest.mm, BarComponent_new, 92, MUTABLE_LOCAL_VARIABLE_IN_COMPONENT_FILE, []
codetoanalyze/objcpp/linters/componentkit/MutableLocalVariablesTest.mm, BarComponent_new, 110, MUTABLE_LOCAL_VARIABLE_IN_COMPONENT_FILE, [] codetoanalyze/objcpp/linters/componentkit/MutableLocalVariablesTest.mm, BarComponent_new, 111, MUTABLE_LOCAL_VARIABLE_IN_COMPONENT_FILE, []
codetoanalyze/objcpp/linters/componentkit/MutableLocalVariablesTest.mm, BarComponent_new, 116, MUTABLE_LOCAL_VARIABLE_IN_COMPONENT_FILE, [] codetoanalyze/objcpp/linters/componentkit/MutableLocalVariablesTest.mm, BarComponent_new, 117, MUTABLE_LOCAL_VARIABLE_IN_COMPONENT_FILE, []
codetoanalyze/objcpp/linters/componentkit/MutableLocalVariablesTest.mm, FooComponent_newWithString:, 52, MUTABLE_LOCAL_VARIABLE_IN_COMPONENT_FILE, [] codetoanalyze/objcpp/linters/componentkit/MutableLocalVariablesTest.mm, FooComponent_newWithString:, 52, MUTABLE_LOCAL_VARIABLE_IN_COMPONENT_FILE, []
codetoanalyze/objcpp/linters/componentkit/MutableLocalVariablesTest.mm, FooComponent_newWithString:, 57, MUTABLE_LOCAL_VARIABLE_IN_COMPONENT_FILE, [] codetoanalyze/objcpp/linters/componentkit/MutableLocalVariablesTest.mm, FooComponent_newWithString:, 57, MUTABLE_LOCAL_VARIABLE_IN_COMPONENT_FILE, []
codetoanalyze/objcpp/linters/componentkit/MutableLocalVariablesTest.mm, FooComponent_newWithString:, 59, MUTABLE_LOCAL_VARIABLE_IN_COMPONENT_FILE, [] codetoanalyze/objcpp/linters/componentkit/MutableLocalVariablesTest.mm, FooComponent_newWithString:, 60, MUTABLE_LOCAL_VARIABLE_IN_COMPONENT_FILE, []
codetoanalyze/objcpp/linters/componentkit/MutableLocalVariablesTest.mm, FooComponent_newWithString:, 63, MUTABLE_LOCAL_VARIABLE_IN_COMPONENT_FILE, [] codetoanalyze/objcpp/linters/componentkit/MutableLocalVariablesTest.mm, FooComponent_newWithString:, 64, MUTABLE_LOCAL_VARIABLE_IN_COMPONENT_FILE, []
codetoanalyze/objcpp/linters/componentkit/MutableLocalVariablesTest.mm, FooComponent_newWithString:, 68, MUTABLE_LOCAL_VARIABLE_IN_COMPONENT_FILE, [] codetoanalyze/objcpp/linters/componentkit/MutableLocalVariablesTest.mm, FooComponent_newWithString:, 69, MUTABLE_LOCAL_VARIABLE_IN_COMPONENT_FILE, []
codetoanalyze/objcpp/linters/componentkit/MutableLocalVariablesTest.mm, SomeClass_init, 40, MUTABLE_LOCAL_VARIABLE_IN_COMPONENT_FILE, [] codetoanalyze/objcpp/linters/componentkit/MutableLocalVariablesTest.mm, SomeClass_init, 40, MUTABLE_LOCAL_VARIABLE_IN_COMPONENT_FILE, []
codetoanalyze/objcpp/linters/componentkit/UnconventionalSuperclassTest.h, Linters_dummy_method, 17, COMPONENT_WITH_UNCONVENTIONAL_SUPERCLASS, [] codetoanalyze/objcpp/linters/componentkit/UnconventionalSuperclassTest.h, Linters_dummy_method, 17, COMPONENT_WITH_UNCONVENTIONAL_SUPERCLASS, []
codetoanalyze/objcpp/linters/cxx_reference_in_block/block.mm, A_foo3:param2:, 37, CXX_REFERENCE_CAPTURED_IN_OBJC_BLOCK, [] codetoanalyze/objcpp/linters/cxx_reference_in_block/block.mm, A_foo3:param2:, 37, CXX_REFERENCE_CAPTURED_IN_OBJC_BLOCK, []

Loading…
Cancel
Save