Skip to content

Commit dc15567

Browse files
Add option to allow formatting files listed in .gitignore (#917)
* Add option to allow formatting files listed in .gitignore * Update changelog * Rename to no-ignore-vcs, only disable VCS-based ignores
1 parent becb272 commit dc15567

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- 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))
13+
1014
## [2.3.1] - 2025-11-01
1115

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

159163
- Updated parser crate with following changes:
164+
160165
- Support Luau floor division (`//`)
161166
- Fix Luau string interpolation parsing
162167
- Fix Luau `\z` escape parsing
163168

164169
- Simplified access and modification patterns for StyLua configuration. You can now access the properties directly
170+
165171
- **Deprecated:** the old access patterns of `.property()` and `.with_property()` are now deprecated
166172
- **Breaking Change (WASM):** due to JS/TS lack of differentiation between `.property` / `.property()` implementation, the `.property()` functions were removed from WASM output.
167173

src/cli/main.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,9 @@ fn format(opt: opt::Opt) -> Result<i32> {
267267
.standard_filters(true)
268268
.hidden(!opt.allow_hidden)
269269
.parents(true)
270+
.git_exclude(!opt.no_ignore_vcs)
271+
.git_global(!opt.no_ignore_vcs)
272+
.git_ignore(!opt.no_ignore_vcs)
270273
.add_custom_ignore_filename(".styluaignore");
271274

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

778+
#[test]
779+
fn test_formatting_respects_gitignore() {
780+
let cwd = construct_tree!({
781+
".git/dummy.txt": "", // Need a .git folder for .gitignore lookup
782+
".gitignore": "foo.lua",
783+
"foo.lua": "local x = 1",
784+
});
785+
786+
let mut cmd = create_stylua();
787+
cmd.current_dir(cwd.path()).args(["."]).assert().success();
788+
789+
cwd.child("foo.lua").assert("local x = 1");
790+
791+
cwd.close().unwrap();
792+
}
793+
794+
#[test]
795+
fn test_formatting_still_formats_gitignore_files_if_requested() {
796+
let cwd = construct_tree!({
797+
".git/dummy.txt": "", // Need a .git folder for .gitignore lookup
798+
".gitignore": "foo.lua",
799+
"foo.lua": "local x = 1",
800+
});
801+
802+
let mut cmd = create_stylua();
803+
cmd.current_dir(cwd.path())
804+
.args(["--no-ignore-vcs", "."])
805+
.assert()
806+
.success();
807+
808+
cwd.child("foo.lua").assert("local x = 1\n");
809+
810+
cwd.close().unwrap();
811+
}
812+
775813
#[test]
776814
fn test_stdin_filepath_respects_cwd_configuration_next_to_file() {
777815
let cwd = construct_tree!({

src/cli/opt.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ pub struct Opt {
9898
#[structopt(short, long)]
9999
pub allow_hidden: bool,
100100

101+
/// Whether to continue formatting files that are excluded from version control (e.g., listed in .gitignore)
102+
#[structopt(long)]
103+
pub no_ignore_vcs: bool,
104+
101105
/// Disables the EditorConfig feature.
102106
///
103107
/// Has no effect if a stylua.toml configuration file is found.

0 commit comments

Comments
 (0)