Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/matsoftware/swift-code-metrics
Code metric analyzer for Swift projects.
https://github.com/matsoftware/swift-code-metrics
analysis architecture dependency dependency-graph dependency-tree ios macos metrics swift swift-dependencies-visualizer
Last synced: 1 day ago
JSON representation
Code metric analyzer for Swift projects.
- Host: GitHub
- URL: https://github.com/matsoftware/swift-code-metrics
- Owner: matsoftware
- License: mit
- Created: 2018-06-01T06:50:28.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-08-18T07:55:17.000Z (about 1 year ago)
- Last Synced: 2024-10-22T13:06:37.730Z (22 days ago)
- Topics: analysis, architecture, dependency, dependency-graph, dependency-tree, ios, macos, metrics, swift, swift-dependencies-visualizer
- Language: Python
- Homepage:
- Size: 716 KB
- Stars: 326
- Watchers: 5
- Forks: 13
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fmatsoftware%2Fswift-code-metrics.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fmatsoftware%2Fswift-code-metrics?ref=badge_shield) [![License](https://img.shields.io/badge/license-MIT-blue.svg?x=1)](LICENSE) [![Build Status](https://travis-ci.org/matsoftware/swift-code-metrics.svg?branch=master)](https://travis-ci.org/matsoftware/swift-code-metrics) [![codecov](https://codecov.io/gh/matsoftware/swift-code-metrics/branch/master/graph/badge.svg)](https://codecov.io/gh/matsoftware/swift-code-metrics) [![Codacy Badge](https://app.codacy.com/project/badge/Grade/c4ecbd3b64cf4518a113bb56d93f6323)](https://www.codacy.com/gh/matsoftware/swift-code-metrics/dashboard?utm_source=github.com&utm_medium=referral&utm_content=matsoftware/swift-code-metrics&utm_campaign=Badge_Grade)
[![PyPI](https://img.shields.io/pypi/v/swift-code-metrics.svg)](https://pypi.python.org/pypi/swift-code-metrics)# swift-code-metrics
Code metrics analyzer for Swift projects.
| ![Example code distribution](https://raw.githubusercontent.com/matsoftware/swift-code-metrics/master/docs/assets/code_distribution.jpeg) ![Example deviation main sequence](https://raw.githubusercontent.com/matsoftware/swift-code-metrics/master/docs/assets/example_deviation_main_sequence.jpeg) |
| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ![Example internal distribution](https://raw.githubusercontent.com/matsoftware/swift-code-metrics/master/docs/assets/example_internal_deps_graph.jpeg) |## Introduction
The goal of this software is to provide an insight of the architectural state of a software written in `Swift` that consists in several modules.
Inspired by the book of Robert C. Martin, _Clean Architecture_, the software will scan the project to identify the different components in order to assess several common code metrics in the software industry:- the overall number of concrete classes and interfaces
- the _instability_ and _abstractness_ of the framework
- the _distance from the main sequence_
- LOC (Lines Of Code)
- NOC (Numbers Of Comments)
- POC (Percentage Of Comments)
- NOM (Number of Methods)
- Number of concretes (Number of classes and structs)
- NOT (Number Of Tests)
- NOI (Number Of Imports)
- Frameworks dependency graph (number of internal and external dependencies)## Requirements
This is a _Python 3_ script that depends on _matplotlib_, _adjustText_, _pyfunctional_ and _pygraphviz_.
This latest package depends on the [Graphviz](https://www.graphviz.org/download/) binary that must be installed before. If you're in a Mac environment, you can install it directly with `brew install graphviz`.
## Usage
The package is available on `pip` with `pip3 install swift-code-metrics`.
The syntax is:
`swift-code-metrics --source --artifacts --exclude --tests-paths --generate-graphs`
- `--source` is the path to the folder that contains the main Xcode project or Workspace
- `--artifacts` path to the folder that will contain the generated `output.json` report
- `--exclude` (optional) space separated list of path substrings to exclude from analysis (e.g. `Tests` will ignore all files/folders that contain `Tests`)
- `--tests-paths` (default: `Test Tests`) space separated list of path substrings matching test classes
- `--generate-graphs` (optional) if passed, it will generate the graphs related to the analysis and save them in the artifacts folder### Development
Please run `./install.sh` and `./build_and_test.sh` to install dependencies and run the tests.
The repo comes with a predefined setup for VS Code to debug and run tests as well.
## Documentation
Please follow the [guide](https://github.com/matsoftware/swift-code-metrics/tree/master/docs/GUIDE.md) with a practical example to get started.
## Current limitations
- This tool is designed for medium/large codebases composed by different frameworks.
The script will scan the directory and it will identify the frameworks by the name of the 'root' folder,
so it's strictly dependent on the file hierarchy (unless a [project path override file](docs/GUIDE.md#Project-paths-override) is specified)- Libraries built with `spm` are not supported.
- The framework name is inferred using the directory structure. If the file is in the root dir, the `default_framework_name` will be used. No inspection of the xcodeproj will be made.
- The list of methods currently doesn't support computed vars
- Inline comments in code (such as `struct Data: {} //dummy data`) are currently not supported
- Only `XCTest` test frameworks are currently supported
## TODOs
- Code improvements
- Other (open to suggestions)## Contact
[Mattia Campolese](https://www.linkedin.com/in/matcamp/)