about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-05-04 16:08:48 +0000
committerbors <bors@rust-lang.org>2024-05-04 16:08:48 +0000
commit1a851da73cdeb02e2c62d301aa6bd98e515a50da (patch)
tree87958b43e7902ba38b5df6b1fce451211a1acd43
parentd7ea27808deb5e10a0f7384e339e4e6165e33398 (diff)
parentf43e3e2023f28d7e7a9f870612c6f2ef867a2acb (diff)
downloadrust-1a851da73cdeb02e2c62d301aa6bd98e515a50da.tar.gz
rust-1a851da73cdeb02e2c62d301aa6bd98e515a50da.zip
Auto merge of #124704 - Urgau:fix-ignored-tests-fmt, r=GuillaumeGomez
Fix ignored tests for formatting

This PR fixes the ignored rules in `rustfmt.toml` that were changed in https://github.com/rust-lang/rust/pull/124613 to allow formatting `rmake.rs` but ended up allowing formatting every Rust files in `tests/`.

The fix is a bit involved since we need to workaround a [`.gitignore` pattern limitation](https://git-scm.com/docs/gitignore#_pattern_format):
> An optional prefix "!" which negates the pattern; any matching file excluded by a previous pattern will become included again. It is not possible to re-include a file if a parent directory of that file is excluded. Git doesn’t list excluded directories for performance reasons, so any patterns on contained files have no effect, no matter where they are defined.

Workaround using https://stackoverflow.com/a/5534865

I tested the fix by changing the formatting in an `rmake.rs` and UI test, and verifying that only the `rmake.rs` files were formatted.

Fixes https://github.com/rust-lang/rust/pull/124613#issuecomment-2094094670
cc `@GuillaumeGomez`
r? `@onur-ozkan`
-rw-r--r--rustfmt.toml6
1 files changed, 6 insertions, 0 deletions
diff --git a/rustfmt.toml b/rustfmt.toml
index 67219b15d20..850d01ea7cb 100644
--- a/rustfmt.toml
+++ b/rustfmt.toml
@@ -13,6 +13,12 @@ ignore = [
 
     # tests for now are not formatted, as they are sometimes pretty-printing constrained
     # (and generally rustfmt can move around comments in UI-testing incompatible ways)
+    "/tests/*",
+
+    # but we still want to format rmake.rs files in tests/run-make/ so we need to do this
+    # dance to avoid the parent directory from being excluded
+    "!/tests/run-make/",
+    "/tests/run-make/*/*.rs",
     "!/tests/run-make/*/rmake.rs",
 
     # do not format submodules