diff --git a/CHANGELOG.md b/CHANGELOG.md index aa68ef83..98386381 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 @@ -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. diff --git a/src/cli/main.rs b/src/cli/main.rs index 1ab114dd..4f7fbb63 100644 --- a/src/cli/main.rs +++ b/src/cli/main.rs @@ -267,6 +267,9 @@ fn format(opt: opt::Opt) -> Result { .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 @@ -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!({ diff --git a/src/cli/opt.rs b/src/cli/opt.rs index 6e1999e3..b9d8499b 100644 --- a/src/cli/opt.rs +++ b/src/cli/opt.rs @@ -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.