From 0dbeb774ba9ea618ff1e92b63ab31e5caf3003dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Mon, 13 Sep 2021 20:19:10 +0200 Subject: feat(fmt): add support for configuration file (#11944) This commit adds support for configuration file for "deno fmt" subcommand. It is also respected by LSP when formatting files. Example configuration: { "fmt": { "files": { "include": ["src/"], "exclude": ["src/testdata/"] }, "options": { "useTabs": true, "lineWidth": 80, "indentWidth": 4, "singleQuote": true, "textWrap": "preserve" } } } --- cli/flags.rs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'cli/flags.rs') diff --git a/cli/flags.rs b/cli/flags.rs index b35b7bad7..eb7d0901f 100644 --- a/cli/flags.rs +++ b/cli/flags.rs @@ -815,6 +815,7 @@ Ignore formatting a file by adding an ignore comment at the top of the file: // deno-fmt-ignore-file", ) + .arg(config_arg()) .arg( Arg::with_name("check") .long("check") @@ -1732,6 +1733,7 @@ fn eval_parse(flags: &mut Flags, matches: &clap::ArgMatches) { } fn fmt_parse(flags: &mut Flags, matches: &clap::ArgMatches) { + config_arg_parse(flags, matches); flags.watch = matches.is_present("watch"); let files = match matches.values_of("files") { Some(f) => f.map(PathBuf::from).collect(), @@ -2534,6 +2536,44 @@ mod tests { ..Flags::default() } ); + + let r = flags_from_vec(svec!["deno", "fmt", "--config", "deno.jsonc"]); + assert_eq!( + r.unwrap(), + Flags { + subcommand: DenoSubcommand::Fmt(FmtFlags { + ignore: vec![], + check: false, + files: vec![], + ext: "ts".to_string() + }), + config_path: Some("deno.jsonc".to_string()), + ..Flags::default() + } + ); + + let r = flags_from_vec(svec![ + "deno", + "fmt", + "--config", + "deno.jsonc", + "--watch", + "foo.ts" + ]); + assert_eq!( + r.unwrap(), + Flags { + subcommand: DenoSubcommand::Fmt(FmtFlags { + ignore: vec![], + check: false, + files: vec![PathBuf::from("foo.ts")], + ext: "ts".to_string() + }), + config_path: Some("deno.jsonc".to_string()), + watch: true, + ..Flags::default() + } + ); } #[test] -- cgit v1.2.3