diff --git a/infer/src/backend/inferconfig.ml b/infer/src/backend/inferconfig.ml index c10411c4d..33b403ed9 100644 --- a/infer/src/backend/inferconfig.ml +++ b/infer/src/backend/inferconfig.ml @@ -333,6 +333,7 @@ module ModeledExpensiveMatcher = OverridesMatcher(struct let json_key = "modeled_expensive" end) +let disabled_checks_by_default = [] let inferconfig () = match !Config.inferconfig_home with @@ -390,6 +391,29 @@ let create_filters analyzer = | None -> do_not_filter | 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 *) (* 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 *) diff --git a/infer/src/backend/inferconfig.mli b/infer/src/backend/inferconfig.mli index 24378b1a7..f7b727758 100644 --- a/infer/src/backend/inferconfig.mli +++ b/infer/src/backend/inferconfig.mli @@ -54,3 +54,6 @@ end val test: unit -> unit 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 diff --git a/infer/src/backend/reporting.ml b/infer/src/backend/reporting.ml index 3a6c8cbdf..c93b8c101 100644 --- a/infer/src/backend/reporting.ml +++ b/infer/src/backend/reporting.ml @@ -45,7 +45,13 @@ let log_issue_from_errlog let ltr = match ltr with | None -> State.get_loc_trace () | 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 err_kind