Git Product home page Git Product logo

aave's Introduction

Aave friendly fork of Aave

malli powered code checking for Clojure(Script).

Fork, you say?

  • This fork adds ClojureScript support and various quality of life improvements, such as 'humanize'd errors.
  • I'll likely be continuing this over time and may diverge from upstream some more. :)

Original README

Pre-alpha - highly subject to change.

“Wherever we find orderly, stable systems in Nature, we find that they are hierarchically structured, for the simple reason that without such structuring of complex systems into sub-assemblies, there could be no order and stability-except the order of a dead universe filled with a uniformly distributed gas.”

-- Arthur Koestler, The Ghost in the Machine

About

aave enables you to write inline schema definitions for your functions. It is highly configurable enabling you to choose what happens when various checks fail. It also provides utilities for common code-quality checks, such as naming conventions.

Examples / Features

In/Outstrumentation

Checks that function inputs and outputs adhere to their schemas before/after invoking function bodies.

Flags:

  • :aave.core/instrument, default true
  • :aave.core/outstrument, default true

Hooks:

  • :aave.core/on-instrument-fail, default: throw exception
  • :aave.core/on-outstrument-fail, default: throw exception
(ns example
  (:require [aave.core :refer [>defn] :as a]))

(>defn bad-return-val
  [x y]
  [int? int? => string?]
  (+ x y))

;; (bad-return-val 1 "foo") will raise `on-instrument-fail`
;; (bad-return-val 1 2) will raise `on-outstrument-fail`

Stub Generation

Causes function definitions with empty bodies to return randomly generated data instead of nil.

Flags:

  • :aave.core/generate-stubs, Default: true
(ns example
  (:require [aave.core :refer [>defn] :as a]))

(>defn add
  {::a/generate-stubs true}
  [x y]
  [int? int? => int?])

;; (add 1 2) => -1

Purity Enforcement

Checks that functions that call functions with ! are also named with a !.

Flags:

  • :aave.core/enforce-purity, default: true

Hooks:

  • :aave.core/on-compilation-purity-fail, default: throw compile-time exception
(ns example
  (:require [aave.core :refer [>defn] :as a]))

(def counter (atom nil))

(>defn increment-counter
  "Increments the coutner and returns the old value"
  {::a/enforce-purity true
   ::a/on-purity-fail (fn [] (throw (ex-info "Purity mismatch")))}
  []
  [=> int?]
  (swap! some-atom inc)))
;; Will raise an exception. Will pass if function is named `increment-counter!`

Development

aave is an open-source project and contributions are more than welcome!

Roadmap

  • Compile-time exercising of (pure) functions
  • Test assertions for a namespace
  • Benchmarking via ::a/benchmark true
  • Consider custom exception types instead of ex-info
  • Additional syntax support (eg. schema style)
  • Clojurescript testing
  • Config groups to save groups of settings as named groups.
  • Configuration at compile time and loading via file at run time
  • nrepl middleware - add ops for getting sample input and querying function metadata

Testing

clojure -Atest

Important Namespaces

  • aave.core - The main "user-level" namespace. Should remain concise and focused on things that a developer would want to do from the REPL or imports that should be readily available.

  • aave.code - Responsible for code generation and analysis. Provides utilities and macros for analysing and modifying code. The most important function in here is the generate macro, which is used to generate function definitions from a config map.

  • aave.config - Provides the implementation of the configuration management for aave. For users, the majority of functionality should be exposed via aave.core.

  • aave.syntax.* - Code parsing constructs for specific syntaxes of function declaration. Eg. ghostwheel, def-spec, etc. If you want to extend aave with support for your favorite way of declaring functions, this is the place to do it.

Inspiration

Aave borrows and builds upon ideas of many fantastic projects. Most directly, it is largely inspired by tools like ghostwheel and orchestra. Thanks to the authors and many others that have provided an amazing foundation of ideas to build upon.

aave's People

Contributors

rschmukler avatar tekacs avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.