Skip to content

Commit

Permalink
fix(declarations): remove unused suppression code
Browse files Browse the repository at this point in the history
Related to the previous commit, this backs out some of the code
in facebook#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.
  • Loading branch information
STRML committed Sep 27, 2019
1 parent 27fa53f commit a0aa29e
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 34 deletions.
2 changes: 0 additions & 2 deletions src/services/inference/init_js.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions src/services/inference/merge_service.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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))
Expand Down
2 changes: 0 additions & 2 deletions src/typing/merge_js.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down
1 change: 0 additions & 1 deletion src/typing/merge_js.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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) ->
Expand Down
28 changes: 7 additions & 21 deletions src/typing/type_inference_js.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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 ();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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.(
Expand Down
2 changes: 0 additions & 2 deletions src/typing/type_inference_js.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand All @@ -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 ->
Expand Down
1 change: 0 additions & 1 deletion testgen/flowtestgen_utils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 () =
Expand Down
10 changes: 9 additions & 1 deletion tests/config_declarations/config_declarations.exp
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit a0aa29e

Please sign in to comment.