-
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(swift): add support for swiftformat (#105)
* feat(swift): add support for swiftformat * chore: update config schema * ci: remove update-schema --------- Co-authored-by: hougesen <[email protected]>
- Loading branch information
Showing
8 changed files
with
205 additions
and
44 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
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
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,42 @@ | ||
use super::execute_command; | ||
|
||
#[inline] | ||
pub fn format_using_swiftformat( | ||
snippet_path: &std::path::Path, | ||
) -> std::io::Result<(bool, Option<String>)> { | ||
let mut cmd = std::process::Command::new("swiftformat"); | ||
|
||
cmd.arg("--quiet").arg(snippet_path); | ||
|
||
execute_command(&mut cmd, snippet_path) | ||
} | ||
|
||
#[cfg(test)] | ||
mod test_swiftformat { | ||
use crate::{formatters::setup_snippet, languages::Language}; | ||
|
||
use super::format_using_swiftformat; | ||
|
||
#[test_with::executable(swiftformat)] | ||
#[test] | ||
fn it_should_format_swift() { | ||
let input = " func add(a:Int ,b:Int)->Int { | ||
return a + b | ||
}"; | ||
|
||
let expected_output = "func add(a: Int, b: Int) -> Int { | ||
return a + b | ||
} | ||
"; | ||
|
||
let snippet = setup_snippet(input, Language::Swift.to_file_ext()) | ||
.expect("it to create a snippet file"); | ||
|
||
let output = format_using_swiftformat(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
Oops, something went wrong.