https://github.com/modernizing/guarding
Guarding is a guardians for code, architecture, layered, inspired by ArchUnit. Guarding 是一个用于 Java、JavaScript、Rust、Golang 等语言的架构守护工具。借助于易于理解的 DSL,来编写守护规则。Guarding is a guardians for code, architecture, layered.
https://github.com/modernizing/guarding
architecture architecture-tests archunit guardian
Last synced: about 1 month ago
JSON representation
Guarding is a guardians for code, architecture, layered, inspired by ArchUnit. Guarding 是一个用于 Java、JavaScript、Rust、Golang 等语言的架构守护工具。借助于易于理解的 DSL,来编写守护规则。Guarding is a guardians for code, architecture, layered.
- Host: GitHub
- URL: https://github.com/modernizing/guarding
- Owner: modernizing
- License: mit
- Created: 2021-05-13T09:00:49.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2022-02-21T01:49:40.000Z (over 3 years ago)
- Last Synced: 2025-04-04T17:03:07.929Z (about 2 months ago)
- Topics: architecture, architecture-tests, archunit, guardian
- Language: Rust
- Homepage:
- Size: 745 KB
- Stars: 71
- Watchers: 6
- Forks: 13
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# Guarding
[](https://github.com/inherd/guarding/actions/workflows/build.yml)
[](https://crates.io/crates/guarding)
[](https://docs.rs/guarding/)
[](https://github.com/inherd/guarding/blob/master/LICENSE)> Guarding is a guardians for code, architecture, layered. Using git hooks and DSL for design guard rules.
Inspired by [ArchUnit](https://github.com/TNG/ArchUnit)

## Usage
### use CLI
1. install
```
cargo install guarding
```2. create `guarding.guarding` file
```
package(".")::file.len should < 200;
package(".")::file.len should > 50;
```3. run
```
guarding .
```### use API
- `guarding_adapter`, FFI adapter, provide Guarding api,
- `guarding_core`, core guarding model,
- `guarding_ident`, identify different language: Java, JavaScript, Rust
- `guarding_parser` parsing Guarding DSL## Development
workflow:
1. parsing guarding rules
2. parsing source code to models
3. capture rule with modelsDSL capture logic:
1. filter models from `rule_level` with `rule_scope`
2. run expression
3. run assertQueries Samples: [https://github.com/nvim-treesitter/nvim-treesitter/tree/master/queries](https://github.com/nvim-treesitter/nvim-treesitter/tree/master/queries)
### Guarding - Class or Struct function-name
for packages:
```
class(implementation "BaseParser")::name should endsWith "Parser";class("java.util.Map") only accessed(["com.phodal.pepper.refactor.staticclass"]);
class(implementation "BaseParser")::name should not contains "Lexer";
```for Java, JavaScript
```
# 类::名 包含 "Controller";
# 中文分词:("..myapp..") 类名称中包含 "Controller"
class("..myapp..")::function.name should contains("Model");
# or
class("..myapp..")::function.name contains("");
```for Rust and Golang
```
struct("..myapp..")::function.name should contains("Model");
# or
struct("..myapp..")::function.name contains("");
```License
---This code is distributed under the MIT license. See `LICENSE` in this directory.