Skip to content

Commit bad9530

Browse files
Handle directory ignore paths and --respect-ignores (#852)
1 parent bc3ce88 commit bad9530

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2323
- The CLI tool will now only write files if the contents differ, and not modify if no change ([#827](https://github.com/JohnnyMorganz/StyLua/issues/827))
2424
- Fixed parentheses around a Luau compound type inside of a type table indexer being removed causing a syntax error ([#828](https://github.com/JohnnyMorganz/StyLua/issues/828))
2525
- Fixed function body parentheses being placed on multiple lines unnecessarily when there are no parameters ([#830](https://github.com/JohnnyMorganz/StyLua/issues/830))
26+
- Fixed directory paths w/o globs in `.styluaignore` not matching when using `--respect-ignores` ([#845](https://github.com/JohnnyMorganz/StyLua/issues/845))
2627

2728
## [0.19.1] - 2023-11-15
2829

src/cli/main.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ fn path_is_stylua_ignored(path: &Path, search_parent_directories: bool) -> Resul
262262
.context("failed to parse ignore file")?;
263263

264264
Ok(matches!(
265-
ignore.matched(path, false),
265+
ignore.matched_path_or_any_parents(path, false),
266266
ignore::Match::Ignore(_)
267267
))
268268
}
@@ -769,4 +769,21 @@ mod tests {
769769

770770
cwd.close().unwrap();
771771
}
772+
773+
#[test]
774+
fn test_respect_ignores_directory_no_glob() {
775+
// https://github.com/JohnnyMorganz/StyLua/issues/845
776+
let cwd = construct_tree!({
777+
".styluaignore": "build/",
778+
"build/foo.lua": "local x = 1",
779+
});
780+
781+
let mut cmd = create_stylua();
782+
cmd.current_dir(cwd.path())
783+
.args(["--check", "--respect-ignores", "build/foo.lua"])
784+
.assert()
785+
.success();
786+
787+
cwd.close().unwrap();
788+
}
772789
}

0 commit comments

Comments
 (0)