Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/commands/serverCommands.ml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ module OptionParser(Config : CONFIG) = struct
~doc:"Do not include embedded declarations"
|> flag "--log-file" string
~doc:"Path to log file (default: /tmp/flow/<escaped root path>.log)"
|> flag "--check-es6-files" no_arg
~doc:"Check .es6 files"
|> anon "root" (optional string) ~doc:"Root directory"
)

Expand Down Expand Up @@ -94,7 +96,7 @@ module OptionParser(Config : CONFIG) = struct

let result = ref None
let main color one_line show_all_errors json profile quiet debug verbose all
weak traces strip_root lib no_flowlib log_file root () =
weak traces strip_root lib no_flowlib log_file check_es6_files root () =
let root = CommandUtils.guess_root root in
let flowconfig = FlowConfig.get root in
let opt_module = FlowConfig.(match flowconfig.options.moduleSystem with
Expand Down Expand Up @@ -146,6 +148,7 @@ module OptionParser(Config : CONFIG) = struct
Options.opt_libs;
Options.opt_no_flowlib = no_flowlib;
Options.opt_one_line_errors = one_line;
Options.opt_check_es6_files = check_es6_files
};
()

Expand Down
5 changes: 4 additions & 1 deletion src/commands/singleCommand.ml
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,16 @@ let spec = {
~doc:"Specify a library path"
|> flag "--no-flowlib" no_arg
~doc:"Do not include embedded declarations"
|> flag "--check-es6-files" no_arg
~doc:"Check .es6 files"
|> error_flags
|> anon "root" (required string)
~doc:"Root"
)
}

let main all weak debug verbose json profile quiet module_
lib no_flowlib color one_line show_all_errors root () =
lib no_flowlib check_es6_files color one_line show_all_errors root () =
let opt_libs = match lib with
| None -> []
| Some lib -> [Path.make lib]
Expand Down Expand Up @@ -88,6 +90,7 @@ let main all weak debug verbose json profile quiet module_
Options.opt_libs;
Options.opt_no_flowlib = no_flowlib;
Options.opt_one_line_errors = one_line;
Options.opt_check_es6_files = check_es6_files
} in

if ! Sys.interactive
Expand Down
13 changes: 9 additions & 4 deletions src/common/files_js.ml
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,23 @@
open Utils
open Modes_js

