diff options
author | Satya Rohith <me@satyarohith.com> | 2021-09-23 21:49:25 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-23 21:49:25 +0530 |
commit | c5442abc237b8e11491afb09dbaa80a66488fc7b (patch) | |
tree | 319a2df2095008a32bc9847c542bf1b96053473f | |
parent | e0c858fa27af07f163f5d18bb0401d0f0069dd3c (diff) |
feat(cli/fmt): support more markdown extensions (#12195)
-rw-r--r-- | cli/fs_util.rs | 39 | ||||
-rw-r--r-- | cli/tests/integration/fmt_tests.rs | 2 | ||||
-rw-r--r-- | cli/tests/testdata/fmt/regular/formatted3.markdown (renamed from cli/tests/testdata/fmt/regular/formatted3.md) | 0 | ||||
-rw-r--r-- | cli/tools/fmt.rs | 5 |
4 files changed, 42 insertions, 4 deletions
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.md b/cli/tests/testdata/fmt/regular/formatted3.markdown index e6e616584..e6e616584 100644 --- a/cli/tests/testdata/fmt/regular/formatted3.md +++ b/cli/tests/testdata/fmt/regular/formatted3.markdown 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<String, String> { 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) |