Skip to content

Commit d942089

Browse files
SamChou19815facebook-github-bot
authored andcommitted
Do not emit redundant flowlint comments error in libdef
Summary: Library definitions don't have control over where the configuration where it is used, and it might need to use features that are considered as bad by flow lints (e.g. getters and setters). Flow currently complains about flowlint comments that do nothing, which makes the beforementioned use cases impossible to achieve. Instead of rejecting this, which is too strict, or do not emit any lint errors in libdef, which is too loose, we need to at least let the users know what they are doing and give them a way to shut Flow up, which is what's being done in this diff. Changelog: [fix] We will no longer emit redundant flowlint disable errors in library definitions. Reviewed By: williewillus Differential Revision: D46165188 fbshipit-source-id: a4c1544876fe3ef9dafb2e68dee6dbb95e5165fc
1 parent 2836f0c commit d942089

File tree

5 files changed

+17
-14
lines changed

5 files changed

+17
-14
lines changed

src/common/lints/exactCover.ml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ let update_settings =
125125
(fun range setting_list builder -> update_range range (map_fun setting_list) builder)
126126

127127
let update_settings_and_running =
128-
let update_settings_and_error err_fun settings settings_list =
128+
let update_settings_and_error ~in_libdef err_fun settings settings_list =
129129
match settings_list with
130130
| (_, (_, loc)) :: _ ->
131131
let (new_settings, all_redundant) =
@@ -139,18 +139,18 @@ let update_settings_and_running =
139139
(settings, true)
140140
settings_list
141141
in
142-
if all_redundant then err_fun (loc, LintSettings.Redundant_argument);
142+
if (not in_libdef) && all_redundant then err_fun (loc, LintSettings.Redundant_argument);
143143
new_settings
144144
| [] -> settings
145145
in
146-
let update_settings_and_error_from_list err_fun settings_list_list settings =
147-
List.fold_left (update_settings_and_error err_fun) settings settings_list_list
146+
let update_settings_and_error_from_list ~in_libdef err_fun settings_list_list settings =
147+
List.fold_left (update_settings_and_error ~in_libdef err_fun) settings settings_list_list
148148
in
149-
fun running_settings err_fun range settings_list_list builder ->
149+
fun ~in_libdef running_settings err_fun range settings_list_list builder ->
150150
let flat_settings_list = List.flatten settings_list_list in
151151
let updated_builder = update_settings range flat_settings_list builder in
152152
let updated_running_settings =
153-
update_settings_and_error_from_list err_fun settings_list_list running_settings
153+
update_settings_and_error_from_list ~in_libdef err_fun settings_list_list running_settings
154154
in
155155
(updated_builder, updated_running_settings)
156156

src/common/lints/exactCover.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ val update_settings :
9090
* anything. It doesn't check for settings that are redundant because they are
9191
* immediately overwritten. (That's done elsewhere.) *)
9292
val update_settings_and_running :
93+
in_libdef:bool ->
9394
'a LintSettings.t ->
9495
((* Running lint settings *)
9596
Loc.t * LintSettings.lint_parse_error -> unit) ->

src/services/inference/merge_service.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ let merge_component ~mutator ~options ~for_find_all_refs ~reader component =
367367
Parsing_heaps.read_ast_unsafe file parse
368368
in
369369
let (_, suppressions, _) =
370-
Type_inference_js.scan_for_suppressions file lint_severities comments
370+
Type_inference_js.scan_for_suppressions ~in_libdef:false file lint_severities comments
371371
in
372372
Error_suppressions.union suppressions acc)
373373
Error_suppressions.empty

src/typing/type_inference_js.ml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ let scan_for_lint_suppressions =
250250
{ loc = new_loc; value = s }
251251
)
252252
in
253-
let process_comment acc comment =
253+
let process_comment ~in_libdef acc comment =
254254
let (severity_cover_builder, running_settings, suppression_locs, errs) = acc in
255255
let loc_comment = comment |> convert_comment |> trim_and_stars_locational in
256256
match parse_keyword loc_comment with
@@ -262,6 +262,7 @@ let scan_for_lint_suppressions =
262262
let (new_builder, new_running_settings) =
263263
let covered_range = get_range keyword in
264264
ExactCover.update_settings_and_running
265+
~in_libdef
265266
running_settings
266267
(fun err ->
267268
error_encountered := true;
@@ -330,23 +331,23 @@ let scan_for_lint_suppressions =
330331
(severity_cover_builder, running_settings, suppression_locs, errs)
331332
| None -> acc
332333
in
333-
fun file_key base_settings acc errs comments ->
334+
fun ~in_libdef file_key base_settings acc errs comments ->
334335
let severity_cover_builder = ExactCover.new_builder file_key base_settings in
335336
let (severity_cover_builder, _, suppression_locs, errs) =
336337
List.fold_left
337-
process_comment
338+
(process_comment ~in_libdef)
338339
(severity_cover_builder, base_settings, Loc_collections.LocSet.empty, errs)
339340
comments
340341
in
341342
let severity_cover = ExactCover.bake severity_cover_builder in
342343
let acc = Error_suppressions.add_lint_suppressions suppression_locs acc in
343344
(severity_cover, acc, errs)
344345

345-
let scan_for_suppressions file_key lint_severities comments =
346+
let scan_for_suppressions ~in_libdef file_key lint_severities comments =
346347
let comments = List.sort (fun (loc1, _) (loc2, _) -> Loc.compare loc1 loc2) comments in
347348
let acc = Error_suppressions.empty in
348349
let (acc, errs) = scan_for_error_suppressions acc [] comments in
349-
scan_for_lint_suppressions file_key lint_severities acc errs comments
350+
scan_for_lint_suppressions ~in_libdef file_key lint_severities acc errs comments
350351

351352
module Statement = Fix_statement.Statement_
352353

@@ -454,7 +455,7 @@ let infer_ast ~lint_severities cx filename comments aloc_ast =
454455
let typed_statements = infer_core cx aloc_statements in
455456

456457
let (severity_cover, suppressions, suppression_errors) =
457-
scan_for_suppressions filename lint_severities comments
458+
scan_for_suppressions ~in_libdef:false filename lint_severities comments
458459
in
459460
Context.add_severity_cover cx filename severity_cover;
460461
Context.add_error_suppressions cx suppressions;
@@ -507,7 +508,7 @@ let infer_lib_file ~exclude_syms ~lint_severities ~file_sig cx ast =
507508
let t_stmts = infer_core cx aloc_statements in
508509

509510
let (severity_cover, suppressions, suppression_errors) =
510-
scan_for_suppressions (Context.file cx) lint_severities all_comments
511+
scan_for_suppressions ~in_libdef:true (Context.file cx) lint_severities all_comments
511512
in
512513
Context.add_severity_cover cx (Context.file cx) severity_cover;
513514
Context.add_error_suppressions cx suppressions;

src/typing/type_inference_js.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*)
77

88
val scan_for_suppressions :
9+
in_libdef:bool ->
910
File_key.t ->
1011
Severity.severity LintSettings.t ->
1112
Loc.t Flow_ast.Comment.t list ->

0 commit comments

Comments
 (0)