一个通过 swift-syntax
检测 [weak self]
的 CLI 工具
OVERVIEW: Check whether `self` is captured by weak reference in Closure.
USAGE: weak-self-check [<path>] [--report-type <report-type>] [--quick] [--silent] [--config <config>] [--index-store-path <index-store-path>]
ARGUMENTS:
<path> Path
OPTIONS:
--report-type <report-type>
Detected as `error` or `warning` (default: error)
--quick Check more quicklys. (Not accurate as indexPath is
not used)
--silent Do not output logs
--config <config> Config (default: .swift-weak-self-check.yml)
--index-store-path <index-store-path>
Path for IndexStore
-h, --help Show help information.
可以通过放置一个名为 .swift-weak-self-check.yml
的文件来自定义配置。
示例文件可在此处找到:swift-weak-self-check.yml
在以下条件下执行检测,并报告警告/错误。
类中调用的所有函数都将进行遍历。
检查作为函数参数存在的任何闭包。
如果该函数包含在配置文件的白名单中,则会跳过。
检查 self
是否在闭包中使用,而没有使用 [weak self]
或 [unowned self]
。
检查是否将 @escaping
属性附加到正在调用的函数的闭包类型。
如果闭包类型为 Optional
类型,即使未附加 @escaping
属性,也适用警告。
@escaping
,也可能产生循环引用。报告警告/错误
swift-weak-self-check 在 MIT 许可证下发布。 请参阅 LICENSE