An open API service indexing awesome lists of open source software.

https://github.com/halleck45/ast-metrics

AST Metrics is a language-agnostic static code analyzer.
https://github.com/halleck45/ast-metrics

quality static-analysis

Last synced: 11 days ago
JSON representation

AST Metrics is a language-agnostic static code analyzer.

Awesome Lists containing this project

README

          


AST Metrics


AST Metrics is a multi-language static code analyzer.


It provides architectural insights, complexity metrics, and activity analysis - all in a fast, standalone binary ready for CI/CD.


CI
GitHub Release
License: MIT

GitHub all releases
Go Report Card
codecov


Documentation | Contributing | Twitter





HTML Report


CLI




AST Metrics HTML report


AST Metrics CLI report

## Getting Started

Open your terminal and run the following command:

```console
curl -s https://raw.githubusercontent.com/Halleck45/ast-metrics/main/scripts/download.sh|bash
./ast-metrics analyze --report-html= /path/to/your/code
```

> To install it manually follow the detailed [installation instructions](https://halleck45.github.io/ast-metrics/getting-started/install/).

## Linting your code

Run:

```bash
# create a .ast-metrics.yaml config file
ast-metrics init

# Add ruleset to your config file
ast-metrics ruleset add architecture
ast-metrics ruleset add volume
ast-metrics ruleset list # see the list of available rulesets

# Run the linter
ast-metrics lint
```

You can declare thresholds in your YAML config (*Lines of code per method, Coupling, Maintainability...*).

Example:

```yaml
requirements:
rules:
architecture:
coupling:
forbidden:
- from: Controller
to: Repository
- from: Repository
to: Service
max_afferent_coupling: 10
max_efferent_coupling: 10
min_maintainability: 70
volume:
max_loc: 1000
max_logical_loc: 600
max_loc_by_method: 30
max_logical_loc_by_method: 20
complexity:
max_cyclomatic: 10
golang:
no_package_name_in_method: true
max_nesting: 4
max_file_size: 1000
max_files_per_package: 50
slice_prealloc: true
ignored_error: true
context_missing: true
context_ignored: true
```

This makes it **easy to enforce architecture and quality at scale**.

Run `ast-metrics ruleset list` to see the list of available rulesets. Then `ast-metrics ruleset add ` to apply a ruleset to your project.

## CI usage

Use the dedicated CI command to run lint and generate all reports in one go:

```bash
ast-metrics ci [options] /path/to/your/code
```

Notes:
- This command runs the linter first, then generates HTML, Markdown, JSON, OpenMetrics and SARIF reports.
- If any lint violations are found, the command exits with a non-zero status but still produces the reports.
- The previous alias `analyze --ci` is deprecated and will display a warning. Please migrate to `ast-metrics ci`.

## Github Action

Create a `.github/workflows/ast-metrics.yml` file in your project with the following content:

```yaml
name: "AST Metrics"
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: halleck45/action-ast-metrics@v1
```

## Why AST Metrics?

- **Catch issues early**: detect complex or tightly coupled code.
- **Ensure architectural coherence**: validate dependencies and layering.
- **Understand your project at scale**: from cyclomatic complexity to bus factor.

## Features

+ **Architectural analysis**: community detection, coupling, instability.
+ **Linter**: enforce coding standards and best practices.
+ **CI/CD ready**: plug into GitHub Actions, GitLab CI, or any pipeline.
+ **Fast & dependency-free**: single binary, no setup required.
+ **Code metrics**: complexity, maintainability, size.
+ **Activity metrics**: commits, bus factor.
+ **Readable reports**: detailed HTML dashboards.

[Read more in the documentation](https://halleck45.github.io/ast-metrics/)

## Supported languages

+ ✅ **Golang** `any version`
+ ✅ **Python** `Python 2, Python 3`
+ ✅ **Rust** `any version`
+ ✅ **PHP** `<= PHP 8.4`
+ 🕛 **TypeScript**
+ 🕛 **Flutter**
+ 🕛 **Java**
+ 🕛 **C++**
+ 🕛 **Ruby**

## License

AST Metrics is open-source software [licensed under the MIT license](LICENSE)

## Contributing

AST Metrics is an actively evolving project.

We welcome discussions, bug reports, and pull requests.

➡️ Start [contributing here](.github/CONTRIBUTING.md)