summaryrefslogtreecommitdiff
path: root/cli/flags.rs
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2021-09-13 20:19:10 +0200
committerGitHub <noreply@github.com>2021-09-13 20:19:10 +0200
commit0dbeb774ba9ea618ff1e92b63ab31e5caf3003dd (patch)
tree592244102cf046716acbb144233586c312ee7a7e /cli/flags.rs
parenta655a0f3e4201840eda94938fc8d6222c2b94a99 (diff)
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" } } }
Diffstat (limited to 'cli/flags.rs')
-rw-r--r--cli/flags.rs40
1 files changed, 40 insertions, 0 deletions
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]