From a0aa29ebaf6906eed495ed0fbb929760870b0554 Mon Sep 17 00:00:00 2001 From: Samuel Reed Date: Thu, 26 Sep 2019 20:15:50 -0400 Subject: [PATCH] fix(declarations): remove unused suppression code Related to the previous commit, this backs out some of the code in #4916 related to file error suppression in the merge phase. This has the benefit of fixing erroneous ignoring of comment suppressions within those files, which was causing unexpected consequences. --- src/services/inference/init_js.ml | 2 -- src/services/inference/merge_service.ml | 4 --- src/typing/merge_js.ml | 2 -- src/typing/merge_js.mli | 1 - src/typing/type_inference_js.ml | 28 +++++-------------- src/typing/type_inference_js.mli | 2 -- testgen/flowtestgen_utils.ml | 1 - .../config_declarations.exp | 10 ++++++- 8 files changed, 16 insertions(+), 34 deletions(-) diff --git a/src/services/inference/init_js.ml b/src/services/inference/init_js.ml index 3cbe50ca88b..7942f8ca87c 100644 --- a/src/services/inference/init_js.ml +++ b/src/services/inference/init_js.ml @@ -64,7 +64,6 @@ let load_lib_files ~sig_cx ~options ~reader files = (fun (exclude_syms, results) file -> let lib_file = File_key.LibFile file in let lint_severities = options.Options.opt_lint_severities in - let file_options = Options.file_options options in let%lwt result = parse_lib_file ~reader options file in Lwt.return (match result with @@ -95,7 +94,6 @@ let load_lib_files ~sig_cx ~options ~reader files = ast ~exclude_syms ~lint_severities - ~file_options:(Some file_options) ~file_sig in let errors = Context.errors cx in diff --git a/src/services/inference/merge_service.ml b/src/services/inference/merge_service.ml index 68ffb244972..724ff7ad364 100644 --- a/src/services/inference/merge_service.ml +++ b/src/services/inference/merge_service.ml @@ -125,7 +125,6 @@ let merge_context_generic ~options ~reader ~get_ast_unsafe ~get_file_sig_unsafe let (master_cx, dep_cxs, file_reqs) = reqs_of_component ~reader component required in let metadata = Context.metadata_of_options options in let lint_severities = Options.lint_severities options in - let file_options = Some (Options.file_options options) in let strict_mode = Options.strict_mode options in let get_aloc_table_unsafe = Parsing_heaps.Reader_dispatcher.get_sig_ast_aloc_table_unsafe ~reader @@ -134,7 +133,6 @@ let merge_context_generic ~options ~reader ~get_ast_unsafe ~get_file_sig_unsafe Merge_js.merge_component ~metadata ~lint_severities - ~file_options ~strict_mode ~file_sigs ~phase @@ -221,7 +219,6 @@ let merge_contents_context ~reader options file ast info file_sig = in let metadata = Context.metadata_of_options options in let lint_severities = Options.lint_severities options in - let file_options = Some (Options.file_options options) in let strict_mode = Options.strict_mode options in let get_aloc_table_unsafe = Parsing_heaps.Reader_dispatcher.get_sig_ast_aloc_table_unsafe ~reader @@ -230,7 +227,6 @@ let merge_contents_context ~reader options file ast info file_sig = Merge_js.merge_component ~metadata ~lint_severities - ~file_options ~strict_mode ~file_sigs ~get_ast_unsafe:(fun _ -> (comments, aloc_ast)) diff --git a/src/typing/merge_js.ml b/src/typing/merge_js.ml index ad992bf9453..a59ce66fbf8 100644 --- a/src/typing/merge_js.ml +++ b/src/typing/merge_js.ml @@ -347,7 +347,6 @@ let detect_non_voidable_properties cx = let merge_component ~metadata ~lint_severities - ~file_options ~strict_mode ~file_sigs ~get_ast_unsafe @@ -416,7 +415,6 @@ let merge_component comments ast ~lint_severities - ~file_options ~file_sig in (cx :: cxs, tast :: tasts, FilenameMap.add filename cx impl_cxs)) diff --git a/src/typing/merge_js.mli b/src/typing/merge_js.mli index bce95336faa..67c6f5351ad 100644 --- a/src/typing/merge_js.mli +++ b/src/typing/merge_js.mli @@ -26,7 +26,6 @@ end val merge_component : metadata:Context.metadata -> lint_severities:Severity.severity LintSettings.t -> - file_options:Files.options option -> strict_mode:StrictModeSettings.t -> file_sigs:File_sig.With_ALoc.t Utils_js.FilenameMap.t -> get_ast_unsafe:(File_key.t -> get_ast_return) -> diff --git a/src/typing/type_inference_js.ml b/src/typing/type_inference_js.ml index 4fce3bd6e00..0d0e1e5536d 100644 --- a/src/typing/type_inference_js.ml +++ b/src/typing/type_inference_js.ml @@ -333,23 +333,9 @@ let scan_for_lint_suppressions = Context.add_severity_cover cx (Context.file cx) severity_cover; Context.add_lint_suppressions cx suppression_locs -let scan_for_suppressions cx lint_severities file_options comments = - let filename = File_key.to_string (Context.file cx) in - let declaration = - match file_options with - | Some file_options -> Files.is_declaration file_options filename - | None -> false - in - if declaration then - (* Declaration mode. - * We don't report any warnings or errors. *) - Context.remove_all_errors cx - else - (* Scan comments for line suppressions. *) - scan_for_error_suppressions cx comments; - scan_for_lint_suppressions cx lint_severities comments; - - () +let scan_for_suppressions cx lint_severities comments = + scan_for_error_suppressions cx comments; + scan_for_lint_suppressions cx lint_severities comments let add_require_tvars = let add cx desc loc = @@ -385,7 +371,7 @@ let add_require_tvars = (* build module graph *) (* Lint suppressions are handled iff lint_severities is Some. *) -let infer_ast ~lint_severities ~file_options ~file_sig cx filename comments aloc_ast = +let infer_ast ~lint_severities ~file_sig cx filename comments aloc_ast = assert (Context.is_checked cx); Flow_js.Cache.clear (); @@ -432,7 +418,7 @@ let infer_ast ~lint_severities ~file_options ~file_sig cx filename comments aloc (* infer *) Flow_js.flow_t cx (init_exports, local_exports_var); let typed_statements = infer_core cx aloc_statements in - scan_for_suppressions cx lint_severities file_options comments; + scan_for_suppressions cx lint_severities comments; let module_t = Import_export.mk_module_t cx reason in Context.add_module cx module_ref module_t; @@ -471,7 +457,7 @@ let with_libdef_builtins cx f = a) symbols from prior library loads are suppressed if found, b) bindings are added as properties to the builtin object *) -let infer_lib_file ~exclude_syms ~lint_severities ~file_options ~file_sig cx ast = +let infer_lib_file ~exclude_syms ~lint_severities ~file_sig cx ast = let aloc_ast = Ast_loc_utils.loc_to_aloc_mapper#program ast in let (_, _, comments) = ast in let (_, aloc_statements, _) = aloc_ast in @@ -487,7 +473,7 @@ let infer_lib_file ~exclude_syms ~lint_severities ~file_options ~file_sig cx ast with_libdef_builtins cx (fun () -> ignore (infer_core cx aloc_statements : (ALoc.t, ALoc.t * Type.t) Ast.Statement.t list); - scan_for_suppressions cx lint_severities file_options comments); + scan_for_suppressions cx lint_severities comments); ( module_scope |> Scope.( diff --git a/src/typing/type_inference_js.mli b/src/typing/type_inference_js.mli index 7311a5d4450..a716af39f96 100644 --- a/src/typing/type_inference_js.mli +++ b/src/typing/type_inference_js.mli @@ -8,7 +8,6 @@ (* Lint suppressions are handled iff lint_severities is Some. *) val infer_ast : lint_severities:Severity.severity LintSettings.t -> - file_options:Files.options option -> file_sig:File_sig.With_ALoc.t -> Context.t -> File_key.t -> @@ -20,7 +19,6 @@ val infer_ast : val infer_lib_file : exclude_syms:SSet.t -> lint_severities:Severity.severity LintSettings.t -> - file_options:Files.options option -> file_sig:File_sig.With_ALoc.t -> Context.t -> (Loc.t, Loc.t) Flow_ast.program -> diff --git a/testgen/flowtestgen_utils.ml b/testgen/flowtestgen_utils.ml index d6d4c606298..0b297325c70 100644 --- a/testgen/flowtestgen_utils.ml +++ b/testgen/flowtestgen_utils.ml @@ -681,7 +681,6 @@ let flow_check (code : string) : string option = builtins_ast ~exclude_syms:SSet.empty ~lint_severities - ~file_options:None ~file_sig:(File_sig.abstractify_locs builtins_file_sig) in let () = diff --git a/tests/config_declarations/config_declarations.exp b/tests/config_declarations/config_declarations.exp index 8613ac67069..a70b832445c 100644 --- a/tests/config_declarations/config_declarations.exp +++ b/tests/config_declarations/config_declarations.exp @@ -20,5 +20,13 @@ Unused suppression comment. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +Warning ------------------------------------------------------------------------------------------------------- B.js:1:1 -Found 1 error and 1 warning +Unused suppression comment. + + 1| // $FlowFixMe + ^^^^^^^^^^^^^ + + + +Found 1 error and 2 warnings