From f5d3870485b1dcca8642193378da4a974989c4b7 Mon Sep 17 00:00:00 2001 From: Dulma Churchill Date: Thu, 25 May 2017 06:18:08 -0700 Subject: [PATCH] [linters] Adding a new error type like Reviewed By: martinoluca Differential Revision: D5111078 fbshipit-source-id: 06e14b8 --- infer/lib/python/inferlib/colorize.py | 1 + infer/lib/python/inferlib/issues.py | 9 ++++++++- infer/src/IR/Errlog.ml | 8 ++++++-- infer/src/IR/Exceptions.ml | 3 ++- infer/src/IR/Exceptions.mli | 2 +- infer/src/backend/InferPrint.re | 6 +++++- infer/src/clang/cFrontend_errors.ml | 1 + .../objc/linters-for-test-only/linters_example.al | 2 +- 8 files changed, 25 insertions(+), 7 deletions(-) diff --git a/infer/lib/python/inferlib/colorize.py b/infer/lib/python/inferlib/colorize.py index 0d33f5088..683e02eab 100644 --- a/infer/lib/python/inferlib/colorize.py +++ b/infer/lib/python/inferlib/colorize.py @@ -46,6 +46,7 @@ HEADER = BRIGHT SUCCESS = BLUE_BG + WHITE + BRIGHT WARNING = '' ADVICE = '' +LIKE = '' class Invalid_mode(Exception): diff --git a/infer/lib/python/inferlib/issues.py b/infer/lib/python/inferlib/issues.py index 4aef00016..6360a102e 100644 --- a/infer/lib/python/inferlib/issues.py +++ b/infer/lib/python/inferlib/issues.py @@ -30,6 +30,7 @@ ISSUE_KIND_ERROR = 'ERROR' ISSUE_KIND_WARNING = 'WARNING' ISSUE_KIND_INFO = 'INFO' ISSUE_KIND_ADVICE = 'ADVICE' +ISSUE_KIND_LIKE = 'LIKE' # field names in rows of json reports JSON_INDEX_DOTTY = 'dotty' @@ -122,6 +123,8 @@ def _text_of_report_list(project_root, reports, bugs_txt_path, limit=None, msg = colorize.color(msg, colorize.WARNING, formatter) elif report[JSON_INDEX_KIND] == ISSUE_KIND_ADVICE: msg = colorize.color(msg, colorize.ADVICE, formatter) + elif report[JSON_INDEX_KIND] == ISSUE_KIND_LIKE: + msg = colorize.color(msg, colorize.LIKE, formatter) text = '%s%s' % (msg, source_context) text_errors_list.append(text) @@ -177,7 +180,11 @@ def _text_of_report_list(project_root, reports, bugs_txt_path, limit=None, def _is_user_visible(project_root, report): kind = report[JSON_INDEX_KIND] - return kind in [ISSUE_KIND_ERROR, ISSUE_KIND_WARNING, ISSUE_KIND_ADVICE] + return kind in [ + ISSUE_KIND_ERROR, + ISSUE_KIND_WARNING, + ISSUE_KIND_ADVICE, + ISSUE_KIND_LIKE] def print_and_save_errors(infer_out, project_root, json_report, bugs_out, diff --git a/infer/src/IR/Errlog.ml b/infer/src/IR/Errlog.ml index e9392adfe..1b2f5afb1 100644 --- a/infer/src/IR/Errlog.ml +++ b/infer/src/IR/Errlog.ml @@ -274,7 +274,9 @@ let log_issue err_kind err_log loc (node_id, node_key) session ltr ?linters_def_ let d = match err_kind with | Exceptions.Kerror -> L.d_error | Exceptions.Kwarning -> L.d_warning - | Exceptions.Kinfo | Exceptions.Kadvice -> L.d_info in + | Exceptions.Kinfo + | Exceptions.Kadvice + | Exceptions.Klike -> L.d_info in d warn_str; L.d_ln(); end in if should_print_now then print_now () @@ -319,6 +321,7 @@ module Err_table = struct let map_warn_re = ref LocMap.empty in let map_info = ref LocMap.empty in let map_advice = ref LocMap.empty in + let map_likes = ref LocMap.empty in let add_err nslm key = let map = match key.in_footprint, key.err_kind with | true, Exceptions.Kerror -> map_err_fp @@ -326,7 +329,8 @@ module Err_table = struct | true, Exceptions.Kwarning -> map_warn_fp | false, Exceptions.Kwarning -> map_warn_re | _, Exceptions.Kinfo -> map_info - | _, Exceptions.Kadvice -> map_advice in + | _, Exceptions.Kadvice -> map_advice + | _, Exceptions.Klike -> map_likes in try let err_list = LocMap.find nslm !map in map := LocMap.add nslm ((key.err_name, key.err_desc) :: err_list) !map diff --git a/infer/src/IR/Exceptions.ml b/infer/src/IR/Exceptions.ml index 01dc045d9..ac57e33d4 100644 --- a/infer/src/IR/Exceptions.ml +++ b/infer/src/IR/Exceptions.ml @@ -40,7 +40,7 @@ type err_class = Checker | Prover | Nocat | Linters [@@deriving compare] let equal_err_class = [%compare.equal : err_class] (** kind of error/warning *) -type err_kind = Kwarning | Kerror | Kinfo | Kadvice [@@deriving compare] +type err_kind = Kwarning | Kerror | Kinfo | Kadvice | Klike [@@deriving compare] let equal_err_kind = [%compare.equal : err_kind] @@ -333,6 +333,7 @@ let err_kind_string = function | Kerror -> "ERROR" | Kinfo -> "INFO" | Kadvice -> "ADVICE" + | Klike -> "LIKE" (** string describing an error class *) let err_class_string = function diff --git a/infer/src/IR/Exceptions.mli b/infer/src/IR/Exceptions.mli index 0b8a13e22..53f4f0ff9 100644 --- a/infer/src/IR/Exceptions.mli +++ b/infer/src/IR/Exceptions.mli @@ -30,7 +30,7 @@ type severity = | Low (** low severity bug *) (** kind of error/warning *) -type err_kind = Kwarning | Kerror | Kinfo | Kadvice [@@deriving compare] +type err_kind = Kwarning | Kerror | Kinfo | Kadvice | Klike [@@deriving compare] val equal_err_kind : err_kind -> err_kind -> bool diff --git a/infer/src/backend/InferPrint.re b/infer/src/backend/InferPrint.re index a660f17b1..2f9dbc3b0 100644 --- a/infer/src/backend/InferPrint.re +++ b/infer/src/backend/InferPrint.re @@ -281,7 +281,8 @@ let should_report (issue_kind: Exceptions.err_kind) issue_type error_desc eclass | Kinfo => true | Kerror | Kwarning - | Kadvice => false + | Kadvice + | Klike => false }; if issue_kind_is_blacklisted { false @@ -642,6 +643,7 @@ module Stats = { mutable nerrors: int, mutable ninfos: int, mutable nadvice: int, + mutable nlikes: int, mutable nprocs: int, mutable nspecs: int, mutable ntimeouts: int, @@ -656,6 +658,7 @@ module Stats = { nerrors: 0, ninfos: 0, nadvice: 0, + nlikes: 0, nprocs: 0, nspecs: 0, ntimeouts: 0, @@ -723,6 +726,7 @@ module Stats = { | Exceptions.Kwarning => stats.nwarnings = stats.nwarnings + 1 | Exceptions.Kinfo => stats.ninfos = stats.ninfos + 1 | Exceptions.Kadvice => stats.nadvice = stats.nadvice + 1 + | Exceptions.Klike => stats.nlikes = stats.nlikes + 1 } } }; diff --git a/infer/src/clang/cFrontend_errors.ml b/infer/src/clang/cFrontend_errors.ml index 8547a2c96..43b32e5c8 100644 --- a/infer/src/clang/cFrontend_errors.ml +++ b/infer/src/clang/cFrontend_errors.ml @@ -114,6 +114,7 @@ let string_to_err_kind = function | "ERROR" -> Exceptions.Kerror | "INFO" -> Exceptions.Kinfo | "ADVICE" -> Exceptions.Kadvice + | "LIKE" -> Exceptions.Klike | s -> (Logging.out "\n[ERROR] Severity %s does not exist. Stop.\n" s; assert false) diff --git a/infer/tests/codetoanalyze/objc/linters-for-test-only/linters_example.al b/infer/tests/codetoanalyze/objc/linters-for-test-only/linters_example.al index 1a0d91436..5a523cf30 100644 --- a/infer/tests/codetoanalyze/objc/linters-for-test-only/linters_example.al +++ b/infer/tests/codetoanalyze/objc/linters-for-test-only/linters_example.al @@ -202,7 +202,7 @@ DEFINE-CHECKER TEST_NTH_PARAM_TYPE_CHECK = { HOLDS-IN-NODE ObjCMethodDecl; SET message = "Found a method with nth parameter of type...."; - + SET severity = "LIKE"; }; DEFINE-CHECKER TEST_NAMESPACE_NAME = {