Skip to content

Commit

Permalink
[flow] remove option to disable as const syntax
Browse files Browse the repository at this point in the history
Summary:
This option has been enabled by default in the released version, so we can remove it now completely.

Changelog: [internal]

Reviewed By: SamChou19815

Differential Revision: D67149500

fbshipit-source-id: 393b3630b5dd09cf82ae7460158d6f642ddc2be6
  • Loading branch information
panagosg7 authored and facebook-github-bot committed Dec 12, 2024
1 parent f543d19 commit 8215548
Show file tree
Hide file tree
Showing 14 changed files with 4 additions and 63 deletions.
1 change: 0 additions & 1 deletion src/commands/commandUtils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1378,7 +1378,6 @@ let make_options
|> min Sys_utils.nbr_procs;
opt_suppress_types = FlowConfig.suppress_types flowconfig;
opt_max_literal_length = FlowConfig.max_literal_length flowconfig;
opt_as_const = Base.Option.value ~default:true (FlowConfig.enable_as_const flowconfig);
opt_component_syntax = FlowConfig.component_syntax flowconfig;
opt_react_rules = FlowConfig.react_rules flowconfig;
opt_hook_compatibility = FlowConfig.hook_compatibility flowconfig;
Expand Down
19 changes: 0 additions & 19 deletions src/commands/config/flowConfig.ml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ module Opts = struct
react_rules: Options.react_rules list;
dev_only_refinement_info_as_errors: bool;
emoji: bool option;
enable_as_const: bool option;
enable_const_params: bool option;
enums: bool;
estimate_recheck_time: bool option;
Expand Down Expand Up @@ -196,7 +195,6 @@ module Opts = struct
react_rules = [];
dev_only_refinement_info_as_errors = false;
emoji = None;
enable_as_const = None;
enable_const_params = None;
enums = false;
estimate_recheck_time = None;
Expand Down Expand Up @@ -414,20 +412,6 @@ module Opts = struct
]
(fun opts v -> Ok { opts with casting_syntax = Some v })

let const_assertion_parser =
boolean (fun opts v ->
match opts.casting_syntax with
| None
| Some Options.CastingSyntax.As
| Some Options.CastingSyntax.Both ->
Ok { opts with enable_as_const = Some v }
| Some Options.CastingSyntax.Colon ->
Error
("Setting \"as_const\" to true requires that \"casting_syntax\" "
^ "is set to \"as\" or \"both\"."
)
)

let channel_mode_parser ~enabled =
enum
[("pipe", `pipe); ("socket", `socket)]
Expand Down Expand Up @@ -998,7 +982,6 @@ module Opts = struct
("enums", boolean (fun opts v -> Ok { opts with enums = v }));
("estimate_recheck_time", estimate_recheck_time_parser);
("exact_by_default", boolean (fun opts v -> Ok { opts with exact_by_default = Some v }));
("as_const", const_assertion_parser);
( "experimental.const_params",
boolean (fun opts v -> Ok { opts with enable_const_params = Some v })
);
Expand Down Expand Up @@ -1707,8 +1690,6 @@ let dev_only_refinement_info_as_errors c = c.options.Opts.dev_only_refinement_in

let emoji c = c.options.Opts.emoji

let enable_as_const c = c.options.Opts.enable_as_const

let enable_const_params c = c.options.Opts.enable_const_params

let enums c = c.options.Opts.enums
Expand Down
2 changes: 0 additions & 2 deletions src/commands/config/flowConfig.mli
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ val dev_only_refinement_info_as_errors : config -> bool

val emoji : config -> bool option

val enable_as_const : config -> bool option

val enable_const_params : config -> bool option

val enums : config -> bool
Expand Down
3 changes: 0 additions & 3 deletions src/common/options.ml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ end

