mirror of
https://github.com/denoland/deno.git
synced 2024-10-29 08:58:01 -04:00
feat(cli/fmt): support more markdown extensions (#12195)
This commit is contained in:
parent
e0c858fa27
commit
c5442abc23
4 changed files with 42 additions and 4 deletions
|
@ -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")));
|
||||
|
|
|
@ -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,
|
||||
});
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue