License Version Language Platform Cohesion

Coherent Swift 是一个使用 Swift 编写的命令行工具,用于测量 Swift 代码库中的内聚性。

功能

什么是内聚性?

在计算机编程中,内聚性是指模块中的元素彼此关联的程度。因此,内聚性衡量给定模块内各个功能部分之间关系的强度。例如,在高内聚系统中,功能之间具有很强的关联性。

当内聚性很高时,意味着类的 methods 和 variables 是相互依赖的,并且作为一个逻辑整体结合在一起。

高内聚性的一些优点,也来自维基百科

coherent-swift 的灵感来自 cohesion

安装

Homebrew(推荐)

brew install arthurpalves/m/coherent-swift

Mint

mint install arthurpalves/coherent-swift

Make

git clone https://github.com/arthurpalves/coherent-swift.git
cd coherent-swift
make install

Swift Package Manager

作为 CLI 使用

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

coherent-swift report --verbose

coherent-swift report --verbose

感谢

许可

coherent-swift 在 MIT 许可下发布。 有关更多信息,请参见 LICENSE