guarding

Crates.ioguarding
lib.rsguarding
version0.2.6
sourcesrc
created_at2021-05-13 09:16:04.331801
updated_at2021-10-22 12:25:04.339361
descriptionGuarding is a guardians for code, architecture, layered. Guarding crate a architecture aguard DSL which based on ArchUnit.
homepagehttps://github.com/inherd/guarding
repositoryhttps://github.com/inherd/guarding
max_upload_size
id396855
size27,943
Fengda Huang (phodal)

documentation

https://github.com/inherd/guarding

README

Guarding

Build crates.io docs.rs license

Guarding is a guardians for code, architecture, layered. Using git hooks and DSL for design guard rules.

Inspired by ArchUnit

Guarding Process

Usage

use CLI

  1. install
cargo install guarding
  1. create guarding.guarding file
package(".")::file.len should < 200;
package(".")::file.len should > 50;
  1. 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 models

DSL capture logic:

  1. filter models from rule_level with rule_scope
  2. run expression
  3. run assert

Queries Samples: 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("");

Todos

todo:

  • template
    • include(standard.guarding) syntax
  • filter
    • filter by package identifier
    • filter by regex
    • filter by implementation
    • filter by extends
    • filter by trait
  • limit impl naming
  • limit files num
  • limit package's sub-package size (for example, Clean Architecture).
  • assert
    • comparison for size / len
    • string comparison
      • contains
      • startsWith
      • endsWith
    • package ops
      • accessed
      • resideIn
      • dependBy
  • languages
    • Java
    • JavaScript (on Going)
    • TypeScript
    • Rust (on Going)
      • class & functions
      • imports
        • basic import
        • mods import restructure
      • package convert

License

This code is distributed under the MIT license. See LICENSE in this directory.

Commit count: 312

cargo fmt