Coherent Swift 是一个使用 Swift 编写的命令行工具,用于测量 Swift 代码库中的内聚性。
在计算机编程中,内聚性是指模块中的元素彼此关联的程度。因此,内聚性衡量给定模块内各个功能部分之间关系的强度。例如,在高内聚系统中,功能之间具有很强的关联性。
当内聚性很高时,意味着类的 methods 和 variables 是相互依赖的,并且作为一个逻辑整体结合在一起。
- Clean Code pg. 140
高内聚性的一些优点,也来自维基百科
coherent-swift 的灵感来自 cohesion。
brew install arthurpalves/m/coherent-swift
mint install arthurpalves/coherent-swift
git clone https://github.com/arthurpalves/coherent-swift.git
cd coherent-swift
make install
git clone https://github.com/arthurpalves/coherent-swift.git
cd coherent-swift
swift run coherent-swift
Usage: coherent-swift <command> [options]
A command-line tool to analyze and report Swift code cohesion
Commands:
init Generate specs (.yml) file
report Generate a report on Swift code cohesion
help Prints help information
version Prints the current version of this app
在运行 report
命令之前,您必须首先拥有一个规范/配置文件。 这是一个 YAML 文件,包含 coherent-swift 的基本配置。
coherent-swift init
这将在您的工作目录中生成文件 coherent-swift.yml
。查看规范模板
注意:默认情况下,
coherent-swift
希望在./coherent-swift.yml
中找到上述配置,如果您的文件位于其他位置或具有不同的名称,请使用参数-s | --spec
指定其路径。
Usage: coherent-swift report [options]
Generate a report on Swift code cohesion
Options:
-d, --diffs Only scan modified files
-h, --help Show help information
-s, --spec <value> Use a yaml configuration file
-v, --verbose Log tech details for nerds
coherent-swift report
coherent-swift report --verbose
coherent-swift 在 MIT 许可下发布。 有关更多信息,请参见 LICENSE。