From fca8322c1fe1d666dc9040954d9c02e4773c879c Mon Sep 17 00:00:00 2001 From: Dulma Churchill Date: Wed, 15 Mar 2017 04:50:54 -0700 Subject: [PATCH] [linters] Save the linters definition file in the report.json Reviewed By: martinoluca Differential Revision: D4698622 fbshipit-source-id: dca4704 --- infer/src/IR/Errlog.ml | 20 +++++++++++--------- infer/src/IR/Errlog.mli | 4 +++- infer/src/backend/InferPrint.re | 14 ++++++++------ infer/src/backend/jsonbug.atd | 1 + infer/src/backend/printer.ml | 2 +- infer/src/backend/reporting.ml | 8 +++++--- infer/src/backend/reporting.mli | 1 + infer/src/backend/state.ml | 1 + infer/src/backend/state.mli | 1 + infer/src/clang/cFrontend_errors.ml | 12 ++++++------ infer/src/unit/DifferentialTestsUtils.ml | 4 +++- 11 files changed, 41 insertions(+), 27 deletions(-) diff --git a/infer/src/IR/Errlog.ml b/infer/src/IR/Errlog.ml index 91a91c3a5..ce7b4f9c2 100644 --- a/infer/src/IR/Errlog.ml +++ b/infer/src/IR/Errlog.ml @@ -30,11 +30,11 @@ type loc_trace = loc_trace_elem list (** Data associated to a specific error *) type err_data = (int * int) * int * Location.t * L.ml_loc option * loc_trace * - Exceptions.err_class * Exceptions.visibility + Exceptions.err_class * Exceptions.visibility * string option (* linters def file *) let compare_err_data - (_, _, loc1, _, _, _, _) - (_, _, loc2, _, _, _, _) = + (_, _, loc1, _, _, _, _, _) + (_, _, loc2, _, _, _, _, _) = Location.compare loc1 loc2 module ErrDataSet = (* set err_data with no repeated loc *) @@ -89,16 +89,17 @@ type iter_fun = loc_trace -> Exceptions.err_class -> Exceptions.visibility -> + string option -> unit (** Apply f to nodes and error names *) let iter (f: iter_fun) (err_log: t) = ErrLogHash.iter (fun (ekind, in_footprint, err_name, desc, severity) set -> ErrDataSet.iter - (fun (node_id_key, _, loc, ml_loc_opt, ltr, eclass, visibility) -> + (fun (node_id_key, _, loc, ml_loc_opt, ltr, eclass, visibility, linters_def_opt) -> f node_id_key loc ml_loc_opt ekind in_footprint err_name - desc severity ltr eclass visibility) + desc severity ltr eclass visibility linters_def_opt) set) err_log @@ -127,7 +128,7 @@ let pp_warnings fmt (errlog : t) = let pp_html source path_to_root fmt (errlog: t) = let pp_eds fmt eds = let pp_nodeid_session_loc - fmt ((nodeid, _), session, loc, _, _, _, _) = + fmt ((nodeid, _), session, loc, _, _, _, _, _) = Io_infer.Html.pp_session_link source path_to_root fmt (nodeid, session, loc.Location.line) in ErrDataSet.iter (pp_nodeid_session_loc fmt) eds in let f do_fp ek (ekind, infp, err_name, desc, _) eds = @@ -182,7 +183,7 @@ let update errlog_old errlog_new = (fun (ekind, infp, s, desc, severity) l -> ignore (add_issue errlog_old (ekind, infp, s, desc, severity) l)) errlog_new -let log_issue _ekind err_log loc node_id_key session ltr exn = +let log_issue _ekind err_log loc node_id_key session ltr ?linters_def_file exn = let err_name, desc, ml_loc_opt, visibility, severity, force_kind, eclass = Exceptions.recognize_exception exn in let ekind = match force_kind with @@ -206,7 +207,8 @@ let log_issue _ekind err_log loc node_id_key session ltr exn = add_issue err_log (ekind, !Config.footprint, err_name, desc, severity_to_str severity) (ErrDataSet.singleton - (node_id_key, session, loc, ml_loc_opt, ltr, eclass, visibility)) in + (node_id_key, session, loc, ml_loc_opt, ltr, eclass, visibility, + linters_def_file)) in let should_print_now = match exn with | Exceptions.Internal_error _ -> true @@ -286,7 +288,7 @@ module Err_table = struct ErrDataSet.iter (fun loc -> add_err loc err_name) eds in ErrLogHash.iter f err_table; - let pp ekind (nodeidkey, _, loc, ml_loc_opt, _, _, _) fmt err_names = + let pp ekind (nodeidkey, _, loc, ml_loc_opt, _, _, _, _) fmt err_names = List.iter ~f:(fun (err_name, desc) -> Exceptions.pp_err nodeidkey loc ekind err_name desc ml_loc_opt fmt ()) err_names in F.fprintf fmt "@.Detailed errors during footprint phase:@."; diff --git a/infer/src/IR/Errlog.mli b/infer/src/IR/Errlog.mli index 570daaafc..af6db8d7e 100644 --- a/infer/src/IR/Errlog.mli +++ b/infer/src/IR/Errlog.mli @@ -42,6 +42,7 @@ type iter_fun = loc_trace -> Exceptions.err_class -> Exceptions.visibility -> + string option -> unit (** Apply f to nodes and error names *) @@ -63,7 +64,8 @@ val size : (Exceptions.err_kind -> bool -> bool) -> t -> int val update : t -> t -> unit val log_issue : - Exceptions.err_kind -> t -> Location.t -> (int * int) -> int -> loc_trace -> exn -> unit + Exceptions.err_kind -> t -> Location.t -> (int * int) -> int -> loc_trace -> + ?linters_def_file:string -> exn -> unit (** {2 Functions for manipulating per-file error tables} *) diff --git a/infer/src/backend/InferPrint.re b/infer/src/backend/InferPrint.re index 26332022b..30a79c74d 100644 --- a/infer/src/backend/InferPrint.re +++ b/infer/src/backend/InferPrint.re @@ -388,7 +388,7 @@ let module IssuesCsv = { /** Write bug report in csv format */ let pp_issues_of_error_log fmt error_filter _ proc_loc_opt procname err_log => { let pp x => F.fprintf fmt x; - let pp_row (_, node_key) loc _ ekind in_footprint error_name error_desc severity ltr eclass _ => { + let pp_row (_, node_key) loc _ ekind in_footprint error_name error_desc severity ltr eclass _ _ => { let source_file = switch proc_loc_opt { | Some proc_loc => proc_loc.Location.file @@ -461,7 +461,8 @@ let module IssuesJson = { severity ltr eclass - visibility => { + visibility + linters_def_file => { let (source_file, procedure_start_line) = switch proc_loc_opt { | Some proc_loc => (proc_loc.Location.file, proc_loc.Location.line) @@ -506,7 +507,8 @@ let module IssuesJson = { hash: get_bug_hash kind bug_type procedure_id file node_key error_desc, dotty: error_desc_to_dotty_string error_desc, infer_source_loc: json_ml_loc, - bug_type_hum: Localise.to_human_readable_string error_name + bug_type_hum: Localise.to_human_readable_string error_name, + linters_def_file }; if (not !is_first_item) { pp "," @@ -577,7 +579,7 @@ let module IssuesTxt = { /** Write bug report in text format */ let pp_issues_of_error_log fmt error_filter _ proc_loc_opt _ err_log => { - let pp_row (node_id, node_key) loc _ ekind in_footprint error_name error_desc _ _ _ _ => { + let pp_row (node_id, node_key) loc _ ekind in_footprint error_name error_desc _ _ _ _ _ => { let source_file = switch proc_loc_opt { | Some proc_loc => proc_loc.Location.file @@ -646,7 +648,7 @@ let module IssuesXml = { /** print issues from summary in xml */ let pp_issues_of_error_log fmt error_filter linereader proc_loc_opt proc_name err_log => { - let do_row (_, node_key) loc _ ekind in_footprint error_name error_desc severity ltr eclass _ => { + let do_row (_, node_key) loc _ ekind in_footprint error_name error_desc severity ltr eclass _ _ => { let source_file = switch proc_loc_opt { | Some proc_loc => proc_loc.Location.file @@ -787,7 +789,7 @@ let module Stats = { }; let process_err_log error_filter linereader err_log stats => { let found_errors = ref false; - let process_row _ loc _ ekind in_footprint error_name error_desc _ ltr _ _ => { + let process_row _ loc _ ekind in_footprint error_name error_desc _ ltr _ _ _ => { let type_str = Localise.to_issue_id error_name; if (in_footprint && error_filter error_desc error_name) { switch ekind { diff --git a/infer/src/backend/jsonbug.atd b/infer/src/backend/jsonbug.atd index d7de136c8..ba6fbfb41 100644 --- a/infer/src/backend/jsonbug.atd +++ b/infer/src/backend/jsonbug.atd @@ -38,6 +38,7 @@ type jsonbug = { ?dotty : string option; ?infer_source_loc: loc option; bug_type_hum: string; + ?linters_def_file: string option; } type report = jsonbug list diff --git a/infer/src/backend/printer.ml b/infer/src/backend/printer.ml index 5b95e0b9b..d04fccc4d 100644 --- a/infer/src/backend/printer.ml +++ b/infer/src/backend/printer.ml @@ -453,7 +453,7 @@ let write_proc_html source whole_seconds pdesc = (** Creare a hash table mapping line numbers to the set of errors occurring on that line *) let create_table_err_per_line err_log = let err_per_line = Hashtbl.create 17 in - let add_err _ loc _ _ _ err_name desc _ _ _ _ = + let add_err _ loc _ _ _ err_name desc _ _ _ _ _ = let err_str = Localise.to_issue_id err_name ^ " " ^ diff --git a/infer/src/backend/reporting.ml b/infer/src/backend/reporting.ml index 4be5772b4..4524a30ac 100644 --- a/infer/src/backend/reporting.ml +++ b/infer/src/backend/reporting.ml @@ -16,6 +16,7 @@ type log_t = ?node_id: (int * int) -> ?session: int -> ?ltr: Errlog.loc_trace -> + ?linters_def_file:string -> exn -> unit @@ -23,7 +24,7 @@ type log_issue = Typ.Procname.t -> log_t type log_issue_from_errlog = Errlog.t -> log_t -let log_issue_from_errlog err_kind err_log ?loc ?node_id ?session ?ltr exn = +let log_issue_from_errlog err_kind err_log ?loc ?node_id ?session ?ltr ?linters_def_file exn = let loc = match loc with | None -> State.get_loc () | Some loc -> loc in @@ -41,7 +42,7 @@ let log_issue_from_errlog err_kind err_log ?loc ?node_id ?session ?ltr exn = | _ -> let err_name, _, _, _, _, _, _ = Exceptions.recognize_exception exn in (Localise.to_issue_id err_name) in if (Inferconfig.is_checker_enabled err_name) then - Errlog.log_issue err_kind err_log loc node_id session ltr exn + Errlog.log_issue err_kind err_log loc node_id session ltr ?linters_def_file exn let log_issue @@ -51,6 +52,7 @@ let log_issue ?node_id ?session ?ltr + ?linters_def_file exn = let should_suppress_lint (summary : Specs.summary) = Config.curr_language_is Config.Java && @@ -59,7 +61,7 @@ let log_issue | Some summary when should_suppress_lint summary -> () | Some summary -> let err_log = summary.Specs.attributes.ProcAttributes.err_log in - log_issue_from_errlog err_kind err_log ?loc ?node_id ?session ?ltr exn + log_issue_from_errlog err_kind err_log ?loc ?node_id ?session ?ltr ?linters_def_file exn | None -> failwithf "Trying to report error on procedure %a, but cannot because no summary exists for this \ diff --git a/infer/src/backend/reporting.mli b/infer/src/backend/reporting.mli index f28a190ed..33852e1ec 100644 --- a/infer/src/backend/reporting.mli +++ b/infer/src/backend/reporting.mli @@ -16,6 +16,7 @@ type log_t = ?node_id: (int * int) -> ?session: int -> ?ltr: Errlog.loc_trace -> + ?linters_def_file:string -> exn -> unit diff --git a/infer/src/backend/state.ml b/infer/src/backend/state.ml index 29d731ce0..1ebab033d 100644 --- a/infer/src/backend/state.ml +++ b/infer/src/backend/state.ml @@ -312,6 +312,7 @@ type log_issue = ?node_id: (int * int) -> ?session: int -> ?ltr: Errlog.loc_trace -> + ?linters_def_file:string -> exn -> unit diff --git a/infer/src/backend/state.mli b/infer/src/backend/state.mli index e7710ab71..9e0e2f00e 100644 --- a/infer/src/backend/state.mli +++ b/infer/src/backend/state.mli @@ -90,6 +90,7 @@ type log_issue = ?node_id: (int * int) -> ?session: int -> ?ltr: Errlog.loc_trace -> + ?linters_def_file:string -> exn -> unit diff --git a/infer/src/clang/cFrontend_errors.ml b/infer/src/clang/cFrontend_errors.ml index aabd44828..9b3710415 100644 --- a/infer/src/clang/cFrontend_errors.ml +++ b/infer/src/clang/cFrontend_errors.ml @@ -190,7 +190,7 @@ let get_err_log translation_unit_context method_decl_opt = LintIssues.get_err_log procname (* Add a frontend warning with a description desc at location loc to the errlog of a proc desc *) -let log_frontend_issue translation_unit_context method_decl_opt key issue_desc = +let log_frontend_issue translation_unit_context method_decl_opt key issue_desc linters_def_file = let name = issue_desc.CIssue.name in let loc = issue_desc.CIssue.loc in let errlog = get_err_log translation_unit_context method_decl_opt in @@ -202,7 +202,7 @@ let log_frontend_issue translation_unit_context method_decl_opt key issue_desc = let method_name = CAst_utils.full_name_of_decl_opt method_decl_opt in let key = Hashtbl.hash (key ^ method_name) in Reporting.log_issue_from_errlog err_kind errlog exn ~loc ~ltr:trace - ~node_id:(0, key) + ~node_id:(0, key) ?linters_def_file let get_current_method context (an : Ctl_parser_types.ast_node) = match an with @@ -215,13 +215,13 @@ let get_current_method context (an : Ctl_parser_types.ast_node) = | Decl (BlockDecl _ as d) -> Some d | _ -> context.CLintersContext.current_method -let fill_issue_desc_info_and_log context an key issue_desc loc = +let fill_issue_desc_info_and_log context an key issue_desc linters_def_file loc = let desc = remove_new_lines (expand_message_string issue_desc.CIssue.description an) in let issue_desc' = {issue_desc with CIssue.description = desc; CIssue.loc = loc } in log_frontend_issue context.CLintersContext.translation_unit_context - (get_current_method context an) key issue_desc' + (get_current_method context an) key issue_desc' linters_def_file (* Calls the set of hard coded checkers (if any) *) let invoke_set_of_hard_coded_checkers_an context (an : Ctl_parser_types.ast_node) = @@ -234,7 +234,7 @@ let invoke_set_of_hard_coded_checkers_an context (an : Ctl_parser_types.ast_node List.iter ~f:(fun issue_desc -> if CIssue.should_run_check issue_desc.CIssue.mode then let loc = issue_desc.CIssue.loc in - fill_issue_desc_info_and_log context an key issue_desc loc + fill_issue_desc_info_and_log context an key issue_desc None loc ) issue_desc_list ) checkers @@ -247,7 +247,7 @@ let invoke_set_of_parsed_checkers_an parsed_linters context (an : Ctl_parser_typ if CIssue.should_run_check linter.issue_desc.CIssue.mode && CTL.eval_formula linter.condition an context then let loc = CFrontend_checkers.location_from_an context an in - fill_issue_desc_info_and_log context an key linter.issue_desc loc + fill_issue_desc_info_and_log context an key linter.issue_desc linter.def_file loc ) parsed_linters (* We decouple the hardcoded checkers from the parsed ones *) diff --git a/infer/src/unit/DifferentialTestsUtils.ml b/infer/src/unit/DifferentialTestsUtils.ml index ff156eade..b28785106 100644 --- a/infer/src/unit/DifferentialTestsUtils.ml +++ b/infer/src/unit/DifferentialTestsUtils.ml @@ -27,7 +27,8 @@ let create_fake_jsonbug ?(qualifier_tags=[]) ?(hash=1) ?(dotty=None) - ?(infer_source_loc=None) () : Jsonbug_t.jsonbug = + ?(infer_source_loc=None) + ?(linters_def_file=Some "file/at/certain/path.al") () : Jsonbug_t.jsonbug = { bug_class; kind; @@ -48,6 +49,7 @@ let create_fake_jsonbug dotty; infer_source_loc; bug_type_hum = kind; + linters_def_file } let pp_diff_of_int_list group_name fmt (expected, actual) =