Introducing a mechanism of white/black listing of checks/error reporting based on .inferconfig

Reviewed By: jberdine

Differential Revision: D3212334

fb-gh-sync-id: 9eaccea
fbshipit-source-id: 9eaccea
master
Dino Distefano 9 years ago committed by Facebook Github Bot 9
parent 7671fe755f
commit a15095c854

@ -333,6 +333,7 @@ module ModeledExpensiveMatcher = OverridesMatcher(struct
let json_key = "modeled_expensive" let json_key = "modeled_expensive"
end) end)
let disabled_checks_by_default = []
let inferconfig () = let inferconfig () =
match !Config.inferconfig_home with match !Config.inferconfig_home with
@ -390,6 +391,29 @@ let create_filters analyzer =
| None -> do_not_filter | None -> do_not_filter
| Some inferconfig -> filters_from_inferconfig inferconfig | Some inferconfig -> filters_from_inferconfig inferconfig
(* Decide whether a checker or error type is enabled or disabled based on*)
(* white/black listing in .inferconfig and the default value *)
let is_checker_enabled checker_name =
let black_listed_checks = lazy (
try
lookup_string_list "disable_checks"
(Yojson.Basic.from_file (inferconfig ()))
with _ -> []) in
let white_listed_checks = lazy (
try
lookup_string_list "enable_checks"
(Yojson.Basic.from_file (inferconfig ()))
with _ -> []) in
match IList.mem (=) checker_name (Lazy.force black_listed_checks), IList.mem (=) checker_name (Lazy.force white_listed_checks) with
| false, false -> (* if it's not amond white/black listed then we use default value *)
not (IList.mem (=) checker_name disabled_checks_by_default)
| true, false -> (* if it's blacklisted and not whitelisted then it should be disabled *)
false
| false, true -> (* if it is not blacklisted and it is whitelisted then it should be enabled *)
true
| true, true -> (* if it's both blacklisted and whitelisted then we flag error *)
failwith ("Inconsistent setting in .inferconfig: checker" ^ checker_name ^ " is both blacklisted and whitelisted.")
(* This function loads and list the path that are being filtered by the analyzer. The results *) (* This function loads and list the path that are being filtered by the analyzer. The results *)
(* are of the form: path/to/file.java -> {infer, eradicate} meaning that analysis results will *) (* are of the form: path/to/file.java -> {infer, eradicate} meaning that analysis results will *)
(* be reported on path/to/file.java both for infer and for eradicate *) (* be reported on path/to/file.java both for infer and for eradicate *)

@ -54,3 +54,6 @@ end
val test: unit -> unit val test: unit -> unit
val skip_translation_headers : string list Lazy.t val skip_translation_headers : string list Lazy.t
(* is_checker_enabled error_name is true if error_name is whitelisted in .inferconfig or if it's enabled by default *)
val is_checker_enabled : string -> bool

@ -45,7 +45,13 @@ let log_issue_from_errlog
let ltr = match ltr with let ltr = match ltr with
| None -> State.get_loc_trace () | None -> State.get_loc_trace ()
| Some ltr -> ltr in | Some ltr -> ltr in
Errlog.log_issue err_kind err_log loc node_id session ltr pre exn let err_name = match exn with
| Exceptions.Frontend_warning (err_name, _, _) -> err_name
| _ -> let err_name, _, _, _, _, _, _ = Exceptions.recognize_exception exn in
(Localise.to_string err_name) in
if (Inferconfig.is_checker_enabled err_name) then
Errlog.log_issue err_kind err_log loc node_id session ltr pre exn
let log_issue let log_issue
err_kind err_kind

Loading…
Cancel
Save