let flow_extensions = [
let default_flow_extensions = [
".js" ; (* Standard JavaScript files *)
".jsx" ; (* JavaScript files with JSX *)
]

let get_flow_extensions ~check_es6_files =
if check_es6_files then ".es6" :: default_flow_extensions
else default_flow_extensions

let is_directory path = try Sys.is_directory path with Sys_error _ -> false

let is_dot_file path =
let filename = Filename.basename path in
String.length filename > 0 && filename.[0] = '.'

let is_flow_file path =
let is_flow_file ~check_es6_files path =
let flow_extensions = get_flow_extensions ~check_es6_files in
not (is_dot_file path) &&
List.exists (Filename.check_suffix path) flow_extensions &&
not (is_directory path)
Expand Down Expand Up @@ -87,14 +92,14 @@ let wanted config =
not (List.exists (match_regexp file) list) &&
not (SSet.mem file (get_lib_files ()))

let make_next_files root =
let make_next_files ~check_es6_files root =
let config = FlowConfig.get root in
let filter = wanted config in
let others = config.FlowConfig.include_stems in
let sroot = Path.to_string root in
Find.make_next_files (fun p ->
(str_starts_with p sroot || FlowConfig.is_included config p)
&& is_flow_file p
&& is_flow_file ~check_es6_files p
&& filter p
) ~others ~follow_symlinks:true root

Expand Down
8 changes: 5 additions & 3 deletions src/common/files_js.mli
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@

(* utilities for supported filenames *)

val flow_extensions: string list
val default_flow_extensions: string list

val get_flow_extensions : check_es6_files:bool -> string list

val is_directory: string -> bool

val is_flow_file: string -> bool
val is_flow_file: check_es6_files:bool -> string -> bool

(* name of library directory defining builtins *)
val init: Path.t list -> unit
Expand All @@ -37,7 +39,7 @@ val parent_dir_name: Str.regexp
val wanted: FlowConfig.config -> string -> bool

(* given a root, make a next_files function for MultiWorker *)
val make_next_files: Path.t -> unit -> string list
val make_next_files: check_es6_files:bool -> Path.t -> unit -> string list

(* given a base directory and a relative path, return an absolute path *)
val normalize_path: string -> string -> string
Expand Down
2 changes: 2 additions & 0 deletions src/common/options.ml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type options = {
opt_no_flowlib: bool;
opt_module_name_mappers: (Str.regexp * string) list;
opt_one_line_errors: bool;
opt_check_es6_files: bool;
}

let color_mode opts = opts.opt_color
Expand All @@ -38,3 +39,4 @@ let log_file opts = opts.opt_log_file
let root opts = opts.opt_root
let should_detach opts = opts.opt_should_detach
let show_all_errors opts = opts.opt_show_all_errors
let check_es6_files opts = opts.opt_check_es6_files
4 changes: 3 additions & 1 deletion src/server/server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -439,9 +439,11 @@ struct
the root, or an include path. *)
let process_updates genv env updates =
let root = Options.root (genv.ServerEnv.options) in
let check_es6_files =
Options.check_es6_files (genv.ServerEnv.options) in
let is_flow_file =
let config_path = FlowConfig.fullpath root in
fun f -> Files_js.is_flow_file f || f = config_path
fun f -> Files_js.is_flow_file ~check_es6_files f || f = config_path
in
let config = FlowConfig.get root in
let sroot = Path.to_string root in
Expand Down
16 changes: 13 additions & 3 deletions src/typing/module_js.ml
Original file line number Diff line number Diff line change
Expand Up @@ -262,26 +262,36 @@ module Node = struct
| None -> None
| Some file ->
let path = Files_js.normalize_path dir file in
let check_es6_files =
match !flow_options with
| Some opts -> Options.check_es6_files opts
| None -> false
in
if path_is_file path
then Some path
else seq
(fun () ->
seqf
(fun ext -> path_if_exists (path ^ ext))
Files_js.flow_extensions)
(Files_js.get_flow_extensions ~check_es6_files))
(fun () ->
let path = Filename.concat path "index.js" in
path_if_exists path)

let resolve_relative root_path rel_path =
let path = Files_js.normalize_path root_path rel_path in
if Files_js.is_flow_file path
let check_es6_files =
match !flow_options with
| Some opts -> Options.check_es6_files opts
| None -> false
in
if Files_js.is_flow_file ~check_es6_files path
then path_if_exists path
else seq
(fun () ->
seqf
(fun ext -> path_if_exists (path ^ ext))
Files_js.flow_extensions
(Files_js.get_flow_extensions ~check_es6_files)
)
(fun () -> seq
(fun () ->
Expand Down
7 changes: 5 additions & 2 deletions src/typing/types_js.ml
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,7 @@ let print_errors ?root options =
let server_init genv env =
let options = genv.ServerEnv.options in
let root = Options.root options in
let check_es6_files = Options.check_es6_files options in

Files_js.package_json root |> List.iter (fun package ->
let errors = Module_js.add_package package in
Expand All @@ -750,7 +751,7 @@ let server_init genv env =
save_errors_or_suppressions infer_errors [package] [error]
);

let get_next = Files_js.make_next_files root in
let get_next = Files_js.make_next_files ~check_es6_files root in
let (parsed, checked) =
full_check genv.ServerEnv.workers get_next options in

Expand Down Expand Up @@ -779,6 +780,8 @@ let server_init genv env =
* parses and checks serially, prints errs to stdout.
*)
let single_main (paths : string list) options =
let get_next = Files_js.make_next_files (Path.make (List.hd paths)) in
let check_es6_files = Options.check_es6_files options in
let get_next =
Files_js.make_next_files ~check_es6_files (Path.make (List.hd paths)) in
let _ = full_check None get_next options in
print_errors options