diff --git a/infer/src/base/Config.ml b/infer/src/base/Config.ml index 24d7eae8e..999505512 100644 --- a/infer/src/base/Config.ml +++ b/infer/src/base/Config.ml @@ -1249,6 +1249,11 @@ and linters_def_folder = in linters_def_folder +and linters_doc_url = + CLOpt.mk_string_list ~long:"linters-doc-url" + ~in_help:CLOpt.([(Capture, manual_clang_linters)]) + "Specify custom documentation URL for some linter that overrides the default one. Useful if your project has specific ways of fixing a lint error that is not true in general or public info. Format: linter_name:doc_url." + and linters_ignore_clang_failures = CLOpt.mk_bool ~long:"linters-ignore-clang-failures" ~in_help:CLOpt.([(Capture, manual_clang_linters)]) @@ -1894,6 +1899,20 @@ let process_iphoneos_target_sdk_version_path_regex args = in List.map ~f:process_iphoneos_target_sdk_version_path_regex args +type linter_doc_url = {linter: string; doc_url: string} + +let process_linters_doc_url args = + let linters_doc_url arg = + match String.rsplit2 ~on:':' arg with + | Some (linter, doc_url) + -> {linter; doc_url} + | None + -> L.(die UserError) + "Incorrect format for the option linters-doc-url. The correct format is linter:doc_url but got %s" + arg + in + List.map ~f:linters_doc_url args + (** Freeze initialized configuration values *) let anon_args = !anon_args @@ -2100,6 +2119,8 @@ and linters_def_file = !linters_def_file and linters_def_folder = !linters_def_folder +and linters_doc_url = process_linters_doc_url !linters_doc_url + and linters_developer_mode = !linters_developer_mode and linters_ignore_clang_failures = !linters_ignore_clang_failures diff --git a/infer/src/base/Config.mli b/infer/src/base/Config.mli index 6a9697b18..8beb356a2 100644 --- a/infer/src/base/Config.mli +++ b/infer/src/base/Config.mli @@ -473,6 +473,10 @@ val linters_def_file : string list val linters_def_folder : string list +type linter_doc_url = {linter: string; doc_url: string} + +val linters_doc_url : linter_doc_url list + val linters_developer_mode : bool val linters_ignore_clang_failures : bool diff --git a/infer/src/clang/cFrontend_errors.ml b/infer/src/clang/cFrontend_errors.ml index 1df8fc5a5..2b0636edd 100644 --- a/infer/src/clang/cFrontend_errors.ml +++ b/infer/src/clang/cFrontend_errors.ml @@ -169,6 +169,17 @@ let string_to_issue_mode m = -> L.internal_error "@\n[ERROR] Mode %s does not exist. Please specify ON/OFF@\n" s ; assert false +let post_process_linter_definition (linter: linter) = + match + List.find Config.linters_doc_url ~f:(fun (linter_doc_url: Config.linter_doc_url) -> + String.equal linter.issue_desc.id linter_doc_url.linter ) + with + | Some linter_doc_url + -> let issue_desc = {linter.issue_desc with doc_url= Some linter_doc_url.doc_url} in + {linter with issue_desc} + | None + -> linter + (** Convert a parsed checker in list of linters *) let create_parsed_linters linters_def_file checkers : linter list = let open CIssue in @@ -215,7 +226,10 @@ let create_parsed_linters linters_def_file checkers : linter list = L.(debug Linters Medium) "@\nMaking condition and issue desc for checker '%s'@\n" checker.id ; L.(debug Linters Medium) "@\nCondition =@\n %a@\n" CTL.Debug.pp_formula condition ; L.(debug Linters Medium) "@\nIssue_desc = %a@\n" CIssue.pp_issue issue_desc ; - {condition; issue_desc; def_file= Some linters_def_file; whitelist_paths; blacklist_paths} + let linter = + {condition; issue_desc; def_file= Some linters_def_file; whitelist_paths; blacklist_paths} + in + post_process_linter_definition linter in List.map ~f:do_one_checker checkers diff --git a/infer/tests/codetoanalyze/objc/linters/Makefile b/infer/tests/codetoanalyze/objc/linters/Makefile index 27a880876..050621c21 100644 --- a/infer/tests/codetoanalyze/objc/linters/Makefile +++ b/infer/tests/codetoanalyze/objc/linters/Makefile @@ -9,7 +9,8 @@ TESTS_DIR = ../../.. ANALYZER = linters CLANG_OPTIONS = -x objective-c -fobjc-arc -c -INFER_OPTIONS = --no-filtering --debug-exceptions --project-root $(TESTS_DIR) --no-keep-going +INFER_OPTIONS = --no-filtering --debug-exceptions --project-root $(TESTS_DIR) --no-keep-going \ +--linters-doc-url "ASSIGN_POINTER_WARNING:www.example.com" INFERPRINT_OPTIONS = --issues-tests SOURCES = \