summaryrefslogtreecommitdiff
path: root/cli/tools/fmt.rs
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2022-06-23 01:17:49 +0200
committerGitHub <noreply@github.com>2022-06-23 01:17:49 +0200
commit1e3713c3bcd1d4c1ea49e1f49ee866380462baf2 (patch)
tree0981720f38956a3678d2128721565219841b1b01 /cli/tools/fmt.rs
parentca4385ad68810e8107984a07d625f5d8beeb50f3 (diff)
fix(fmt): ignore node_modules directory (#14943)
Diffstat (limited to 'cli/tools/fmt.rs')
-rw-r--r--cli/tools/fmt.rs33
1 files changed, 26 insertions, 7 deletions
diff --git a/cli/tools/fmt.rs b/cli/tools/fmt.rs
index 4e399bcf5..7758f29f9 100644
--- a/cli/tools/fmt.rs
+++ b/cli/tools/fmt.rs
@@ -94,8 +94,11 @@ pub async fn format(
maybe_fmt_config.map(|c| c.options).unwrap_or_default(),
);
- let fmt_predicate =
- |path: &Path| is_supported_ext_fmt(path) && !is_contain_git(path);
+ let fmt_predicate = |path: &Path| {
+ is_supported_ext_fmt(path)
+ && !contains_git(path)
+ && !contains_node_modules(path)
+ };
let resolver = |changed: Option<Vec<PathBuf>>| {
let files_changed = changed.is_some();
@@ -730,10 +733,14 @@ fn is_supported_ext_fmt(path: &Path) -> bool {
}
}
-fn is_contain_git(path: &Path) -> bool {
+fn contains_git(path: &Path) -> bool {
path.components().any(|c| c.as_os_str() == ".git")
}
+fn contains_node_modules(path: &Path) -> bool {
+ path.components().any(|c| c.as_os_str() == "node_modules")
+}
+
#[cfg(test)]
mod test {
use super::*;
@@ -767,10 +774,22 @@ mod test {
#[test]
fn test_is_located_in_git() {
- assert!(is_contain_git(Path::new("test/.git")));
- assert!(is_contain_git(Path::new(".git/bad.json")));
- assert!(is_contain_git(Path::new("test/.git/bad.json")));
- assert!(!is_contain_git(Path::new("test/bad.git/bad.json")));
+ assert!(contains_git(Path::new("test/.git")));
+ assert!(contains_git(Path::new(".git/bad.json")));
+ assert!(contains_git(Path::new("test/.git/bad.json")));
+ assert!(!contains_git(Path::new("test/bad.git/bad.json")));
+ }
+
+ #[test]
+ fn test_is_located_in_node_modules() {
+ assert!(contains_node_modules(Path::new("test/node_modules")));
+ assert!(contains_node_modules(Path::new("node_modules/bad.json")));
+ assert!(contains_node_modules(Path::new(
+ "test/node_modules/bad.json"
+ )));
+ assert!(!contains_node_modules(Path::new(
+ "test/bad.node_modules/bad.json"
+ )));
}
#[test]