Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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