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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Added flag `--no-ignore-vcs` to continue formatting files listed in a `.gitignore` file, instead of skipping over them ([#895](https://github.com/JohnnyMorganz/StyLua/issues/895))

## [2.3.1] - 2025-11-01

### Fixed
Expand Down Expand Up @@ -157,11 +161,13 @@ failing tests ([#824](https://github.com/JohnnyMorganz/StyLua/issues/824))
### Changed

- Updated parser crate with following changes:

- Support Luau floor division (`//`)
- Fix Luau string interpolation parsing
- Fix Luau `\z` escape parsing

- Simplified access and modification patterns for StyLua configuration. You can now access the properties directly

- **Deprecated:** the old access patterns of `.property()` and `.with_property()` are now deprecated
- **Breaking Change (WASM):** due to JS/TS lack of differentiation between `.property` / `.property()` implementation, the `.property()` functions were removed from WASM output.

Expand Down
38 changes: 38 additions & 0 deletions src/cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,9 @@ fn format(opt: opt::Opt) -> Result<i32> {
.standard_filters(true)
.hidden(!opt.allow_hidden)
.parents(true)
.git_exclude(!opt.no_ignore_vcs)
.git_global(!opt.no_ignore_vcs)
.git_ignore(!opt.no_ignore_vcs)
.add_custom_ignore_filename(".styluaignore");

// Look for an ignore file in the current working directory
Expand Down Expand Up @@ -772,6 +775,41 @@ mod tests {
cwd.close().unwrap();
}

#[test]
fn test_formatting_respects_gitignore() {
let cwd = construct_tree!({
".git/dummy.txt": "", // Need a .git folder for .gitignore lookup
".gitignore": "foo.lua",
"foo.lua": "local x = 1",
});

let mut cmd = create_stylua();
cmd.current_dir(cwd.path()).args(["."]).assert().success();

cwd.child("foo.lua").assert("local x = 1");

cwd.close().unwrap();
}

#[test]
fn test_formatting_still_formats_gitignore_files_if_requested() {
let cwd = construct_tree!({
".git/dummy.txt": "", // Need a .git folder for .gitignore lookup
".gitignore": "foo.lua",
"foo.lua": "local x = 1",
});

let mut cmd = create_stylua();
cmd.current_dir(cwd.path())
.args(["--no-ignore-vcs", "."])
.assert()
.success();

cwd.child("foo.lua").assert("local x = 1\n");

cwd.close().unwrap();
}

#[test]
fn test_stdin_filepath_respects_cwd_configuration_next_to_file() {
let cwd = construct_tree!({
Expand Down
4 changes: 4 additions & 0 deletions src/cli/opt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ pub struct Opt {
#[structopt(short, long)]
pub allow_hidden: bool,

/// Whether to continue formatting files that are excluded from version control (e.g., listed in .gitignore)
#[structopt(long)]
pub no_ignore_vcs: bool,

/// Disables the EditorConfig feature.
///
/// Has no effect if a stylua.toml configuration file is found.
Expand Down
Loading