Skip to content

Commit 752fe6c

Browse files
committed
Skip formatting cde-tool managed files
1 parent 73e4034 commit 752fe6c

3 files changed

Lines changed: 25 additions & 8 deletions

File tree

.githooks/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ git config core.hooksPath .githooks
2828
- 检测所有待提交的 `.swift` 文件
2929
- 使用 `swift-format` 格式化这些文件
3030
- 自动将格式化后的文件重新暂存
31+
- 自动跳过 `cde-tool` 托管的 generated files(例如 `*+CoreDataEvolution.swift`
3132
- 如果未安装 `swift-format`,会给出警告但不会阻止提交
3233

3334
## 安装 swift-format

.githooks/pre-commit

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,22 @@ fi
3939

4040
# swift-format 使用默认规则或项目根目录的 .swift-format 配置
4141

42+
# `cde-tool` managed files participate in exact drift validation. Formatting them in the hook would
43+
# introduce noise that the generator did not emit.
44+
is_cde_managed_file() {
45+
local file="$1"
46+
47+
if [[ "$file" == *"+CoreDataEvolution.swift" ]]; then
48+
return 0
49+
fi
50+
51+
if [ -f "$file" ] && grep -q '^// cde-tool:generated$' "$file"; then
52+
return 0
53+
fi
54+
55+
return 1
56+
}
57+
4258
# 格式化每个文件
4359
FORMATTED_COUNT=0
4460
for file in $SWIFT_FILES; do
@@ -49,6 +65,11 @@ for file in $SWIFT_FILES; do
4965
;;
5066
esac
5167

68+
if is_cde_managed_file "$file"; then
69+
echo " ⏭️ 跳过 cde-tool 托管文件: $file"
70+
continue
71+
fi
72+
5273
if [ -f "$file" ]; then
5374
echo " 📝 格式化: $file"
5475

Integration/GeneratedFlowFixture/Sources/GeneratedModels/FlowTask+CoreDataEvolution.swift

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ import Foundation
88
@objc(FlowTask)
99
@PersistentModel
1010
public final class FlowTask: NSManagedObject {
11-
@Attribute(
12-
persistentName: "config_blob", storageMethod: .codable,
13-
decodeFailurePolicy: .fallbackToDefaultValue)
11+
@Attribute(persistentName: "config_blob", storageMethod: .codable, decodeFailurePolicy: .fallbackToDefaultValue)
1412
public var config: FlowTaskConfig? = nil
1513

1614
@Attribute(persistentName: "created_at")
@@ -24,13 +22,10 @@ public final class FlowTask: NSManagedObject {
2422
@Attribute(persistentName: "name")
2523
public var title: String = ""
2624

27-
@Attribute(
28-
persistentName: "status_raw", storageMethod: .raw, decodeFailurePolicy: .fallbackToDefaultValue)
25+
@Attribute(persistentName: "status_raw", storageMethod: .raw, decodeFailurePolicy: .fallbackToDefaultValue)
2926
public var status: FlowTaskStatus? = nil
3027

31-
@Attribute(
32-
persistentName: "tags_payload", storageMethod: .transformed(name: "NSSecureUnarchiveFromData"),
33-
decodeFailurePolicy: .fallbackToDefaultValue)
28+
@Attribute(persistentName: "tags_payload", storageMethod: .transformed(name: "NSSecureUnarchiveFromData"), decodeFailurePolicy: .fallbackToDefaultValue)
3429
public var tags: [String]? = nil
3530

3631
@Relationship(persistentName: "owner_project", inverse: "owned_tasks", deleteRule: .nullify)

0 commit comments

Comments
 (0)