From e320d8a580a3426f8a368d303dc8dee589119ab9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ezgi=20=C3=87i=C3=A7ek?= Date: Mon, 29 Jul 2019 10:10:03 -0700 Subject: [PATCH] [config] Rename `filter-report` command to `censor-report` and stop reporting them on console and bugs.txt Summary: - Rename `filter-report` command to `censor-report`and update comments - Stop reporting censored issues on the console and in `bugs.txt` Reviewed By: jvillard Differential Revision: D16540525 fbshipit-source-id: f5f7dcea3 --- infer/lib/python/inferlib/issues.py | 17 +++++--- infer/man/man1/infer-full.txt | 43 ++++++++++---------- infer/man/man1/infer-report.txt | 37 +++++++++-------- infer/man/man1/infer-run.txt | 37 +++++++++-------- infer/man/man1/infer.txt | 37 +++++++++-------- infer/src/backend/InferPrint.ml | 2 +- infer/src/base/Config.ml | 62 +++++++++++++++-------------- infer/src/base/Config.mli | 4 +- 8 files changed, 130 insertions(+), 109 deletions(-) diff --git a/infer/lib/python/inferlib/issues.py b/infer/lib/python/inferlib/issues.py index 93d23f838..f7599be82 100644 --- a/infer/lib/python/inferlib/issues.py +++ b/infer/lib/python/inferlib/issues.py @@ -31,6 +31,7 @@ ISSUE_SEVERITY_ADVICE = 'ADVICE' ISSUE_SEVERITY_LIKE = 'LIKE' # field names in rows of json reports +JSON_INDEX_CENSORED_REASON = 'censored_reason' JSON_INDEX_DOTTY = 'dotty' JSON_INDEX_FILENAME = 'file' JSON_INDEX_HASH = 'hash' @@ -177,12 +178,18 @@ def _text_of_report_list(project_root, reports, bugs_txt_path, limit=None, return bug_list + summary +def _get_censored_reason(report): + return report.get(JSON_INDEX_CENSORED_REASON) + def _is_user_visible(report): - return report[JSON_INDEX_SEVERITY] in [ - ISSUE_SEVERITY_ERROR, - ISSUE_SEVERITY_WARNING, - ISSUE_SEVERITY_ADVICE, - ISSUE_SEVERITY_LIKE] + if _get_censored_reason(report) is not None: + return False + else: + return report[JSON_INDEX_SEVERITY] in [ + ISSUE_SEVERITY_ERROR, + ISSUE_SEVERITY_WARNING, + ISSUE_SEVERITY_ADVICE, + ISSUE_SEVERITY_LIKE] def print_and_save_errors(infer_out, project_root, json_report, bugs_out, diff --git a/infer/man/man1/infer-full.txt b/infer/man/man1/infer-full.txt index 9d5db425e..ce40ef9a8 100644 --- a/infer/man/man1/infer-full.txt +++ b/infer/man/man1/infer-full.txt @@ -163,6 +163,26 @@ OPTIONS expression (only supported by the javac integration for now). See also infer-capture(1) and infer-run(1). + --censor-report +string + Specify a filter for issues to be censored by adding a + 'censored_reason' field in the json report. Infer will not report + censored issues on the console output and in bugs.txt, but tools + that post-process the json report can take them into account. If + multiple filters are specified, they are applied in the order in + which they are specified. Each filter is applied to each issue + detected, and only issues which are accepted by all filters are + reported. Each filter is of the form: + `::`. The first + two components are OCaml Str regular expressions, with an optional + `!` character prefix. If a regex has a `!` prefix, the polarity is + inverted, and the filter becomes a "blacklist" instead of a + "whitelist". Each filter is interpreted as an implication: an + issue matches if it does not match the `issue_type_regex` or if it + does match the `filename_regex`. The filenames that are tested by + the regex are relative to the `--project-root` directory. The + `` is a non-empty string used to explain why the + issue was filtered. See also infer-report(1) and infer-run(1). + --changed-files-index file Specify the file containing the list of source files from which reactive analysis should start. Source files should be specified @@ -514,23 +534,6 @@ OPTIONS JSON with a list of file renamings to use while computing differential reports See also infer-reportdiff(1). - --filter-report +string - Specify a filter for issues to report. If multiple filters are - specified, they are applied in the order in which they are - specified. Each filter is applied to each issue detected, and only - issues which are accepted by all filters are reported. Each filter - is of the form: - `::`. The first - two components are OCaml Str regular expressions, with an optional - `!` character prefix. If a regex has a `!` prefix, the polarity is - inverted, and the filter becomes a "blacklist" instead of a - "whitelist". Each filter is interpreted as an implication: an - issue matches if it does not match the `issue_type_regex` or if it - does match the `filename_regex`. The filenames that are tested by - the regex are relative to the `--project-root` directory. The - `` is a non-empty string used to explain why the - issue was filtered. See also infer-report(1) and infer-run(1). - --no-filtering,-F Deactivates: Do not show the experimental and blacklisted issue types (Conversely: --filtering | -f) See also infer-report(1). @@ -1184,6 +1187,9 @@ INTERNAL OPTIONS --capture-blacklist-reset Cancel the effect of --capture-blacklist. + --censor-report-reset + Set --censor-report to the empty list. + --changed-files-index-reset Cancel the effect of --changed-files-index. @@ -1355,9 +1361,6 @@ INTERNAL OPTIONS Deactivates: Filters specified in .inferconfig (Conversely: --filter-paths) - --filter-report-reset - Set --filter-report to the empty list. - --force-integration-reset Cancel the effect of --force-integration. diff --git a/infer/man/man1/infer-report.txt b/infer/man/man1/infer-report.txt index c501217fd..0ed1a8cb3 100644 --- a/infer/man/man1/infer-report.txt +++ b/infer/man/man1/infer-report.txt @@ -15,6 +15,26 @@ DESCRIPTION OPTIONS + --censor-report +string + Specify a filter for issues to be censored by adding a + 'censored_reason' field in the json report. Infer will not report + censored issues on the console output and in bugs.txt, but tools + that post-process the json report can take them into account. If + multiple filters are specified, they are applied in the order in + which they are specified. Each filter is applied to each issue + detected, and only issues which are accepted by all filters are + reported. Each filter is of the form: + `::`. The first + two components are OCaml Str regular expressions, with an optional + `!` character prefix. If a regex has a `!` prefix, the polarity is + inverted, and the filter becomes a "blacklist" instead of a + "whitelist". Each filter is interpreted as an implication: an + issue matches if it does not match the `issue_type_regex` or if it + does match the `filename_regex`. The filenames that are tested by + the regex are relative to the `--project-root` directory. The + `` is a non-empty string used to explain why the + issue was filtered. + --debug,-g Activates: Debug mode (also sets --debug-level 2, --developer-mode, --no-filtering, --print-buckets, --print-types, @@ -227,23 +247,6 @@ OPTIONS checker run; see individual checker options to turn them on or off. - --filter-report +string - Specify a filter for issues to report. If multiple filters are - specified, they are applied in the order in which they are - specified. Each filter is applied to each issue detected, and only - issues which are accepted by all filters are reported. Each filter - is of the form: - `::`. The first - two components are OCaml Str regular expressions, with an optional - `!` character prefix. If a regex has a `!` prefix, the polarity is - inverted, and the filter becomes a "blacklist" instead of a - "whitelist". Each filter is interpreted as an implication: an - issue matches if it does not match the `issue_type_regex` or if it - does match the `filename_regex`. The filenames that are tested by - the regex are relative to the `--project-root` directory. The - `` is a non-empty string used to explain why the - issue was filtered. - --no-filtering,-F Deactivates: Do not show the experimental and blacklisted issue types (Conversely: --filtering | -f) diff --git a/infer/man/man1/infer-run.txt b/infer/man/man1/infer-run.txt index 4edab6a8d..8e3578317 100644 --- a/infer/man/man1/infer-run.txt +++ b/infer/man/man1/infer-run.txt @@ -16,6 +16,26 @@ DESCRIPTION OPTIONS + --censor-report +string + Specify a filter for issues to be censored by adding a + 'censored_reason' field in the json report. Infer will not report + censored issues on the console output and in bugs.txt, but tools + that post-process the json report can take them into account. If + multiple filters are specified, they are applied in the order in + which they are specified. Each filter is applied to each issue + detected, and only issues which are accepted by all filters are + reported. Each filter is of the form: + `::`. The first + two components are OCaml Str regular expressions, with an optional + `!` character prefix. If a regex has a `!` prefix, the polarity is + inverted, and the filter becomes a "blacklist" instead of a + "whitelist". Each filter is interpreted as an implication: an + issue matches if it does not match the `issue_type_regex` or if it + does match the `filename_regex`. The filenames that are tested by + the regex are relative to the `--project-root` directory. The + `` is a non-empty string used to explain why the + issue was filtered. + --debug,-g Activates: Debug mode (also sets --debug-level 2, --developer-mode, --no-filtering, --print-buckets, --print-types, @@ -45,23 +65,6 @@ OPTIONS Activates: Exit with error code 2 if Infer found something to report (Conversely: --no-fail-on-issue) - --filter-report +string - Specify a filter for issues to report. If multiple filters are - specified, they are applied in the order in which they are - specified. Each filter is applied to each issue detected, and only - issues which are accepted by all filters are reported. Each filter - is of the form: - `::`. The first - two components are OCaml Str regular expressions, with an optional - `!` character prefix. If a regex has a `!` prefix, the polarity is - inverted, and the filter becomes a "blacklist" instead of a - "whitelist". Each filter is interpreted as an implication: an - issue matches if it does not match the `issue_type_regex` or if it - does match the `filename_regex`. The filenames that are tested by - the regex are relative to the `--project-root` directory. The - `` is a non-empty string used to explain why the - issue was filtered. - --force-delete-results-dir Activates: Do not refuse to delete the results directory if it doesn't look like an infer results directory. (Conversely: diff --git a/infer/man/man1/infer.txt b/infer/man/man1/infer.txt index 616aa5719..c390bf99f 100644 --- a/infer/man/man1/infer.txt +++ b/infer/man/man1/infer.txt @@ -163,6 +163,26 @@ OPTIONS expression (only supported by the javac integration for now). See also infer-capture(1) and infer-run(1). + --censor-report +string + Specify a filter for issues to be censored by adding a + 'censored_reason' field in the json report. Infer will not report + censored issues on the console output and in bugs.txt, but tools + that post-process the json report can take them into account. If + multiple filters are specified, they are applied in the order in + which they are specified. Each filter is applied to each issue + detected, and only issues which are accepted by all filters are + reported. Each filter is of the form: + `::`. The first + two components are OCaml Str regular expressions, with an optional + `!` character prefix. If a regex has a `!` prefix, the polarity is + inverted, and the filter becomes a "blacklist" instead of a + "whitelist". Each filter is interpreted as an implication: an + issue matches if it does not match the `issue_type_regex` or if it + does match the `filename_regex`. The filenames that are tested by + the regex are relative to the `--project-root` directory. The + `` is a non-empty string used to explain why the + issue was filtered. See also infer-report(1) and infer-run(1). + --changed-files-index file Specify the file containing the list of source files from which reactive analysis should start. Source files should be specified @@ -514,23 +534,6 @@ OPTIONS JSON with a list of file renamings to use while computing differential reports See also infer-reportdiff(1). - --filter-report +string - Specify a filter for issues to report. If multiple filters are - specified, they are applied in the order in which they are - specified. Each filter is applied to each issue detected, and only - issues which are accepted by all filters are reported. Each filter - is of the form: - `::`. The first - two components are OCaml Str regular expressions, with an optional - `!` character prefix. If a regex has a `!` prefix, the polarity is - inverted, and the filter becomes a "blacklist" instead of a - "whitelist". Each filter is interpreted as an implication: an - issue matches if it does not match the `issue_type_regex` or if it - does match the `filename_regex`. The filenames that are tested by - the regex are relative to the `--project-root` directory. The - `` is a non-empty string used to explain why the - issue was filtered. See also infer-report(1) and infer-run(1). - --no-filtering,-F Deactivates: Do not show the experimental and blacklisted issue types (Conversely: --filtering | -f) See also infer-report(1). diff --git a/infer/src/backend/InferPrint.ml b/infer/src/backend/InferPrint.ml index dec2ab8b3..b79a1243d 100644 --- a/infer/src/backend/InferPrint.ml +++ b/infer/src/backend/InferPrint.ml @@ -173,7 +173,7 @@ let censored_reason (issue_type : IssueType.t) source_file = in Option.some_if (not accepted) reason in - List.find_map Config.filter_report ~f:rejected_by + List.find_map Config.censor_report ~f:rejected_by let potential_exception_message = "potential exception at line" diff --git a/infer/src/base/Config.ml b/infer/src/base/Config.ml index 569661931..90497694f 100644 --- a/infer/src/base/Config.ml +++ b/infer/src/base/Config.ml @@ -922,6 +922,23 @@ and capture_blacklist = the javac integration for now)." +and censor_report = + CLOpt.mk_string_list ~long:"censor-report" ~deprecated:["-filter-report"] + ~in_help:InferCommand.[(Report, manual_generic); (Run, manual_generic)] + "Specify a filter for issues to be censored by adding a 'censored_reason' field in the json \ + report. Infer will not report censored issues on the console output and in bugs.txt, but \ + tools that post-process the json report can take them into account. If multiple filters are \ + specified, they are applied in the order in which they are specified. Each filter is applied \ + to each issue detected, and only issues which are accepted by all filters are reported. Each \ + filter is of the form: `::`. The first two \ + components are OCaml Str regular expressions, with an optional `!` character prefix. If a \ + regex has a `!` prefix, the polarity is inverted, and the filter becomes a \"blacklist\" \ + instead of a \"whitelist\". Each filter is interpreted as an implication: an issue matches \ + if it does not match the `issue_type_regex` or if it does match the `filename_regex`. The \ + filenames that are tested by the regex are relative to the `--project-root` directory. The \ + `` is a non-empty string used to explain why the issue was filtered." + + and changed_files_index = CLOpt.mk_path_opt ~long:"changed-files-index" ~in_help:InferCommand.[(Analyze, manual_generic); (Diff, manual_generic)] @@ -1401,21 +1418,6 @@ and filter_paths = CLOpt.mk_bool ~long:"filter-paths" ~default:true "Filters specified in .inferconfig" -and filter_report = - CLOpt.mk_string_list ~long:"filter-report" - ~in_help:InferCommand.[(Report, manual_generic); (Run, manual_generic)] - "Specify a filter for issues to report. If multiple filters are specified, they are applied \ - in the order in which they are specified. Each filter is applied to each issue detected, and \ - only issues which are accepted by all filters are reported. Each filter is of the form: \ - `::`. The first two components are OCaml \ - Str regular expressions, with an optional `!` character prefix. If a regex has a `!` prefix, \ - the polarity is inverted, and the filter becomes a \"blacklist\" instead of a \"whitelist\". \ - Each filter is interpreted as an implication: an issue matches if it does not match the \ - `issue_type_regex` or if it does match the `filename_regex`. The filenames that are tested \ - by the regex are relative to the `--project-root` directory. The `` is a \ - non-empty string used to explain why the issue was filtered." - - and flavors = CLOpt.mk_bool ~deprecated:["-use-flavors"] ~long:"flavors" ~in_help:InferCommand.[(Capture, manual_buck_flavors)] @@ -2731,6 +2733,21 @@ and capture = and capture_blacklist = !capture_blacklist +and censor_report = + List.map !censor_report ~f:(fun str -> + match String.split str ~on:':' with + | [issue_type_re; filename_re; reason_str] + when not String.(is_empty issue_type_re || is_empty filename_re || is_empty reason_str) -> + let polarity_regex re = + let polarity = not (Char.equal '!' re.[0]) in + let regex = Str.regexp (if polarity then re else String.slice re 1 0) in + (polarity, regex) + in + (polarity_regex issue_type_re, polarity_regex filename_re, reason_str) + | _ -> + L.(die UserError) "Ill-formed report filter: %s" str ) + + and changed_files_index = !changed_files_index and nullsafe = !nullsafe @@ -2827,21 +2844,6 @@ and file_renamings = !file_renamings and filter_paths = !filter_paths -and filter_report = - List.map !filter_report ~f:(fun str -> - match String.split str ~on:':' with - | [issue_type_re; filename_re; reason_str] - when not String.(is_empty issue_type_re || is_empty filename_re || is_empty reason_str) -> - let polarity_regex re = - let polarity = not (Char.equal '!' re.[0]) in - let regex = Str.regexp (if polarity then re else String.slice re 1 0) in - (polarity, regex) - in - (polarity_regex issue_type_re, polarity_regex filename_re, reason_str) - | _ -> - L.(die UserError) "Ill-formed report filter: %s" str ) - - and filtering = !filtering and flavors = !flavors diff --git a/infer/src/base/Config.mli b/infer/src/base/Config.mli index 8cdc78b21..ba896973f 100644 --- a/infer/src/base/Config.mli +++ b/infer/src/base/Config.mli @@ -268,6 +268,8 @@ val capture_blacklist : string option val captured_dir : string (** directory where the results of the capture phase are stored *) +val censor_report : ((bool * Str.regexp) * (bool * Str.regexp) * string) list + val changed_files_index : string option val check_version : string option @@ -364,8 +366,6 @@ val file_renamings : string option val filter_paths : bool -val filter_report : ((bool * Str.regexp) * (bool * Str.regexp) * string) list - val filtering : bool val flavors : bool