Guarding
Guarding is a guardians for code, architecture, layered. Using git hooks and DSL for design guard rules.
Usage
- install
cargo install guarding
- create
guarding.guarding
file
package(".")::file.len should < 200;
package(".")::file.len should > 50;
- run
guarding .
Development
workflow:
- parsing guarding rules
- parsing source code to models
- capture rule with models
DSL capture logic:
- filter models from
rule_level
withrule_scope
- run expression
- run assert
Queries Samples: https://github.com/nvim-treesitter/nvim-treesitter/tree/master/queries
Guarding - Class or Struct function-name
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:
- 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.