[linters] Save the linters definition file in the report.json

Reviewed By: martinoluca

Differential Revision: D4698622

fbshipit-source-id: dca4704
master
Dulma Churchill 8 years ago committed by Facebook Github Bot
parent fe51f08ae9
commit fca8322c1f

@ -30,11 +30,11 @@ type loc_trace = loc_trace_elem list
(** Data associated to a specific error *) (** Data associated to a specific error *)
type err_data = type err_data =
(int * int) * int * Location.t * L.ml_loc option * loc_trace * (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 let compare_err_data
(_, _, loc1, _, _, _, _) (_, _, loc1, _, _, _, _, _)
(_, _, loc2, _, _, _, _) = (_, _, loc2, _, _, _, _, _) =
Location.compare loc1 loc2 Location.compare loc1 loc2
module ErrDataSet = (* set err_data with no repeated loc *) module ErrDataSet = (* set err_data with no repeated loc *)
@ -89,16 +89,17 @@ type iter_fun =
loc_trace -> loc_trace ->
Exceptions.err_class -> Exceptions.err_class ->
Exceptions.visibility -> Exceptions.visibility ->
string option ->
unit unit
(** Apply f to nodes and error names *) (** Apply f to nodes and error names *)
let iter (f: iter_fun) (err_log: t) = let iter (f: iter_fun) (err_log: t) =
ErrLogHash.iter (fun (ekind, in_footprint, err_name, desc, severity) set -> ErrLogHash.iter (fun (ekind, in_footprint, err_name, desc, severity) set ->
ErrDataSet.iter 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 f
node_id_key loc ml_loc_opt ekind in_footprint err_name 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) set)
err_log err_log
@ -127,7 +128,7 @@ let pp_warnings fmt (errlog : t) =
let pp_html source path_to_root fmt (errlog: t) = let pp_html source path_to_root fmt (errlog: t) =
let pp_eds fmt eds = let pp_eds fmt eds =
let pp_nodeid_session_loc 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 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 ErrDataSet.iter (pp_nodeid_session_loc fmt) eds in
let f do_fp ek (ekind, infp, err_name, desc, _) eds = 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 -> (fun (ekind, infp, s, desc, severity) l ->
ignore (add_issue errlog_old (ekind, infp, s, desc, severity) l)) errlog_new 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 = let err_name, desc, ml_loc_opt, visibility, severity, force_kind, eclass =
Exceptions.recognize_exception exn in Exceptions.recognize_exception exn in
let ekind = match force_kind with 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 add_issue err_log
(ekind, !Config.footprint, err_name, desc, severity_to_str severity) (ekind, !Config.footprint, err_name, desc, severity_to_str severity)
(ErrDataSet.singleton (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 = let should_print_now =
match exn with match exn with
| Exceptions.Internal_error _ -> true | Exceptions.Internal_error _ -> true
@ -286,7 +288,7 @@ module Err_table = struct
ErrDataSet.iter (fun loc -> add_err loc err_name) eds in ErrDataSet.iter (fun loc -> add_err loc err_name) eds in
ErrLogHash.iter f err_table; 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) -> List.iter ~f:(fun (err_name, desc) ->
Exceptions.pp_err nodeidkey loc ekind err_name desc ml_loc_opt fmt ()) err_names in Exceptions.pp_err nodeidkey loc ekind err_name desc ml_loc_opt fmt ()) err_names in
F.fprintf fmt "@.Detailed errors during footprint phase:@."; F.fprintf fmt "@.Detailed errors during footprint phase:@.";

@ -42,6 +42,7 @@ type iter_fun =
loc_trace -> loc_trace ->
Exceptions.err_class -> Exceptions.err_class ->
Exceptions.visibility -> Exceptions.visibility ->
string option ->
unit unit
(** Apply f to nodes and error names *) (** 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 update : t -> t -> unit
val log_issue : 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} *) (** {2 Functions for manipulating per-file error tables} *)

