CoherentSwift is a command line tool written in Swift that analyses the cohesion level of your Swift codebase.

What's New



License Version Language Platform Cohesion

Coherent Swift is a command line tool written in Swift that measures cohesion in your Swift codebase .


  • ✅ Measures the cohesion of your Swift code
  • ✅ Ability to validate cohesion against a minimum threshold
  • ✅ Ability to scan only through files that have been changed
  • ✅ Ability to ignore output for a passive scan
  • ✅ Generates report in JSON or plain text
  • ✅ Generates a compatible JSON file

What is Cohesion?

In computer programming, cohesion refers to the degree to which the elements of a module belong together. Thus, cohesion measures the strength of relationship between pieces of functionality within a given module. For example, in highly cohesive systems functionality is strongly related.

When cohesion is high, it means that the methods and variables of the class are co-dependent and hang together as a logical whole.

  • Clean Code pg. 140

Some of the advantages of high cohesion, also by Wikipedia:

  • Reduced module complexity (they are simpler, having fewer operations).
  • Increased system maintainability, because logical changes in the domain affect fewer modules, and because changes in one module require fewer changes in other modules.
  • Increased module reusability, because application developers will find the component they need more easily among the cohesive set of operations provided by the module.

coherent-swift is inspired by cohesion.


brew install arthurpalves/m/coherent-swift


mint install arthurpalves/coherent-swift


git clone
cd coherent-swift
make install

Swift Package Manager

Use as CLI

git clone
cd coherent-swift
swift run coherent-swift


Usage: coherent-swift <command> [options]

A command-line tool to analyze and report Swift code cohesion

  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

Specs | Configuration

Before running the report command you must first have a spec/configuration file. This is a YAML file containing the basic configuration for coherent-swift.

coherent-swift init

This will generate the file coherent-swift.yml in your working directory. See the specs template

NOTE: By default, coherent-swift expects to find the configuration above in ./coherent-swift.yml, if you do have this file elsewhere or with a different name, please specify it's path by using the parameter -s | --spec.

Scan and report

Usage: coherent-swift report [options]

Generate a report on Swift code cohesion

  -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


  • mschwager, who has built cohesion, a tool for measuring Python class cohesion.
  • Omar Albeik, colleague, whose contribution to Open Source served as inspiration to put this out here. This README is also inspired by his work on SketchGen and inherits all appreciation to those who made that possible.


coherent-swift is released under the MIT license. See LICENSE for more information.


  • Swift Tools 5.4.0
View More Packages from this Author


Last updated: Sun Sep 24 2023 10:33:48 GMT-0900 (Hawaii-Aleutian Daylight Time)