-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for deno fmt (#66)
- Loading branch information
Showing
8 changed files
with
255 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,6 +78,10 @@ jobs: | |
- uses: crystal-lang/install-crystal@v1 | ||
# roc_format | ||
- uses: hasnep/[email protected] | ||
# deno_fmt | ||
- uses: denoland/setup-deno@v1 | ||
with: | ||
deno-version: v1.x | ||
|
||
- run: rustup toolchain install stable --profile minimal | ||
- run: rustup component add rustfmt clippy | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
use super::execute_command; | ||
|
||
#[inline] | ||
pub fn format_using_deno_fmt( | ||
snippet_path: &std::path::Path, | ||
) -> std::io::Result<(bool, Option<String>)> { | ||
// NOTE: the biome docs recommend running biome using npx, and not directly | ||
let mut cmd = std::process::Command::new("deno"); | ||
|
||
cmd.arg("fmt").arg("--quiet").arg(snippet_path); | ||
|
||
execute_command(&mut cmd, snippet_path) | ||
} | ||
|
||
#[cfg(test)] | ||
mod test_deno_fmt { | ||
use crate::{formatters::setup_snippet, languages::Language}; | ||
|
||
use super::format_using_deno_fmt; | ||
|
||
#[test] | ||
fn it_should_format_json() { | ||
let input = " | ||
{ | ||
// comments are allowed | ||
\"key\": \"value\", | ||
\"key2\": [ | ||
\"value2\", | ||
\"value3\", | ||
1 | ||
, null] | ||
} | ||
"; | ||
|
||
let expected_output = "{ | ||
// comments are allowed | ||
\"key\": \"value\", | ||
\"key2\": [ | ||
\"value2\", | ||
\"value3\", | ||
1, | ||
null | ||
] | ||
} | ||
"; | ||
|
||
let snippet = setup_snippet(input, Language::Json.to_file_ext()) | ||
.expect("it to create a snippet file"); | ||
|
||
let output = format_using_deno_fmt(snippet.path()) | ||
.expect("it to be successful") | ||
.1 | ||
.expect("it to be some"); | ||
|
||
assert_eq!(expected_output, output); | ||
} | ||
|
||
#[test] | ||
fn it_should_format_javascript() { | ||
let input = " | ||
async function asyncAddition(a,b){ | ||
return a+b | ||
} | ||
"; | ||
|
||
let expected_output = "async function asyncAddition(a, b) { | ||
return a + b; | ||
} | ||
"; | ||
|
||
let snippet = setup_snippet(input, Language::JavaScript.to_file_ext()) | ||
.expect("it to create a snippet file"); | ||
|
||
let output = format_using_deno_fmt(snippet.path()) | ||
.expect("it to be successful") | ||
.1 | ||
.expect("it to be some"); | ||
|
||
assert_eq!(expected_output, output); | ||
} | ||
|
||
#[test] | ||
fn it_should_format_typescript() { | ||
let input = " | ||
async function asyncAddition( a: \tnumber,b:number ) :Promise< number> | ||
{ | ||
return a+b | ||
} | ||
"; | ||
|
||
let expected_output = | ||
"async function asyncAddition(a: number, b: number): Promise<number> { | ||
return a + b; | ||
} | ||
"; | ||
|
||
let snippet = setup_snippet(input, Language::TypeScript.to_file_ext()) | ||
.expect("it to create a snippet file"); | ||
|
||
let output = format_using_deno_fmt(snippet.path()) | ||
.expect("it to be successful") | ||
.1 | ||
.expect("it to be some"); | ||
|
||
assert_eq!(expected_output, output); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.