diff options
author | Satya Rohith <me@satyarohith.com> | 2021-02-18 22:01:32 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-18 17:31:32 +0100 |
commit | d9b1f96897239bf7de8cdfd11d40e3f99bb29a4a (patch) | |
tree | 4a1c60d4850111f738b485bbad5f43659bd9ed09 /cli/fs_util.rs | |
parent | c0f10e72ee64f1512e6aff20a841f4696e774217 (diff) |
feat: add json(c) support to deno fmt (#9292)
This commit adds support for formatting JSON and JSONC
in "deno fmt".
New values "json" and "jsonc" are added to "--ext" flag for
standard input processing.
Diffstat (limited to 'cli/fs_util.rs')
-rw-r--r-- | cli/fs_util.rs | 44 |
1 files changed, 26 insertions, 18 deletions
diff --git a/cli/fs_util.rs b/cli/fs_util.rs index a6cd06e78..04cdfff75 100644 --- a/cli/fs_util.rs +++ b/cli/fs_util.rs @@ -97,10 +97,14 @@ pub fn is_supported_ext(path: &Path) -> bool { } } -/// This function is similar to is_supported_ext but also allows .md extension. -pub fn is_supported_ext_md(path: &Path) -> bool { +/// This function is similar to is_supported_ext but adds additional extensions +/// supported by `deno fmt`. +pub fn is_supported_ext_fmt(path: &Path) -> bool { if let Some(ext) = get_extension(path) { - matches!(ext.as_str(), "ts" | "tsx" | "js" | "jsx" | "mjs" | "md") + matches!( + ext.as_str(), + "ts" | "tsx" | "js" | "jsx" | "mjs" | "md" | "json" | "jsonc" + ) } else { false } @@ -221,21 +225,25 @@ mod tests { } #[test] - fn test_is_supported_ext_md() { - assert!(!is_supported_ext_md(Path::new("tests/subdir/redirects"))); - assert!(is_supported_ext_md(Path::new("README.md"))); - assert!(is_supported_ext_md(Path::new("readme.MD"))); - assert!(is_supported_ext_md(Path::new("lib/typescript.d.ts"))); - assert!(is_supported_ext_md(Path::new("cli/tests/001_hello.js"))); - assert!(is_supported_ext_md(Path::new("cli/tests/002_hello.ts"))); - assert!(is_supported_ext_md(Path::new("foo.jsx"))); - assert!(is_supported_ext_md(Path::new("foo.tsx"))); - assert!(is_supported_ext_md(Path::new("foo.TS"))); - assert!(is_supported_ext_md(Path::new("foo.TSX"))); - assert!(is_supported_ext_md(Path::new("foo.JS"))); - assert!(is_supported_ext_md(Path::new("foo.JSX"))); - assert!(is_supported_ext_md(Path::new("foo.mjs"))); - assert!(!is_supported_ext_md(Path::new("foo.mjsx"))); + fn test_is_supported_ext_fmt() { + assert!(!is_supported_ext_fmt(Path::new("tests/subdir/redirects"))); + assert!(is_supported_ext_fmt(Path::new("README.md"))); + assert!(is_supported_ext_fmt(Path::new("readme.MD"))); + assert!(is_supported_ext_fmt(Path::new("lib/typescript.d.ts"))); + assert!(is_supported_ext_fmt(Path::new("cli/tests/001_hello.js"))); + assert!(is_supported_ext_fmt(Path::new("cli/tests/002_hello.ts"))); + assert!(is_supported_ext_fmt(Path::new("foo.jsx"))); + assert!(is_supported_ext_fmt(Path::new("foo.tsx"))); + assert!(is_supported_ext_fmt(Path::new("foo.TS"))); + assert!(is_supported_ext_fmt(Path::new("foo.TSX"))); + assert!(is_supported_ext_fmt(Path::new("foo.JS"))); + assert!(is_supported_ext_fmt(Path::new("foo.JSX"))); + assert!(is_supported_ext_fmt(Path::new("foo.mjs"))); + assert!(!is_supported_ext_fmt(Path::new("foo.mjsx"))); + assert!(is_supported_ext_fmt(Path::new("foo.jsonc"))); + assert!(is_supported_ext_fmt(Path::new("foo.JSONC"))); + assert!(is_supported_ext_fmt(Path::new("foo.json"))); + assert!(is_supported_ext_fmt(Path::new("foo.JsON"))); } #[test] |