-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path.swiftlint.yml
More file actions
120 lines (104 loc) · 3.78 KB
/
.swiftlint.yml
File metadata and controls
120 lines (104 loc) · 3.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# SwiftLint 配置 —— STBaseProject
# 与 .github/check_try_question_mark.sh 互补:try? 政策由专门脚本兜底,本文件聚焦
# 其他反模式:强解包、as!、过长文件、Bool 旗参痕迹、`@objc` 滥用等。
#
# 渐进式落地策略:
# - 严重项标 error(as!、Markdown 外 try! 在源码区)
# - 风格项标 warning,先看清存量数量再考虑收紧
# - 大量历史代码可以通过 `disabled_rules` 精确豁免
included:
- Sources
excluded:
- Sources/STMarkdown/Resources
- .build
- DerivedData
# 默认规则中需要关闭或软化的
disabled_rules:
- todo # TODO/FIXME 不视为告警
- identifier_name # 历史命名以 st_ / ST 前缀为主,先不卡
- type_name # 同上
- trailing_whitespace # 历史空白多,独立 PR 清理
- opening_brace # 与历史风格不一致
- line_length # 由下方自定义长度覆盖
- force_try # 由 st_no_force_try_outside_markdown 精准限制,允许 STMarkdown 静态正则
opt_in_rules:
- empty_count
- empty_string
- explicit_init
- first_where
- last_where
- redundant_nil_coalescing
- redundant_type_annotation
- sorted_first_last
- prohibited_super_call
- overridden_super_call
- closure_end_indentation
- closure_spacing
- contains_over_filter_count
- contains_over_first_not_nil
- convenience_type
- discouraged_optional_boolean # ★ 标记 Optional<Bool>,常是 Bool 旗参的延伸坏味
- fallthrough
- fatal_error_message
- flatmap_over_map_reduce
- force_unwrapping # ★ 强解包警告(不直接 error,避免一次性失血)
- implicitly_unwrapped_optional # ★ 隐式解包变量
- joined_default_parameter
- literal_expression_end_indentation
- lower_acl_than_parent # ★ 子声明可见性高于父类型时报警
- modifier_order
- operator_usage_whitespace
- redundant_string_enum_value
- sorted_imports
- toggle_bool
force_cast: error # as! 直接 error
analyzer_rules:
- unused_import
- unused_declaration
# === 规则参数化 ===
line_length:
warning: 220
error: 300
ignores_urls: true
ignores_function_declarations: true
ignores_comments: true
function_body_length:
warning: 120
error: 250
type_body_length:
warning: 600
error: 1000
file_length:
warning: 1200
error: 2500
ignore_comment_only_lines: true
cyclomatic_complexity:
warning: 15
error: 30
nesting:
type_level: 3
# === 自定义规则 ===
custom_rules:
st_no_force_try_outside_markdown:
name: "try! outside STMarkdown is forbidden"
regex: '\\btry!'
match_kinds:
- keyword
message: "try! 仅在 STMarkdown 静态正则编译路径允许,其它位置请使用 do/catch。"
severity: error
excluded:
- "Sources/STMarkdown/.*"
st_no_print:
name: "Use STLog instead of print"
regex: '(?<![\w.])print\('
message: "请使用 STLog(...) 输出日志,避免 print 在生产环境泄露。"
severity: warning
excluded:
- "Sources/STUIKit/STLog/.*" # 日志模块自身
- "Sources/STMarkdown/Resources/.*"
st_avoid_bool_flag_param:
name: "Avoid Bool flag parameters (use enum)"
regex: '\b(?<!override\s)func\s+\w+\([^)]*(?:\b(?:enabled|disabled|on|off|flag|animated|immediately|prettyPrinted|fromEnd|ellipsis|uppercase|sync|force|reset|notify|selected|highlighted|displayMode|imageReady|iconOnLeft|animatingIn)|\b(?:is|has|can|should|allows?|enable|disable|use|uses|include|exclude|show|hide|needs|wants|requires)[A-Z]\w*)\s*:\s*Bool(?:\s*=\s*[^,\)\n]+)?(?=\s*[,)\n])'
message: "Bool 旗参可读性差,建议改为枚举(如 case enabled / disabled)。"
severity: warning
reporter: "xcode"