[CI] Update swiftformat config#3753
Conversation
WalkthroughThis change updates SwiftFormat and SwiftLint exclusion handling by moving exclusion rules from inline command arguments into configuration files for both lefthook and SwiftFormat. It also removes a redundant SwiftFormat snippets file, adjusts Fastlane configuration for formatting, and introduces a pre-push hook for SwiftLint in lefthook.yml. Changes
Sequence Diagram(s)sequenceDiagram
participant Dev as Developer
participant Lefthook as Lefthook
participant SwiftFormat as SwiftFormat
participant SwiftLint as SwiftLint
Dev->>Lefthook: git commit / push
Lefthook->>SwiftFormat: Run with exclusion list from config
Lefthook->>SwiftLint: Run with exclusion list from config
Lefthook->>Lefthook: On push, run pre-push SwiftLint with exclusions
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Note ⚡️ Unit Test Generation is now available in beta!Learn more here, or try it out under "Finishing Touches" below. ✨ Finishing Touches🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
.swiftformat(1 hunks).swiftformat-snippets(0 hunks)fastlane/Fastfile(2 hunks)lefthook.yml(1 hunks)
💤 Files with no reviewable changes (1)
- .swiftformat-snippets
🧰 Additional context used
🧠 Learnings (1)
fastlane/Fastfile (1)
Learnt from: testableapple
PR: #3740
File: fastlane/Fastfile:849-886
Timestamp: 2025-07-23T16:14:40.281Z
Learning: The team prefers simpler error handling in fastlane scripts and relies on fastlane's default error reporting mechanisms rather than adding explicit begin-rescue blocks around shell commands.
🔇 Additional comments (5)
fastlane/Fastfile (2)
798-799: LGTM! Cleaner exclusion handling.The simplification of the SwiftFormat command by removing the
--excludeoption and iterating over a unifiedsources_matrix[:swiftformat]key is a good improvement. This centralizes exclusion management in the.swiftformatconfiguration file.
835-835: Good refactoring to unify source paths.The consolidation of separate include/exclude keys into a single
swiftformatkey simplifies the configuration and aligns with the new centralized exclusion approach.lefthook.yml (3)
4-11: LGTM! Improved exclusion handling for SwiftFormat.Moving exclusions from inline
--excludearguments to the YAMLexcludelist is cleaner and more maintainable. The lefthook configuration syntax is correct.
16-23: Good consistency in SwiftLint exclusion handling.The exclusion patterns are consistent with the SwiftFormat configuration above, maintaining the same approach across both tools.
28-38: Excellent addition of pre-push SwiftLint strict mode.The new pre-push hook running SwiftLint in strict mode is a great way to catch issues before code is pushed. The configuration properly uses
{push_files}and includes appropriate skip conditions.
| # Exclude paths | ||
| --exclude **/Generated,Sources/StreamChatUI/StreamNuke,Sources/StreamChatUI/StreamSwiftyGif,Sources/StreamChatUI/StreamDifferenceKit |
There was a problem hiding this comment.
💡 Verification agent
🧩 Analysis chain
Verify path consistency across configuration files.
The exclusion paths look well-structured, but there's a discrepancy between the StreamChatUI paths here and the StreamChatSwiftUI paths in lefthook.yml. Ensure these paths match the actual directory structure.
🏁 Script executed:
#!/bin/bash
# Verify the actual directory structure to confirm correct paths
echo "Checking for StreamChatUI directories:"
fd -t d StreamChatUI Sources/
echo "Checking for StreamChatSwiftUI directories:"
fd -t d StreamChatSwiftUI Sources/
echo "Checking for the specific excluded subdirectories:"
fd -t d -e / StreamNuke StreamSwiftyGif StreamDifferenceKit Sources/Length of output: 584
🏁 Script executed:
#!/bin/bash
# List immediate subdirectories under Sources/StreamChatUI to confirm exclusions
echo "Subdirectories in Sources/StreamChatUI:"
ls -d Sources/StreamChatUI/*/ || echo "No subdirectories found or path does not exist."
# Search all YAML configs for any references to StreamChatSwiftUI vs StreamChatUI
echo -e "\nReferences to 'StreamChatSwiftUI' in .yml files:"
grep -R -n "StreamChatSwiftUI" --include="*.yml" . || echo "No references to StreamChatSwiftUI found."
echo -e "\nReferences to 'StreamChatUI' in .yml files:"
grep -R -n "StreamChatUI" --include="*.yml" . || echo "No references to StreamChatUI found."Length of output: 3469
Ensure consistent exclusion paths across all configs
The .swiftformat exclusions correctly reference Sources/StreamChatUI (where the directories actually live). However, lefthook.yml still points to the non-existent Sources/StreamChatSwiftUI/... path. Update those entries to use Sources/StreamChatUI so all tooling excludes the same directories.
• Fix in lefthook.yml: replace
Sources/StreamChatSwiftUI/StreamNuke/**
Sources/StreamChatSwiftUI/StreamSwiftyGif/**
Sources/StreamChatSwiftUI/StreamDifferenceKit/**with
Sources/StreamChatUI/StreamNuke/**
Sources/StreamChatUI/StreamSwiftyGif/**
Sources/StreamChatUI/StreamDifferenceKit/**Affected blocks at lines 9–11, 21–23, and 34–36 in lefthook.yml.
🤖 Prompt for AI Agents
In lefthook.yml at lines 9–11, 21–23, and 34–36, update the exclusion paths from
Sources/StreamChatSwiftUI/... to Sources/StreamChatUI/... to match the correct
directory names used in the .swiftformat file. Replace all instances of
Sources/StreamChatSwiftUI/StreamNuke/**,
Sources/StreamChatSwiftUI/StreamSwiftyGif/**, and
Sources/StreamChatSwiftUI/StreamDifferenceKit/** with
Sources/StreamChatUI/StreamNuke/**, Sources/StreamChatUI/StreamSwiftyGif/**, and
Sources/StreamChatUI/StreamDifferenceKit/** respectively to ensure consistent
exclusion paths across all configs.
| - Sources/StreamChatSwiftUI/StreamNuke/** | ||
| - Sources/StreamChatSwiftUI/StreamSwiftyGif/** | ||
| - Sources/StreamChatSwiftUI/StreamDifferenceKit/** |
There was a problem hiding this comment.
Critical: Path inconsistency with .swiftformat configuration.
The exclusion paths use StreamChatSwiftUI here, but the .swiftformat file uses StreamChatUI. This inconsistency could result in different files being excluded by different tools, leading to formatting/linting inconsistencies.
The paths should be consistent across all configuration files. Verify which path is correct and update accordingly:
#!/bin/bash
# Verify the correct directory structure
echo "Checking actual directory structure:"
find Sources/ -type d -name "StreamNuke" -o -name "StreamSwiftyGif" -o -name "StreamDifferenceKit" 2>/dev/nullAlso applies to: 21-23, 34-36
🤖 Prompt for AI Agents
In lefthook.yml around lines 9 to 11 (and also lines 21-23, 34-36), the
exclusion paths use "StreamChatSwiftUI" which is inconsistent with the
".swiftformat" file that uses "StreamChatUI". To fix this, verify the correct
directory name by checking the actual folder structure under Sources/ using a
command like 'find Sources/ -type d -name "StreamNuke" -o -name
"StreamSwiftyGif" -o -name "StreamDifferenceKit"'. Then update all exclusion
paths in lefthook.yml to match the correct directory name consistently across
all configuration files.
| - rebase | ||
|
|
||
| - run: mint run swiftlint lint --config .swiftlint.yml --strict --progress --quiet --reporter json {staged_files} | ||
| pre-push: |
There was a problem hiding this comment.
So the summary is that if I commit, then we autocorrect and include autocorrected files with the commit. If I push, then we just lint again for making sure no linting related issues end up in develop?
Summary by CodeRabbit