[linters] Do not report MUTABLE_LOCAL_VARIABLE_IN_COMPONENT_FILE for variables of type std:vector

Reviewed By: mbouaziz

Differential Revision: D5964464

fbshipit-source-id: 71f2391
master
Dulma Churchill 7 years ago committed by Facebook Github Bot
parent e5007cf2e0
commit bb3201a8e8

@ -127,6 +127,7 @@ let mutable_local_vars_advice context an =
&& not (CAst_utils.is_static_local_var decl) && not is_const
&& not (is_of_whitelisted_type qual_type) && not decl_info.di_is_implicit
&& not context.CLintersContext.in_for_loop_declaration
&& not (CAst_utils.is_std_vector qual_type)
in
if condition then
Some

@ -486,3 +486,15 @@ let get_cxx_virtual_base_classes decl =
-> cxx_record_info.xrdi_transitive_vbases
| _
-> []
let is_std_vector qt =
match get_decl_from_typ_ptr qt.Clang_ast_t.qt_type_ptr with
| Some decl -> (
match Clang_ast_proj.get_named_decl_tuple decl with
| Some (_, qual_name)
-> String.equal qual_name.ni_name "vector"
&& List.mem ~equal:String.equal qual_name.ni_qual_name "std"
| None
-> false )
| None
-> false

@ -149,3 +149,5 @@ val get_record_fields : Clang_ast_t.decl -> Clang_ast_t.decl list
val get_cxx_base_classes : Clang_ast_t.decl -> Clang_ast_t.type_ptr list
val get_cxx_virtual_base_classes : Clang_ast_t.decl -> Clang_ast_t.type_ptr list
val is_std_vector : Clang_ast_t.qual_type -> bool

@ -1 +1 @@
TestIgnoreImports.mm, SomeClass_new, 18, MUTABLE_LOCAL_VARIABLE_IN_COMPONENT_FILE, []
TestIgnoreImports.mm, SomeClass_new, 22, MUTABLE_LOCAL_VARIABLE_IN_COMPONENT_FILE, []

@ -11,14 +11,20 @@
#include "../../../codetoanalyze/objcpp/linters/componentkit/FakeComponentKitHeader.h"
#include <vector>
struct D {};
@interface SomeClass : CKCompositeComponent
@end
@implementation SomeClass
+ (instancetype) new {
int i; // error
for (int i = 0; i < 10; i++) {
for (int i = 0; i < 10; i++) { // no error
}
std::vector<D*> v; // no error
return nil;
}
@end

Loading…
Cancel
Save