diff --git a/CHANGELOG.md b/CHANGELOG.md index deca7e25..02e838a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Breaking Changes - For automated downloaders: the legacy release artifacts `stylua-win64.zip`, `stylua-linux.zip` and `stylua-macos.zip` are no longer produced in GitHub releases, in favour of more specific names (e.g., `stylua-windows-x86_64`, `stylua-linux-x86_64` and `stylua-macos-x86_64`). +- `--stdin-filepath` no longer respects ignore files by default, in line with passing files directly to the command line. Now, `stylua --stdin-filepath foo.lua -` will still format the stdin even if `foo.lua` was in a `.styluaignore` file. Use `--respect-ignores` to preserve the original behaviour. ### Added diff --git a/src/cli/main.rs b/src/cli/main.rs index f19debd6..2c96d7ce 100644 --- a/src/cli/main.rs +++ b/src/cli/main.rs @@ -418,7 +418,10 @@ fn format(opt: opt::Opt) -> Result { let opt = opt.clone(); let should_skip_format = match &opt.stdin_filepath { - Some(path) => path_is_stylua_ignored(path, opt.search_parent_directories)?, + Some(path) => { + opt.respect_ignores + && path_is_stylua_ignored(path, opt.search_parent_directories)? + } None => false, }; @@ -737,6 +740,23 @@ mod tests { cwd.close().unwrap(); } + #[test] + fn explicitly_provided_files_dont_check_ignores_stdin() { + let cwd = construct_tree!({ + ".styluaignore": "foo.lua", + }); + + let mut cmd = create_stylua(); + cmd.current_dir(cwd.path()) + .args(["--stdin-filepath", "foo.lua", "-"]) + .write_stdin("local x = 1") + .assert() + .success() + .stdout("local x = 1\n"); + + cwd.close().unwrap(); + } + #[test] fn test_respect_ignores() { let cwd = construct_tree!({ @@ -755,6 +775,23 @@ mod tests { cwd.close().unwrap(); } + #[test] + fn test_respect_ignores_stdin() { + let cwd = construct_tree!({ + ".styluaignore": "foo.lua", + }); + + let mut cmd = create_stylua(); + cmd.current_dir(cwd.path()) + .args(["--respect-ignores", "--stdin-filepath", "foo.lua", "-"]) + .write_stdin("local x = 1") + .assert() + .success() + .stdout("local x = 1"); + + cwd.close().unwrap(); + } + #[test] fn test_respect_ignores_directory_no_glob() { // https://github.com/JohnnyMorganz/StyLua/issues/845