Skip to content

Commit

Permalink
feat(cli/fmt): support more markdown extensions (denoland#12195)
Browse files Browse the repository at this point in the history
  • Loading branch information
satyarohith committed Sep 23, 2021
1 parent e0c858f commit c5442ab
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
39 changes: 37 additions & 2 deletions cli/fs_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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")));
Expand All @@ -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")));
Expand Down
2 changes: 1 addition & 1 deletion cli/tests/integration/fmt_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down
5 changes: 4 additions & 1 deletion cli/tools/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c5442ab

Please sign in to comment.