Skip to content

Add ability to filter config options to files created after date - #2689

Merged
calda merged 1 commit into
nicklockwood:developfrom
calda:cal--filter-by-creation-date
Sep 21, 2026
Merged

calda merged 1 commit into
nicklockwood:developfrom
calda:cal--filter-by-creation-date

Conversation

@calda

@calda calda commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator

This PR adds the ability to apply options only to files created after a given date.

We already have the ability to apply options only within certain directories:

--rules ...

[Tests]
--filter **/Tests/**
--enable noForceUnwrapInTests
--enable noForceTryInTests
--indent 2

Following this design, we can support applying any options to file created after a certain date:

[New test files]
--filter header-creation-date-after:2026-08-31
--enable preferSwiftTesting

The quickest way to retrieve the creation date of the file is to retrieve it from the header comment. It could also make sense to support the Git creation date using something like git-creation-date-after, but Git-integrated functionality is too expensive for our use case.

@codecov

codecov Bot commented Sep 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.50847% with 23 lines in your changes missing coverage. Please review.
✅ Project coverage is 95.44%. Comparing base (28330d9) to head (a266e65).

Files with missing lines Patch % Lines
Sources/Arguments.swift 77.55% 22 Missing ⚠️
Sources/Options.swift 83.33% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2689      +/-   ##
===========================================
- Coverage    95.51%   95.44%   -0.07%     
===========================================
  Files          182      182              
  Lines        27830    27930     +100     
===========================================
+ Hits         26582    26658      +76     
- Misses        1248     1272      +24     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@nicklockwood

Copy link
Copy Markdown
Owner

@calda is the idea of this feature to avoid formatting existing files? If so I had a slightly different idea in mind:

I was thinking of adding a --snapshot feature that would capture the current state of the project, using the same hashing mechanism already employed by the cache.

the snapshot file would be saved in the project as something like .swiftformat-snapshot. Any files that match the hashes in the snapshot would be ignored for future formatting passes.

@calda

calda commented Sep 10, 2026

Copy link
Copy Markdown
Collaborator Author

I think the snapshot idea is reasonable, but I think checking in a snapshot file is more complicated and visible than using the created-on date (for example, if a file is renamed, the snapshot file has to be updated).

We also would need the ability to only ignore existing violations for specific rules, rather than just ignoring all existing violations in a file.

I think both approaches are pretty reasonable with different situation where one makes more sense than the other.

@nicklockwood

Copy link
Copy Markdown
Owner

No reason not to have both I suppose, but the neat feature of a snapshot is that files that are touched get opted back into formatting, whereas with the creation date they don't.

Unless you plan to support modified date as an alternative option?

@calda

calda commented Sep 10, 2026

Copy link
Copy Markdown
Collaborator Author

In our case we specifically only want to apply the preferSwiftTesting rule to newly-created Swift files, and not apply it to existing Swift files. We want it to be alright to continue modifying existing XCTest files without them being auto-formatted to Swift Testing.

@nicklockwood
nicklockwood force-pushed the develop branch 3 times, most recently from 5908303 to 741c3e4 Compare September 16, 2026 06:51
@calda
calda force-pushed the cal--filter-by-creation-date branch from b69d5ff to a266e65 Compare September 21, 2026 17:34
@calda
calda merged commit fd6f2d3 into nicklockwood:develop Sep 21, 2026
14 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants