Skip to content

Commit

Permalink
refactor(declarations): rename [declarations] to [silence]
Browse files Browse the repository at this point in the history
This name has not gone over well:
#6631 (comment)

and is confusing in multiple places, such as:
https://github.com/facebook/flow/blob/master/website/en/docs/declarations/index.md
and
https://github.com/facebook/flow/blob/dd93de0a3796897fe07cca8a3bdc621c992a9880/tests/lib_interfaces/.flowconfig#L5-L6

It is difficult to grep for, difficult to distinguish versus type declarations,
and is widely used interchangeably with "interfaces".

For these reasons and many more, it is best to rename this option now that it
is usable.
  • Loading branch information
STRML committed Sep 27, 2019
1 parent a0aa29e commit a2e11e1
Show file tree
Hide file tree
Showing 30 changed files with 65 additions and 65 deletions.
24 changes: 12 additions & 12 deletions src/commands/commandUtils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ let assert_version flowconfig =
type flowconfig_params = {
ignores: string list;
untyped: string list;
declarations: string list;
silence: string list;
includes: string list;
libs: string list;
(* We store raw_lint_severities as a string list instead of as a LintSettings.t so we
Expand All @@ -543,14 +543,14 @@ let list_of_string_arg = function
| Some arg_str -> Str.split (Str.regexp ",") arg_str

let collect_flowconfig_flags
main ignores_str untyped_str declarations_str includes_str lib_str lints_str =
main ignores_str untyped_str silence_str includes_str lib_str lints_str =
let ignores = list_of_string_arg ignores_str in
let untyped = list_of_string_arg untyped_str in
let declarations = list_of_string_arg declarations_str in
let silence = list_of_string_arg silence_str in
let includes = list_of_string_arg includes_str in
let libs = list_of_string_arg lib_str in
let raw_lint_severities = list_of_string_arg lints_str in
main { ignores; includes; libs; raw_lint_severities; untyped; declarations }
main { ignores; includes; libs; raw_lint_severities; untyped; silence }

let remove_exclusion pattern =
if String_utils.string_starts_with pattern "!" then
Expand Down Expand Up @@ -635,14 +635,14 @@ let file_options =
| [] -> config_libs
| _ -> config_libs @ Core_list.map ~f:(Files.make_path_absolute root) extras
in
fun ~root ~no_flowlib ~temp_dir ~includes ~ignores ~libs ~untyped ~declarations flowconfig ->
fun ~root ~no_flowlib ~temp_dir ~includes ~ignores ~libs ~untyped ~silence flowconfig ->
let default_lib_dir =
let no_flowlib = no_flowlib || FlowConfig.no_flowlib flowconfig in
Some (default_lib_dir ~no_flowlib temp_dir)
in
let ignores = ignores_of_arg root (FlowConfig.ignores flowconfig) ignores in
let untyped = ignores_of_arg root (FlowConfig.untyped flowconfig) untyped in
let declarations = ignores_of_arg root (FlowConfig.declarations flowconfig) declarations in
let silence = ignores_of_arg root (FlowConfig.silence flowconfig) silence in
let lib_paths = lib_paths ~root flowconfig libs in
let includes =
includes
Expand All @@ -653,7 +653,7 @@ let file_options =
Files.default_lib_dir;
ignores;
untyped;
declarations;
silence;
includes;
lib_paths;
module_file_exts = FlowConfig.module_file_exts flowconfig;
Expand Down Expand Up @@ -681,9 +681,9 @@ let declaration_flag prev =
CommandSpec.ArgSpec.(
prev
|> flag
"--declaration"
"--silence"
(optional string)
~doc:"Specify one or more patterns, comma separated, for files to treat as declarations")
~doc:"Specify one or more patterns, comma separated, for files to silence errors for")

let include_flag prev =
CommandSpec.ArgSpec.(
Expand Down Expand Up @@ -949,7 +949,7 @@ let options_flags =
no_arg
~doc:"Typecheck with weak inference, assuming dynamic types by default"
|> flag "--traces" (optional int) ~doc:"Outline an error path up to a specified level"
|> flag "--no-flowlib" no_arg ~doc:"Do not include embedded declarations"
|> flag "--no-flowlib" no_arg ~doc:"Do not include embedded silence"
|> flag
"--munge-underscore-members"
no_arg
Expand Down Expand Up @@ -1148,7 +1148,7 @@ let make_options ~flowconfig_name ~flowconfig ~lazy_mode ~root (options_flags :
Options_flags.(
let file_options =
let no_flowlib = options_flags.no_flowlib in
let { includes; ignores; libs; raw_lint_severities = _; untyped; declarations } =
let { includes; ignores; libs; raw_lint_severities = _; untyped; silence } =
options_flags.flowconfig_flags
in
file_options
Expand All @@ -1159,7 +1159,7 @@ let make_options ~flowconfig_name ~flowconfig ~lazy_mode ~root (options_flags :
~ignores
~libs
~untyped
~declarations
~silence
flowconfig
in
let lint_severities =
Expand Down
26 changes: 13 additions & 13 deletions src/commands/config/flowConfig.ml
Original file line number Diff line number Diff line change
Expand Up @@ -600,8 +600,8 @@ type config = {
ignores: string list;
(* files that should be treated as untyped *)
untyped: string list;
(* files that should be treated as declarations *)
declarations: string list;
(* files that should be treated as silent *)
silence: string list;
(* non-root include paths *)
includes: string list;
(* library paths. no wildcards *)
Expand All @@ -627,7 +627,7 @@ end = struct

let untyped o = Core_list.iter ~f:(fprintf o "%s\n")

let declarations o = Core_list.iter ~f:(fprintf o "%s\n")
let silence o = Core_list.iter ~f:(fprintf o "%s\n")

let includes o = Core_list.iter ~f:(fprintf o "%s\n")

Expand Down Expand Up @@ -680,7 +680,7 @@ end = struct
ignores o config.ignores;
fprintf o "\n";
section_if_nonempty o "untyped" untyped config.untyped;
section_if_nonempty o "declarations" declarations config.declarations;
section_if_nonempty o "silence" silence config.silence;
section_header o "include";
includes o config.includes;
fprintf o "\n";
Expand All @@ -702,7 +702,7 @@ let empty_config =
rollouts = SMap.empty;
ignores = [];
untyped = [];
declarations = [];
silence = [];
includes = [];
libs = [];
lint_severities = LintSettings.empty_severities;
Expand Down Expand Up @@ -765,8 +765,8 @@ let parse_untyped lines config =
Ok ({ config with untyped }, [])

let parse_declarations lines config =
let declarations = trim_lines lines in
Ok ({ config with declarations }, [])
let silence = trim_lines lines in
Ok ({ config with silence }, [])

let parse_options lines config : (config * warning list, error) result =
Opts.parse config.options lines
Expand Down Expand Up @@ -910,7 +910,7 @@ let parse_section config ((section_ln, section), lines) : (config * warning list
| ("ignore", _) -> parse_ignores lines config
| ("libs", _) -> parse_libs lines config
| ("lints", _) -> parse_lints lines config
| ("declarations", _) -> parse_declarations lines config
| ("silence", _) -> parse_declarations lines config
| ("strict", _) -> parse_strict lines config
| ("options", _) -> parse_options lines config
| ("untyped", _) -> parse_untyped lines config
Expand Down Expand Up @@ -983,7 +983,7 @@ let is_not_comment =
(* Line starts with ; *)
Str.regexp_string "\240\159\146\169";
(* Line starts with poop emoji *)

]
in
fun (_, line) ->
Expand Down Expand Up @@ -1013,7 +1013,7 @@ let get_empty_config () =
in
{ empty_config with lint_severities }

let init ~ignores ~untyped ~declarations ~includes ~libs ~options ~lints =
let init ~ignores ~untyped ~silence ~includes ~libs ~options ~lints =
let ( >>= )
(acc : (config * warning list, error) result)
(fn : config -> (config * warning list, error) result) =
Expand All @@ -1024,7 +1024,7 @@ let init ~ignores ~untyped ~declarations ~includes ~libs ~options ~lints =
in
let ignores_lines = Core_list.map ~f:(fun s -> (1, s)) ignores in
let untyped_lines = Core_list.map ~f:(fun s -> (1, s)) untyped in
let declarations_lines = Core_list.map ~f:(fun s -> (1, s)) declarations in
let declarations_lines = Core_list.map ~f:(fun s -> (1, s)) silence in
let includes_lines = Core_list.map ~f:(fun s -> (1, s)) includes in
let options_lines = Core_list.map ~f:(fun s -> (1, s)) options in
let lib_lines = Core_list.map ~f:(fun s -> (1, s)) libs in
Expand Down Expand Up @@ -1073,8 +1073,8 @@ let ignores config = config.ignores
(* files that should be treated as untyped *)
let untyped config = config.untyped

(* files that should be treated as declarations *)
let declarations config = config.declarations
(* files that should be treated as silenct *)
let silence config = config.silence

(* non-root include paths *)
let includes config = config.includes
Expand Down
6 changes: 3 additions & 3 deletions src/commands/config/flowConfig.mli
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ val empty_config : config
val init :
ignores:string list ->
untyped:string list ->
declarations:string list ->
silence:string list ->
includes:string list ->
libs:string list ->
options:string list ->
Expand All @@ -37,8 +37,8 @@ val ignores : config -> string list
(* files that should be treated as untyped *)
val untyped : config -> string list

(* files that should be treated as declarations *)
val declarations : config -> string list
(* files that should be treated as silence *)
val silence : config -> string list

(* non-root include paths *)
val includes : config -> string list
Expand Down
4 changes: 2 additions & 2 deletions src/commands/initCommand.ml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ let main base_flags flowconfig_flags options root () =
in
let ignores = flowconfig_flags.CommandUtils.ignores in
let untyped = flowconfig_flags.CommandUtils.untyped in
let declarations = flowconfig_flags.CommandUtils.declarations in
let silence = flowconfig_flags.CommandUtils.silence in
let includes = flowconfig_flags.CommandUtils.includes in
let libs = flowconfig_flags.CommandUtils.libs in
let lints = flowconfig_flags.CommandUtils.raw_lint_severities in
Expand All @@ -62,7 +62,7 @@ let main base_flags flowconfig_flags options root () =
let msg = Utils_js.spf "Error: \"%s\" already exists!\n%!" file in
FlowExitStatus.(exit ~msg Invalid_flowconfig) );

let config = FlowConfig.init ~ignores ~untyped ~declarations ~includes ~libs ~options ~lints in
let config = FlowConfig.init ~ignores ~untyped ~silence ~includes ~libs ~options ~lints in
let config =
match config with
| Ok (config, []) -> config
Expand Down
4 changes: 2 additions & 2 deletions src/commands/lsCommand.ml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ let make_options ~flowconfig_name ~root ~ignore_flag ~include_flag ~untyped_flag
let includes = CommandUtils.list_of_string_arg include_flag in
let ignores = CommandUtils.list_of_string_arg ignore_flag in
let untyped = CommandUtils.list_of_string_arg untyped_flag in
let declarations = CommandUtils.list_of_string_arg declaration_flag in
let silence = CommandUtils.list_of_string_arg declaration_flag in
let libs = [] in
CommandUtils.file_options
flowconfig
Expand All @@ -132,7 +132,7 @@ let make_options ~flowconfig_name ~root ~ignore_flag ~include_flag ~untyped_flag
~includes
~libs
~untyped
~declarations
~silence

(* The problem with Files.wanted is that it says yes to everything except ignored files and libs.
* So implicitly ignored files (like files in another directory) pass the Files.wanted check *)
Expand Down
10 changes: 5 additions & 5 deletions src/common/files.ml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type options = {
default_lib_dir: Path.t option;
ignores: (string * Str.regexp) list;
untyped: (string * Str.regexp) list;
declarations: (string * Str.regexp) list;
silence: (string * Str.regexp) list;
includes: Path_matcher.t;
lib_paths: Path.t list;
module_file_exts: SSet.t;
Expand All @@ -25,7 +25,7 @@ let ignores options = options.ignores

let untyped options = options.untyped

let declarations options = options.declarations
let silence options = options.silence

let includes options = options.includes

Expand Down Expand Up @@ -377,12 +377,12 @@ let is_untyped (options : options) path =
let path = Sys_utils.normalize_filename_dir_sep path in
is_matching path options.untyped

(* true if a file path matches a [declarations] entry in config *)
let is_declaration (options : options) path =
(* true if a file path matches a [silence] entry in config *)
let is_silenced (options : options) path =
(* On Windows, the path may use \ instead of /, but let's standardize the
* ignore regex to use / *)
let path = Sys_utils.normalize_filename_dir_sep path in
is_matching path options.declarations
is_matching path options.silence

(* true if a file path matches an [include] path in config *)
let is_included options f = Path_matcher.matches options.includes f
Expand Down
8 changes: 4 additions & 4 deletions src/common/files.mli
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type options = {
default_lib_dir: Path.t option;
ignores: (string * Str.regexp) list;
untyped: (string * Str.regexp) list;
declarations: (string * Str.regexp) list;
silence: (string * Str.regexp) list;
includes: Path_matcher.t;
lib_paths: Path.t list;
module_file_exts: SSet.t;
Expand All @@ -25,7 +25,7 @@ val ignores : options -> (string * Str.regexp) list

val untyped : options -> (string * Str.regexp) list

val declarations : options -> (string * Str.regexp) list
val silence : options -> (string * Str.regexp) list

val includes : options -> Path_matcher.t

Expand Down Expand Up @@ -57,8 +57,8 @@ val is_ignored : options -> string -> bool
(* true if a file path matches an [untyped] entry in config *)
val is_untyped : options -> string -> bool

(* true if a file path matches a [declarations] entry in config *)
val is_declaration : options -> string -> bool
(* true if a file path matches a [silence] entry in config *)
val is_silenced : options -> string -> bool

(* true if a file path matches an [include] path in config *)
val is_included : options -> string -> bool
Expand Down
2 changes: 1 addition & 1 deletion src/services/inference/__tests__/types_js_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ let dummy_flowconfig_params =
{
CommandUtils.ignores = [];
untyped = [];
declarations = [];
silence = [];
includes = [];
libs = [];
raw_lint_severities = [];
Expand Down
8 changes: 4 additions & 4 deletions src/typing/errors/error_suppressions.ml
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,10 @@ let in_node_modules ~root ~file_options loc =
| None -> false
| Some (file, options) -> Files.is_within_node_modules ~root ~options (File_key.to_string file)

let in_declarations ~file_options loc =
let in_silence ~file_options loc =
match Option.both (Loc.source loc) file_options with
| None -> false
| Some (file, options) -> Files.is_declaration options (File_key.to_string file)
| Some (file, options) -> Files.is_silenced options (File_key.to_string file)

let check ~root ~file_options (err : Loc.t Errors.printable_error) (suppressions : t) (unused : t)
=
Expand All @@ -181,11 +181,11 @@ let check ~root ~file_options (err : Loc.t Errors.printable_error) (suppressions
* without a source. *)
|> List.filter (fun loc -> Option.is_some (Loc.source loc))
in
(* Ignore lint errors from node modules, and all errors from declarations directories. *)
(* Ignore lint errors from node modules, and all errors from [silence] directories. *)
let ignore =
match Errors.kind_of_printable_error err with
| Errors.LintError _ -> in_node_modules ~root ~file_options (Errors.loc_of_printable_error err)
| _ -> in_declarations ~file_options (Errors.loc_of_printable_error err)
| _ -> in_silence ~file_options (Errors.loc_of_printable_error err)
in
if ignore then
None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[libs]
lib.js

[declarations]
[silence]
.*/B.js
.*/C.js

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

[libs]

[declarations]
[silence]
<PROJECT_ROOT>/node_modules/react-native/.*

[options]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Due to [declarations], this won't error
// Due to [silence], this won't error
const str2str = require('react-native/str2str')

// But this identical one will
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/flowconfig_ignore/.flowconfig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[declarations]
[silence]
.*/my_declarations/.*
!.*/my_declarations/typecheck/.*
!.*/my_declarations/actually_typecheck\.js
Expand Down
Loading

0 comments on commit a2e11e1

Please sign in to comment.