From c5442abc237b8e11491afb09dbaa80a66488fc7b Mon Sep 17 00:00:00 2001 From: Satya Rohith Date: Thu, 23 Sep 2021 21:49:25 +0530 Subject: feat(cli/fmt): support more markdown extensions (#12195) --- cli/fs_util.rs | 39 ++++++++++++++++++++-- cli/tests/integration/fmt_tests.rs | 2 +- cli/tests/testdata/fmt/regular/formatted3.markdown | 17 ++++++++++ cli/tests/testdata/fmt/regular/formatted3.md | 17 ---------- cli/tools/fmt.rs | 5 ++- 5 files changed, 59 insertions(+), 21 deletions(-) create mode 100644 cli/tests/testdata/fmt/regular/formatted3.markdown delete mode 100644 cli/tests/testdata/fmt/regular/formatted3.md (limited to 'cli') diff --git a/cli/fs_util.rs b/cli/fs_util.rs index 446c16f27..86dfb5b10 100644 --- a/cli/fs_util.rs +++ b/cli/fs_util.rs @@ -106,7 +106,19 @@ 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" | "json" | "jsonc" + "ts" + | "tsx" + | "js" + | "jsx" + | "mjs" + | "json" + | "jsonc" + | "md" + | "mkd" + | "mkdn" + | "mdwn" + | "mdown" + | "markdown" ) } else { false @@ -143,7 +155,20 @@ pub fn is_supported_test_path(path: &Path) -> bool { /// Checks if the path has an extension Deno supports for tests. pub fn is_supported_test_ext(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" + | "mkd" + | "mkdn" + | "mdwn" + | "mdown" + | "markdown" + ) } else { false } @@ -320,6 +345,11 @@ mod tests { 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("readme.mkd"))); + assert!(is_supported_ext_fmt(Path::new("readme.mkdn"))); + assert!(is_supported_ext_fmt(Path::new("readme.mdwn"))); + assert!(is_supported_ext_fmt(Path::new("readme.mdown"))); + assert!(is_supported_ext_fmt(Path::new("readme.markdown"))); assert!(is_supported_ext_fmt(Path::new("lib/typescript.d.ts"))); assert!(is_supported_ext_fmt(Path::new("testdata/001_hello.js"))); assert!(is_supported_ext_fmt(Path::new("testdata/002_hello.ts"))); @@ -342,6 +372,11 @@ mod tests { assert!(!is_supported_test_ext(Path::new("tests/subdir/redirects"))); assert!(is_supported_test_ext(Path::new("README.md"))); assert!(is_supported_test_ext(Path::new("readme.MD"))); + assert!(is_supported_ext_fmt(Path::new("readme.mkd"))); + assert!(is_supported_ext_fmt(Path::new("readme.mkdn"))); + assert!(is_supported_ext_fmt(Path::new("readme.mdwn"))); + assert!(is_supported_ext_fmt(Path::new("readme.mdown"))); + assert!(is_supported_ext_fmt(Path::new("readme.markdown"))); assert!(is_supported_test_ext(Path::new("lib/typescript.d.ts"))); assert!(is_supported_test_ext(Path::new("testdata/001_hello.js"))); assert!(is_supported_test_ext(Path::new("testdata/002_hello.ts"))); diff --git a/cli/tests/integration/fmt_tests.rs b/cli/tests/integration/fmt_tests.rs index 2d7451694..1adbc8ff8 100644 --- a/cli/tests/integration/fmt_tests.rs +++ b/cli/tests/integration/fmt_tests.rs @@ -141,7 +141,7 @@ itest!(fmt_quiet_check_fmt_dir { }); itest!(fmt_check_formatted_files { - args: "fmt --check fmt/regular/formatted1.js fmt/regular/formatted2.ts fmt/regular/formatted3.md fmt/regular/formatted4.jsonc", + args: "fmt --check fmt/regular/formatted1.js fmt/regular/formatted2.ts fmt/regular/formatted3.markdown fmt/regular/formatted4.jsonc", output: "fmt/expected_fmt_check_formatted_files.out", exit_code: 0, }); diff --git a/cli/tests/testdata/fmt/regular/formatted3.markdown b/cli/tests/testdata/fmt/regular/formatted3.markdown new file mode 100644 index 000000000..e6e616584 --- /dev/null +++ b/cli/tests/testdata/fmt/regular/formatted3.markdown @@ -0,0 +1,17 @@ +# Hello + +```js +function foo() { + return 42; +} + +foo(); +``` + +```ts +function bar(): number { + return 42; +} + +bar(); +``` diff --git a/cli/tests/testdata/fmt/regular/formatted3.md b/cli/tests/testdata/fmt/regular/formatted3.md deleted file mode 100644 index e6e616584..000000000 --- a/cli/tests/testdata/fmt/regular/formatted3.md +++ /dev/null @@ -1,17 +0,0 @@ -# Hello - -```js -function foo() { - return 42; -} - -foo(); -``` - -```ts -function bar(): number { - return 42; -} - -bar(); -``` diff --git a/cli/tools/fmt.rs b/cli/tools/fmt.rs index 6758d7b8b..5d33240a5 100644 --- a/cli/tools/fmt.rs +++ b/cli/tools/fmt.rs @@ -206,7 +206,10 @@ pub fn format_file( fmt_options: FmtOptionsConfig, ) -> Result { let ext = get_extension(file_path).unwrap_or_else(String::new); - if ext == "md" { + if matches!( + ext.as_str(), + "md" | "mkd" | "mkdn" | "mdwn" | "mdown" | "markdown" + ) { format_markdown(file_text, &fmt_options) } else if matches!(ext.as_str(), "json" | "jsonc") { format_json(file_text, &fmt_options) -- cgit v1.2.3