@ -388,7 +388,7 @@ let module IssuesCsv = {
/** Write bug report in csv format */ /** Write bug report in csv format */
let pp_issues_of_error_log fmt error_filter _ proc_loc_opt procname err_log => { let pp_issues_of_error_log fmt error_filter _ proc_loc_opt procname err_log => {
let pp x => F.fprintf fmt x; 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 = let source_file =
switch proc_loc_opt { switch proc_loc_opt {
| Some proc_loc => proc_loc.Location.file | Some proc_loc => proc_loc.Location.file
@ -461,7 +461,8 @@ let module IssuesJson = {
severity severity
ltr ltr
eclass eclass
visibility => { visibility
linters_def_file => {
let (source_file, procedure_start_line) = let (source_file, procedure_start_line) =
switch proc_loc_opt { switch proc_loc_opt {
| Some proc_loc => (proc_loc.Location.file, proc_loc.Location.line) | 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, hash: get_bug_hash kind bug_type procedure_id file node_key error_desc,
dotty: error_desc_to_dotty_string error_desc, dotty: error_desc_to_dotty_string error_desc,
infer_source_loc: json_ml_loc, 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) { if (not !is_first_item) {
pp "," pp ","
@ -577,7 +579,7 @@ let module IssuesTxt = {
/** Write bug report in text format */ /** Write bug report in text format */
let pp_issues_of_error_log fmt error_filter _ proc_loc_opt _ err_log => { 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 = let source_file =
switch proc_loc_opt { switch proc_loc_opt {
| Some proc_loc => proc_loc.Location.file | Some proc_loc => proc_loc.Location.file
@ -646,7 +648,7 @@ let module IssuesXml = {
/** print issues from summary in xml */ /** print issues from summary in xml */
let pp_issues_of_error_log fmt error_filter linereader proc_loc_opt proc_name err_log => { 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 = let source_file =
switch proc_loc_opt { switch proc_loc_opt {
| Some proc_loc => proc_loc.Location.file | 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 process_err_log error_filter linereader err_log stats => {
let found_errors = ref false; 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; let type_str = Localise.to_issue_id error_name;
if (in_footprint && error_filter error_desc error_name) { if (in_footprint && error_filter error_desc error_name) {
switch ekind { switch ekind {

@ -38,6 +38,7 @@ type jsonbug = {
?dotty : string option; ?dotty : string option;
?infer_source_loc: loc option; ?infer_source_loc: loc option;
bug_type_hum: string; bug_type_hum: string;
?linters_def_file: string option;
} }
type report = jsonbug list type report = jsonbug list

@ -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 *) (** 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 create_table_err_per_line err_log =
let err_per_line = Hashtbl.create 17 in 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 = let err_str =
Localise.to_issue_id err_name ^ Localise.to_issue_id err_name ^
" " ^ " " ^

@ -16,6 +16,7 @@ type log_t =
?node_id: (int * int) -> ?node_id: (int * int) ->
?session: int -> ?session: int ->
?ltr: Errlog.loc_trace -> ?ltr: Errlog.loc_trace ->
?linters_def_file:string ->
exn -> exn ->
unit unit
@ -23,7 +24,7 @@ type log_issue = Typ.Procname.t -> log_t
type log_issue_from_errlog = Errlog.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 let loc = match loc with
| None -> State.get_loc () | None -> State.get_loc ()
| Some loc -> loc in | 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 | _ -> let err_name, _, _, _, _, _, _ = Exceptions.recognize_exception exn in
(Localise.to_issue_id err_name) in (Localise.to_issue_id err_name) in
if (Inferconfig.is_checker_enabled err_name) then 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 let log_issue
@ -51,6 +52,7 @@ let log_issue
?node_id ?node_id
?session ?session
?ltr ?ltr
?linters_def_file
exn = exn =
let should_suppress_lint (summary : Specs.summary) = let should_suppress_lint (summary : Specs.summary) =
Config.curr_language_is Config.Java && Config.curr_language_is Config.Java &&
@ -59,7 +61,7 @@ let log_issue
| Some summary when should_suppress_lint summary -> () | Some summary when should_suppress_lint summary -> ()
| Some summary -> | Some summary ->
let err_log = summary.Specs.attributes.ProcAttributes.err_log in 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 -> | None ->
failwithf failwithf
"Trying to report error on procedure %a, but cannot because no summary exists for this \ "Trying to report error on procedure %a, but cannot because no summary exists for this \

@ -16,6 +16,7 @@ type log_t =
?node_id: (int * int) -> ?node_id: (int * int) ->
?session: int -> ?session: int ->
?ltr: Errlog.loc_trace -> ?ltr: Errlog.loc_trace ->
?linters_def_file:string ->
exn -> exn ->
unit unit

@ -312,6 +312,7 @@ type log_issue =
?node_id: (int * int) -> ?node_id: (int * int) ->
?session: int -> ?session: int ->
?ltr: Errlog.loc_trace -> ?ltr: Errlog.loc_trace ->
?linters_def_file:string ->
exn -> exn ->
unit unit

@ -90,6 +90,7 @@ type log_issue =
?node_id: (int * int) -> ?node_id: (int * int) ->
?session: int -> ?session: int ->
?ltr: Errlog.loc_trace -> ?ltr: Errlog.loc_trace ->
?linters_def_file:string ->
exn -> exn ->
unit unit

@ -190,7 +190,7 @@ let get_err_log translation_unit_context method_decl_opt =
LintIssues.get_err_log procname LintIssues.get_err_log procname
(* Add a frontend warning with a description desc at location loc to the errlog of a proc desc *) (* 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 name = issue_desc.CIssue.name in
let loc = issue_desc.CIssue.loc in let loc = issue_desc.CIssue.loc in
let errlog = get_err_log translation_unit_context method_decl_opt 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 method_name = CAst_utils.full_name_of_decl_opt method_decl_opt in
let key = Hashtbl.hash (key ^ method_name) in let key = Hashtbl.hash (key ^ method_name) in
Reporting.log_issue_from_errlog err_kind errlog exn ~loc ~ltr:trace 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) = let get_current_method context (an : Ctl_parser_types.ast_node) =
match an with match an with
@ -215,13 +215,13 @@ let get_current_method context (an : Ctl_parser_types.ast_node) =
| Decl (BlockDecl _ as d) -> Some d | Decl (BlockDecl _ as d) -> Some d
| _ -> context.CLintersContext.current_method | _ -> 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 let desc = remove_new_lines
(expand_message_string issue_desc.CIssue.description an) in (expand_message_string issue_desc.CIssue.description an) in
let issue_desc' = let issue_desc' =
{issue_desc with CIssue.description = desc; CIssue.loc = loc } in {issue_desc with CIssue.description = desc; CIssue.loc = loc } in
log_frontend_issue context.CLintersContext.translation_unit_context 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) *) (* Calls the set of hard coded checkers (if any) *)
let invoke_set_of_hard_coded_checkers_an context (an : Ctl_parser_types.ast_node) = 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 -> List.iter ~f:(fun issue_desc ->
if CIssue.should_run_check issue_desc.CIssue.mode then if CIssue.should_run_check issue_desc.CIssue.mode then
let loc = issue_desc.CIssue.loc in 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 ) issue_desc_list
) checkers ) 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 && if CIssue.should_run_check linter.issue_desc.CIssue.mode &&
CTL.eval_formula linter.condition an context then CTL.eval_formula linter.condition an context then
let loc = CFrontend_checkers.location_from_an context an in 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 ) parsed_linters
(* We decouple the hardcoded checkers from the parsed ones *) (* We decouple the hardcoded checkers from the parsed ones *)

@ -27,7 +27,8 @@ let create_fake_jsonbug
?(qualifier_tags=[]) ?(qualifier_tags=[])
?(hash=1) ?(hash=1)
?(dotty=None) ?(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; bug_class;
kind; kind;
@ -48,6 +49,7 @@ let create_fake_jsonbug
dotty; dotty;
infer_source_loc; infer_source_loc;
bug_type_hum = kind; bug_type_hum = kind;
linters_def_file
} }
let pp_diff_of_int_list group_name fmt (expected, actual) = let pp_diff_of_int_list group_name fmt (expected, actual) =

Loading…
Cancel
Save