From f4d32165428114745a28ec67c5111ea0601ca09d Mon Sep 17 00:00:00 2001 From: Matt Schellhas Date: Wed, 17 Jul 2019 15:38:06 -0700 Subject: [PATCH] Add flag and functionality to disable the ability to HH_FIXME or HH_IGNORE_ERROR 5000-5999 codes Summary: 5000 errors are reserved for linters. They should be ignored via lint specific suppression comments. Reviewed By: kmeht Differential Revision: D16289389 fbshipit-source-id: 4aca78554215f1744cb4776f537524e28de69acb --- hphp/hack/src/errors/errors.ml | 19 +++++++++++++++---- hphp/hack/src/errors/errors.mli | 2 ++ hphp/hack/src/hh_single_type_check.ml | 6 ++++++ hphp/hack/src/options/globalOptions.ml | 5 +++++ hphp/hack/src/options/globalOptions.mli | 5 +++++ hphp/hack/src/server/serverConfig.ml | 3 +++ hphp/hack/src/server/serverGlobalState.ml | 5 +++++ hphp/hack/src/utils/lint/lint_core.ml | 3 ++- 8 files changed, 43 insertions(+), 5 deletions(-) diff --git a/hphp/hack/src/errors/errors.ml b/hphp/hack/src/errors/errors.ml index 12c2e7638d1..f830593fc90 100644 --- a/hphp/hack/src/errors/errors.ml +++ b/hphp/hack/src/errors/errors.ml @@ -548,6 +548,7 @@ let error_codes_treated_strictly = ref (ISet.of_list []) let is_strict_code code = ISet.mem code !error_codes_treated_strictly let use_new_type_errors = ref false +let disable_linter_fixmes = ref false let default_ignored_fixme_codes = ISet.of_list [ Typing.err_code Typing.InvalidIsAsExpressionHint; @@ -565,7 +566,8 @@ let ignored_fixme_codes = ref default_ignored_fixme_codes let set_allow_errors_in_default_path x = allow_errors_in_default_path := x -let is_ignored_code code = ISet.mem code !ignored_fixme_codes +let is_ignored_code code = ISet.mem code !ignored_fixme_codes || + (!disable_linter_fixmes && (code / 1000) = 5) let is_ignored_fixme code = is_ignored_code code @@ -576,9 +578,18 @@ let (get_hh_fixme_pos: (Pos.t -> error_code -> Pos.t option) ref) = let add_ignored_fixme_code_error pos code = if !is_hh_fixme pos code && is_ignored_code code then let pos = Option.value (!get_hh_fixme_pos pos code) ~default:pos in - add_error (make_error code - [pos, - Printf.sprintf "You cannot use HH_FIXME or HH_IGNORE_ERROR comments to suppress error %d" code]) + if (code / 1000) = 5 + then + add_error (make_error code + [pos, + Printf.sprintf + "You cannot use HH_FIXME or HH_IGNORE_ERROR comments to suppress error %d.\ + Please use @lint-ignore." + code]) + else + add_error (make_error code + [pos, + Printf.sprintf "You cannot use HH_FIXME or HH_IGNORE_ERROR comments to suppress error %d" code]) (*****************************************************************************) (* Errors accumulator. *) diff --git a/hphp/hack/src/errors/errors.mli b/hphp/hack/src/errors/errors.mli index 3cd444fce8a..debae7b6fbf 100644 --- a/hphp/hack/src/errors/errors.mli +++ b/hphp/hack/src/errors/errors.mli @@ -40,6 +40,8 @@ val ignored_fixme_codes : ISet.t ref val error_codes_treated_strictly : ISet.t ref (* Flag that causes certain typing errors to be reported with different codes. *) val use_new_type_errors : bool ref +(* Flag that causes 5000-5999 to be unable to be suppressed with a FIXME *) +val disable_linter_fixmes : bool ref val is_strict_code : int -> bool val set_allow_errors_in_default_path : bool -> unit diff --git a/hphp/hack/src/hh_single_type_check.ml b/hphp/hack/src/hh_single_type_check.ml index 172806d1b3c..c562a2d57dc 100644 --- a/hphp/hack/src/hh_single_type_check.ml +++ b/hphp/hack/src/hh_single_type_check.ml @@ -213,6 +213,7 @@ let parse_options () = let disable_legacy_soft_typehints = ref false in let use_new_type_errors = ref false in let disable_outside_dollar_str_interp = ref false in + let disable_linter_fixmes = ref false in let options = [ "--ai", Arg.String (set_ai), @@ -453,6 +454,9 @@ let parse_options () = "--disable-outside-dollar-str-interp", Arg.Set disable_outside_dollar_str_interp, "Disables ${x} syntax for string interpolation (use {$x} instead)"; + "--disable-linter-fixmes", + Arg.Set disable_linter_fixmes, + "Disables HH_FIXME and HH_IGNORE_ERROR for 5000-5999 error codes"; ] in let options = Arg.align ~limit:25 options in Arg.parse options (fun fn -> fn_ref := fn::(!fn_ref)) usage; @@ -495,6 +499,7 @@ let parse_options () = ~po_disable_legacy_soft_typehints:!disable_legacy_soft_typehints ~use_new_type_errors:!use_new_type_errors ~po_disable_outside_dollar_str_interp:!disable_outside_dollar_str_interp + ~disable_linter_fixmes:!disable_linter_fixmes () in let tcopt = { @@ -518,6 +523,7 @@ let parse_options () = ~workers:None in Errors.use_new_type_errors := !use_new_type_errors; + Errors.disable_linter_fixmes := !disable_linter_fixmes; ({ files = fns; mode = !mode; diff --git a/hphp/hack/src/options/globalOptions.ml b/hphp/hack/src/options/globalOptions.ml index ddb335a2961..240db1a3e20 100644 --- a/hphp/hack/src/options/globalOptions.ml +++ b/hphp/hack/src/options/globalOptions.ml @@ -66,6 +66,7 @@ type t = { tco_use_lru_workers: bool; use_new_type_errors: bool; po_disable_outside_dollar_str_interp : bool; + disable_linter_fixmes: bool; } [@@deriving show] let tco_experimental_instanceof = "instanceof" @@ -251,6 +252,7 @@ let default = { tco_use_lru_workers = true; use_new_type_errors = false; po_disable_outside_dollar_str_interp = false; + disable_linter_fixmes = false; } let make @@ -311,6 +313,7 @@ let make ?(tco_use_lru_workers = default.tco_use_lru_workers) ?(use_new_type_errors = default.use_new_type_errors) ?(po_disable_outside_dollar_str_interp = default.po_disable_outside_dollar_str_interp) + ?(disable_linter_fixmes = default.disable_linter_fixmes) () = { tco_safe_array; @@ -371,6 +374,7 @@ let make tco_use_lru_workers; use_new_type_errors; po_disable_outside_dollar_str_interp; + disable_linter_fixmes; } let tco_safe_array t = t.tco_safe_array let tco_safe_vector_array t = t.tco_safe_vector_array @@ -453,6 +457,7 @@ let tco_use_lru_workers t = t.tco_use_lru_workers let use_new_type_errors t = t.use_new_type_errors let po_disable_outside_dollar_str_interp t = t.po_disable_outside_dollar_str_interp +let disable_linter_fixmes t = t.disable_linter_fixmes let setup_pocket_universes env enabled = let exp_features = env.tco_experimental_features in diff --git a/hphp/hack/src/options/globalOptions.mli b/hphp/hack/src/options/globalOptions.mli index dc09c2bd0f3..8ed6ecccb1e 100644 --- a/hphp/hack/src/options/globalOptions.mli +++ b/hphp/hack/src/options/globalOptions.mli @@ -270,6 +270,9 @@ type t = { (* Disable ${x} syntax for string interpolation in Hack and only allow {$x} *) po_disable_outside_dollar_str_interp : bool; + (* Force 5000s to be @lint-ignored rather than fixme'd *) + disable_linter_fixmes : bool; + } [@@deriving show] val make : @@ -330,6 +333,7 @@ val make : ?tco_use_lru_workers : bool -> ?use_new_type_errors : bool -> ?po_disable_outside_dollar_str_interp: bool -> + ?disable_linter_fixmes : bool -> unit -> t @@ -414,3 +418,4 @@ val po_disable_legacy_soft_typehints : t -> bool val tco_use_lru_workers : t -> bool val use_new_type_errors : t -> bool val po_disable_outside_dollar_str_interp : t -> bool +val disable_linter_fixmes : t -> bool diff --git a/hphp/hack/src/server/serverConfig.ml b/hphp/hack/src/server/serverConfig.ml index 5d419c7440a..afddc229079 100644 --- a/hphp/hack/src/server/serverConfig.ml +++ b/hphp/hack/src/server/serverConfig.ml @@ -318,6 +318,7 @@ let load config_filename options = ?tco_use_lru_workers:(Some local_config.ServerLocalConfig.use_lru_workers) ?use_new_type_errors:(bool_opt "use_new_type_errors" config) ?po_disable_outside_dollar_str_interp:(bool_opt "disable_outside_dollar_str_interp" config) + ?disable_linter_fixmes:(bool_opt "disable_linter_fixmes" config) () in Errors.ignored_fixme_codes := @@ -326,6 +327,8 @@ let load config_filename options = (GlobalOptions.error_codes_treated_strictly global_opts); Errors.use_new_type_errors := (GlobalOptions.use_new_type_errors global_opts); + Errors.disable_linter_fixmes := + (GlobalOptions.disable_linter_fixmes global_opts); { version = version; load_script_timeout = load_script_timeout; diff --git a/hphp/hack/src/server/serverGlobalState.ml b/hphp/hack/src/server/serverGlobalState.ml index b63f13b8469..7a1cc9bdd1e 100644 --- a/hphp/hack/src/server/serverGlobalState.ml +++ b/hphp/hack/src/server/serverGlobalState.ml @@ -17,6 +17,7 @@ type t = { fixme_codes : ISet.t; strict_codes : ISet.t; use_new_type_errors : bool; + disable_linter_fixmes : bool; paths_to_ignore : Str.regexp list; no_load : bool; logging_init : unit -> unit; @@ -32,6 +33,7 @@ let save ~logging_init = { fixme_codes = !Errors.ignored_fixme_codes; strict_codes = !Errors.error_codes_treated_strictly; use_new_type_errors = !Errors.use_new_type_errors; + disable_linter_fixmes = !Errors.disable_linter_fixmes; paths_to_ignore = FilesToIgnore.get_paths_to_ignore (); no_load = ServerLoadFlag.get_no_load (); logging_init; @@ -47,6 +49,7 @@ let restore state = Errors.ignored_fixme_codes := state.fixme_codes; Errors.error_codes_treated_strictly := state.strict_codes; Errors.use_new_type_errors := state.use_new_type_errors; + Errors.disable_linter_fixmes := state.disable_linter_fixmes; FilesToIgnore.set_paths_to_ignore state.paths_to_ignore; ServerLoadFlag.set_no_load state.no_load; Errors.set_allow_errors_in_default_path false; @@ -62,6 +65,7 @@ let to_string state = let fixme_codes = ISet.to_string state.fixme_codes in let strict_codes = ISet.to_string state.strict_codes in let use_new_type_errors = if state.use_new_type_errors then "true" else "false" in + let disable_linter_fixmes = if state.disable_linter_fixmes then "true" else "false" in (* OCaml regexps cannot be re-serialized to strings *) let paths_to_ignore = "(...)" in [ @@ -74,6 +78,7 @@ let to_string state = ("fixme_codes", fixme_codes); ("strict_codes", strict_codes); ("use_new_type_errors", use_new_type_errors); + ("disable_linter_fixmes", disable_linter_fixmes); ("paths_to_ignore", paths_to_ignore); ] |> List.map (fun (x, y) -> Printf.sprintf "%s : %s" x y) diff --git a/hphp/hack/src/utils/lint/lint_core.ml b/hphp/hack/src/utils/lint/lint_core.ml index 07d44221672..b6db36352af 100644 --- a/hphp/hack/src/utils/lint/lint_core.ml +++ b/hphp/hack/src/utils/lint/lint_core.ml @@ -50,7 +50,8 @@ let add message = match !lint_list with | Some lst -> - if !Errors.is_hh_fixme pos code then () else begin + if (not !Errors.disable_linter_fixmes) && !Errors.is_hh_fixme pos code + then () else begin let lint = { code; severity; pos; message; bypass_changed_lines; autofix } in lint_list := Some (lint :: lst) -- 2.11.4.GIT