Skip to content

Latest commit

 

History

History
145 lines (102 loc) · 4.84 KB

README.md

File metadata and controls

145 lines (102 loc) · 4.84 KB

License Version Language Platform Cohesion

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

Features

  • ✅ 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 shields.io 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.

Installation

Homebrew (recommended)

brew install arthurpalves/m/coherent-swift
mint install arthurpalves/coherent-swift

Make

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

Swift Package Manager

Use as CLI

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

Usage

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

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

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

Example

coherent-swift report

coherent-swift report

coherent-swift report --verbose

coherent-swift report --verbose

Thanks

  • 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.

License

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