From 229e1bea9749986307b8dec0750167c96fd2ab8e Mon Sep 17 00:00:00 2001 From: JohnnyMorganz Date: Sun, 17 Nov 2024 13:31:56 +0100 Subject: [PATCH 1/3] Add option to allow formatting files listed in .gitignore --- src/cli/main.rs | 37 ++++++++++++++++++++++++++++++++++++- src/cli/opt.rs | 4 ++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/cli/main.rs b/src/cli/main.rs index 2c96d7ce..32075878 100644 --- a/src/cli/main.rs +++ b/src/cli/main.rs @@ -304,7 +304,7 @@ fn format(opt: opt::Opt) -> Result { } walker_builder - .standard_filters(true) + .standard_filters(!opt.allow_gitignore) .hidden(!opt.allow_hidden) .parents(true) .add_custom_ignore_filename(".styluaignore"); @@ -808,4 +808,39 @@ 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(["--allow-gitignore", "."]) + .assert() + .success(); + + cwd.child("foo.lua").assert("local x = 1\n"); + + cwd.close().unwrap(); + } } diff --git a/src/cli/opt.rs b/src/cli/opt.rs index 0e7c5884..4b59c9e6 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 listed in .gitignore / .ignore + #[structopt(long)] + pub allow_gitignore: bool, + /// Disables the EditorConfig feature. /// /// Has no effect if a stylua.toml configuration file is found. From fda3aa4dfe966b595f378c70a72d097809e4dd71 Mon Sep 17 00:00:00 2001 From: JohnnyMorganz Date: Sun, 17 Nov 2024 13:36:21 +0100 Subject: [PATCH 2/3] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 02e838a8..1ca609ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added runtime syntax configuration option `syntax` to help handle ambiguous syntax. By default, StyLua builds and runs with a parser to handle all Lua versions. However, the syntax of some Lua versions conflict with eachother: most notably, Lua 5.2+ goto label syntax `::label::` and Luau type assertion operator `::`. This option allows choosing what syntax to parse, to handle these conflicts. ([#407](https://github.com/JohnnyMorganz/StyLua/issues/407)) - Added configuration option `space_after_function_names` to specify whether to include a space between a function name and parentheses ([#839](https://github.com/JohnnyMorganz/StyLua/issues/839)) +- Added flag `--allow-gitignore` to continue formatting files listed in a `.gitignore` file, instead of skipping over them ([#895](https://github.com/JohnnyMorganz/StyLua/issues/895)) ### Changed From ecab48550892d695470f6742a6fbfe7e425daf1b Mon Sep 17 00:00:00 2001 From: JohnnyMorganz Date: Sat, 24 Jan 2026 13:34:23 +0000 Subject: [PATCH 3/3] Rename to no-ignore-vcs, only disable VCS-based ignores --- CHANGELOG.md | 2 +- src/cli/main.rs | 7 +++++-- src/cli/opt.rs | 4 ++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3dcfab5b..98386381 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added -- Added flag `--allow-gitignore` to continue formatting files listed in a `.gitignore` file, instead of skipping over them ([#895](https://github.com/JohnnyMorganz/StyLua/issues/895)) +- 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 diff --git a/src/cli/main.rs b/src/cli/main.rs index 9572f1d5..4f7fbb63 100644 --- a/src/cli/main.rs +++ b/src/cli/main.rs @@ -264,9 +264,12 @@ fn format(opt: opt::Opt) -> Result { } walker_builder - .standard_filters(!opt.allow_gitignore) + .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 @@ -798,7 +801,7 @@ mod tests { let mut cmd = create_stylua(); cmd.current_dir(cwd.path()) - .args(["--allow-gitignore", "."]) + .args(["--no-ignore-vcs", "."]) .assert() .success(); diff --git a/src/cli/opt.rs b/src/cli/opt.rs index 7706a9f1..b9d8499b 100644 --- a/src/cli/opt.rs +++ b/src/cli/opt.rs @@ -98,9 +98,9 @@ pub struct Opt { #[structopt(short, long)] pub allow_hidden: bool, - /// Whether to continue formatting files listed in .gitignore / .ignore + /// Whether to continue formatting files that are excluded from version control (e.g., listed in .gitignore) #[structopt(long)] - pub allow_gitignore: bool, + pub no_ignore_vcs: bool, /// Disables the EditorConfig feature. ///