mirror of
https://github.com/roc-lang/roc.git
synced 2024-09-21 15:59:20 +03:00
parent
dca9404772
commit
3e368a64ff
@ -1,4 +1,5 @@
|
||||
use std::path::PathBuf;
|
||||
use std::ffi::OsStr;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use crate::FormatMode;
|
||||
use bumpalo::collections::Vec;
|
||||
@ -39,7 +40,7 @@ fn flatten_directories(files: std::vec::Vec<PathBuf>) -> std::vec::Vec<PathBuf>
|
||||
let file_path = file.path();
|
||||
if file_path.is_dir() {
|
||||
to_flatten.push(file_path);
|
||||
} else if file_path.ends_with(".roc") {
|
||||
} else if is_roc_file(&file_path) {
|
||||
files.push(file_path);
|
||||
}
|
||||
}
|
||||
@ -57,14 +58,19 @@ fn flatten_directories(files: std::vec::Vec<PathBuf>) -> std::vec::Vec<PathBuf>
|
||||
error
|
||||
),
|
||||
}
|
||||
} else {
|
||||
files.push(path)
|
||||
} else if is_roc_file(&path) {
|
||||
files.push(path);
|
||||
}
|
||||
}
|
||||
|
||||
files
|
||||
}
|
||||
|
||||
fn is_roc_file(path: &Path) -> bool {
|
||||
let ext = path.extension().and_then(OsStr::to_str);
|
||||
return matches!(ext, Some("roc"));
|
||||
}
|
||||
|
||||
pub fn format(files: std::vec::Vec<PathBuf>, mode: FormatMode) -> Result<(), String> {
|
||||
let files = flatten_directories(files);
|
||||
|
||||
|
@ -73,7 +73,6 @@ mod cli_run {
|
||||
fn check_format_check_as_expected(file: &Path, expects_success_exit_code: bool) {
|
||||
let flags = &["--check"];
|
||||
let out = run_roc(&[&["format", file.to_str().unwrap()], &flags[..]].concat());
|
||||
|
||||
if expects_success_exit_code {
|
||||
assert!(out.status.success());
|
||||
} else {
|
||||
@ -940,7 +939,7 @@ mod cli_run {
|
||||
// This fails, because "NotFormatted.roc" is present in this folder
|
||||
check_format_check_as_expected(&fixtures_dir("format"), false);
|
||||
|
||||
// This doesn't fail, since only "Formatted.roc" is present in this folder
|
||||
// This doesn't fail, since only "Formatted.roc" and non-roc files are present in this folder
|
||||
check_format_check_as_expected(&fixtures_dir("format/formatted_directory"), true);
|
||||
}
|
||||
}
|
||||
|
1
cli/tests/fixtures/format/NotARocFile.txt
vendored
Normal file
1
cli/tests/fixtures/format/NotARocFile.txt
vendored
Normal file
@ -0,0 +1 @@
|
||||
This is not a .roc file, and should be ignored by the formatter.
|
1
cli/tests/fixtures/format/formatted_directory/NestedNotARocFile.txt
vendored
Normal file
1
cli/tests/fixtures/format/formatted_directory/NestedNotARocFile.txt
vendored
Normal file
@ -0,0 +1 @@
|
||||
This is not a .roc file, and should be ignored by the formatter.
|
3
cli/tests/fixtures/format/formatted_directory/NotARocFile
vendored
Normal file
3
cli/tests/fixtures/format/formatted_directory/NotARocFile
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
This is not a .roc file, and should be ignored by the formatter.
|
||||
|
||||
This file does not have an extension, to ensure the formatter does not simply test with `ends_with(".roc")`
|
1
cli/tests/fixtures/format/formatted_directory/ignored/NotARocFile.txt
vendored
Normal file
1
cli/tests/fixtures/format/formatted_directory/ignored/NotARocFile.txt
vendored
Normal file
@ -0,0 +1 @@
|
||||
This is not a .roc file, and should be ignored by the formatter.
|
Loading…
Reference in New Issue
Block a user