Skip to content

Commit

Permalink
Don't ignore by default with --stdin-filepath, use `--respect-ignor…
Browse files Browse the repository at this point in the history
…es` (#912)

Don't ignore by default with `--stdin-filepath`
  • Loading branch information
JohnnyMorganz authored Nov 16, 2024
1 parent 2c6a374 commit 5e4e837
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
39 changes: 38 additions & 1 deletion src/cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,10 @@ fn format(opt: opt::Opt) -> Result<i32> {
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,
};

Expand Down Expand Up @@ -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!({
Expand All @@ -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
Expand Down

0 comments on commit 5e4e837

Please sign in to comment.