type t = {
opt_all: bool;
opt_as_const: bool;
opt_autoimports: bool;
opt_autoimports_min_characters: int;
opt_autoimports_ranked_by_usage: bool;
Expand Down Expand Up @@ -170,8 +169,6 @@ type t = {

let all opts = opts.opt_all

let as_const opts = opts.opt_as_const

let autoimports opts = opts.opt_autoimports

let autoimports_min_characters opts = opts.opt_autoimports_min_characters
Expand Down
1 change: 0 additions & 1 deletion src/flow_dot_js.ml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ let stub_metadata ~root ~checked =
[ValidateRefAccessDuringRender; DeepReadOnlyProps; DeepReadOnlyHookReturns; RulesOfHooks];
react_rules_always = false;
dev_only_refinement_info_as_errors = false;
enable_as_const = true;
enable_const_params = false;
enable_enums = true;
enable_jest_integration = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ let stub_metadata ~root ~checked =
react_rules = [];
react_rules_always = false;
dev_only_refinement_info_as_errors = false;
enable_as_const = false;
enable_const_params = false;
enable_enums = true;
enable_jest_integration = false;
Expand Down
1 change: 0 additions & 1 deletion src/typing/__tests__/type_hint_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ let metadata =
react_rules = [];
react_rules_always = false;
dev_only_refinement_info_as_errors = false;
enable_as_const = false;
enable_const_params = false;
enable_enums = true;
enable_jest_integration = false;
Expand Down
1 change: 0 additions & 1 deletion src/typing/__tests__/typed_ast_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ let metadata =
react_rules = [];
react_rules_always = false;
dev_only_refinement_info_as_errors = false;
enable_as_const = false;
enable_const_params = false;
enable_enums = true;
enable_jest_integration = false;
Expand Down
4 changes: 0 additions & 4 deletions src/typing/context.ml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ type metadata = {
react_rules: Options.react_rules list;
react_rules_always: bool;
dev_only_refinement_info_as_errors: bool;
enable_as_const: bool;
enable_const_params: bool;
enable_enums: bool;
enable_jest_integration: bool;
Expand Down Expand Up @@ -271,7 +270,6 @@ let metadata_of_options options =
react_rules = Options.react_rules options;
react_rules_always = false;
dev_only_refinement_info_as_errors = Options.dev_only_refinement_info_as_errors options;
enable_as_const = Options.as_const options;
enable_const_params = Options.enable_const_params options;
enable_enums = Options.enums options;
enable_jest_integration = Options.enable_jest_integration options;
Expand Down Expand Up @@ -485,8 +483,6 @@ let react_rule_enabled cx rule = List.mem rule cx.metadata.react_rules

let dev_only_refinement_info_as_errors cx = cx.metadata.dev_only_refinement_info_as_errors

let enable_as_const cx = cx.metadata.enable_as_const

let enable_const_params cx =
cx.metadata.enable_const_params || cx.metadata.strict || cx.metadata.strict_local

Expand Down
3 changes: 0 additions & 3 deletions src/typing/context.mli
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ type metadata = {
react_rules: Options.react_rules list;
react_rules_always: bool;
dev_only_refinement_info_as_errors: bool;
enable_as_const: bool;
enable_const_params: bool;
enable_enums: bool;
enable_jest_integration: bool;
Expand Down Expand Up @@ -183,8 +182,6 @@ val react_rules_always : t -> bool

val dev_only_refinement_info_as_errors : t -> bool

val enable_as_const : t -> bool

val enable_const_params : t -> bool

val enable_enums : t -> bool
Expand Down
2 changes: 0 additions & 2 deletions src/typing/errors/error_message.ml
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,6 @@ and ts_syntax_kind =
| TSTypeParamExtends
| TSReadonlyVariance
| TSInOutVariance of [ `In | `Out | `InOut ]
| TSAsConst of Options.CastingSyntax.t
| TSSatisfiesType of Options.CastingSyntax.t
| TSReadonlyType of [ `Tuple | `Array ] option

Expand Down Expand Up @@ -2805,7 +2804,6 @@ let friendly_message_of_msg = function
| TSInOutVariance `In -> Normal MessageTSVarianceIn
| TSInOutVariance `Out -> Normal MessageTSVarianceOut
| TSInOutVariance `InOut -> Normal MessageTSVarianceInOut
| TSAsConst enabled_casting_syntax -> Normal (MessageTSAsConst enabled_casting_syntax)
| TSSatisfiesType enabled_casting_syntax ->
Normal (MessageTSSatisfiesType enabled_casting_syntax)
| TSReadonlyType (Some arg_kind) ->
Expand Down
14 changes: 0 additions & 14 deletions src/typing/errors/flow_intermediate_error.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3502,20 +3502,6 @@ let to_printable_error :
text " inside object methods since these methods may be unbound and rebound.";
]
@ suggestion
| MessageTSAsConst enabled_casting_syntax ->
let (example, _) = type_casting_examples enabled_casting_syntax in
[
code "as const";
text " syntax is not enabled by default. ";
text "Try adding a type annotation instead. ";
text "You can cast an expression to a type using the form ";
code example;
text ". ";
text "Alternatively, you can enable experimental support for ";
text "the feature by setting ";
code "as_const=true";
text " in your flow config.";
]
| MessageTSKeyofType ->
[
code "keyof";
Expand Down
1 change: 0 additions & 1 deletion src/typing/errors/flow_intermediate_error_types.ml
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,6 @@ type 'loc message =
| MessageThisInComponent of 'loc
| MessageThisInExportedFunction
| MessageThisSuperInObject of 'loc virtual_reason * This_finder.kind
| MessageTSAsConst of Options.CastingSyntax.t
| MessageTSKeyofType
| MessageTSNeverType
| MessageTSParamExtends
Expand Down
14 changes: 4 additions & 10 deletions src/typing/statement.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2780,16 +2780,10 @@ module Make
(Error_message.EInvalidTypeCastSyntax { loc; enabled_casting_syntax = casting_syntax });
let t = AnyT.at (AnyError None) loc in
((loc, t), AsExpression (Tast_utils.error_mapper#as_expression cast)))
| AsConstExpression ({ AsConstExpression.expression = e; comments } as cast) ->
if Context.enable_as_const cx then (
check_const_assertion cx e;
let (((_, t), _) as e) = expression cx ~as_const:true e in
((loc, t), AsConstExpression { AsConstExpression.expression = e; comments })
) else
let kind = Error_message.TSAsConst (Context.casting_syntax cx) in
Flow_js_utils.add_output cx (Error_message.ETSSyntax { kind; loc });
let t = AnyT.at (AnyError None) loc in
((loc, t), AsConstExpression (Tast_utils.error_mapper#as_const_expression cast))
| AsConstExpression { AsConstExpression.expression = e; comments } ->
check_const_assertion cx e;
let (((_, t), _) as e) = expression cx ~as_const:true e in
((loc, t), AsConstExpression { AsConstExpression.expression = e; comments })
| TSSatisfies cast ->
Flow_js_utils.add_output
cx
Expand Down

0 comments on commit 8215548

Please sign in to comment.