Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
# gleam_contracts
# module_contracts

[![Package Version](https://img.shields.io/hexpm/v/gleam_contracts)](https://hex.pm/packages/gleam_contracts)
[![Hex Docs](https://img.shields.io/badge/hex-docs-ffaff3)](https://hexdocs.pm/gleam_contracts/)
[![Package Version](https://img.shields.io/hexpm/v/module_contracts)](https://hex.pm/packages/module_contracts)
[![Hex Docs](https://img.shields.io/badge/hex-docs-ffaff3)](https://hexdocs.pm/module_contracts/)

Build-time module contract verification for Gleam — enforce that paired modules stay in sync.

## Installation

```sh
gleam add gleam_contracts
gleam add module_contracts
```

## Usage

Create a contract check entrypoint in your package:

```gleam
import gleam_contracts
import gleam_contracts/rule
import module_contracts
import module_contracts/rule

pub fn main() {
gleam_contracts.check(
module_contracts.check(
interface_path: "build/dev/docs/my_package/package-interface.json",
rules: [
gleam_contracts.mirror_rule(
module_contracts.mirror_rule(
source: "my_package/headless/button",
target: "my_package/button",
prefix_params: [rule.Labeled(label: "context")],
)
|> gleam_contracts.with_exceptions(exceptions: ["button"]),
gleam_contracts.shared_types(
|> module_contracts.with_exceptions(exceptions: ["button"]),
module_contracts.shared_types(
module_a: "my_package/headless/button",
module_b: "my_package/button",
type_names: ["ButtonConfig"],
Expand Down
32 changes: 16 additions & 16 deletions SPEC.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# gleam_contracts Specification
# module_contracts Specification

Build-time module contract verification for Gleam. Reads the compiler's
`package-interface` JSON and checks that paired modules (e.g. headless/styled
Expand Down Expand Up @@ -230,38 +230,38 @@ pub fn check(
## Module Layout

```
src/gleam_contracts.gleam — public API, re-exports
src/gleam_contracts/rule.gleam — Rule type + constructors
src/gleam_contracts/verify.gleam — verification engine
src/gleam_contracts/violation.gleam — Violation type + formatter
src/gleam_contracts/loader.gleam — package interface JSON loading
src/module_contracts.gleam — public API, re-exports
src/module_contracts/rule.gleam — Rule type + constructors
src/module_contracts/verify.gleam — verification engine
src/module_contracts/violation.gleam — Violation type + formatter
src/module_contracts/loader.gleam — package interface JSON loading
```

## Usage Pattern

A consuming project adds `gleam_contracts` as a dev dependency, then
A consuming project adds `module_contracts` as a dev dependency, then
creates a verification entry point:

```gleam
// test/contract_test.gleam (or a standalone script)
import gleam_contracts
import gleam_contracts/rule
import module_contracts
import module_contracts/rule

pub fn main() {
gleam_contracts.check(
module_contracts.check(
interface_path: "build/dev/docs/my_package/package-interface.json",
rules: [
gleam_contracts.mirror_rule(
module_contracts.mirror_rule(
source: "my_package/headless/badge",
target: "my_package/badge",
prefix_params: [rule.Labeled(label: "context")],
),
gleam_contracts.mirror_rule(
module_contracts.mirror_rule(
source: "my_package/headless/button",
target: "my_package/button",
prefix_params: [rule.Labeled(label: "context")],
)
|> gleam_contracts.with_exceptions(exceptions: ["button"]),
|> module_contracts.with_exceptions(exceptions: ["button"]),
],
)
}
Expand All @@ -277,18 +277,18 @@ gleam run -m contract_test
Or as a startest test:

```gleam
import gleam_contracts
import module_contracts
import startest.{describe, it}
import startest/expect

pub fn contract_tests() {
describe("module contracts", [
it("headless/styled modules stay in sync", fn() {
let assert Ok(interface) = gleam_contracts.load_package_interface(
let assert Ok(interface) = module_contracts.load_package_interface(
path: "build/dev/docs/my_package/package-interface.json",
)

gleam_contracts.verify(interface: interface, rules: my_rules())
module_contracts.verify(interface: interface, rules: my_rules())
|> expect.to_be_ok
}),
])
Expand Down
4 changes: 2 additions & 2 deletions gleam.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name = "gleam_contracts"
name = "module_contracts"
version = "0.1.0"
description = "Build-time module contract verification for Gleam — enforce that paired modules stay in sync."
licences = ["Apache-2.0"]
repository = { type = "github", user = "bbopen", repo = "gleam_contracts" }
repository = { type = "github", user = "bbopen", repo = "module_contracts" }
gleam = ">= 1.14.0"

[dependencies]
Expand Down
8 changes: 4 additions & 4 deletions src/gleam_contracts.gleam → src/module_contracts.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import gleam/io
import gleam/package_interface.{type Package}
import gleam/result
import gleam_contracts/loader
import gleam_contracts/rule
import gleam_contracts/verify as contract_verify
import gleam_contracts/violation
import module_contracts/loader
import module_contracts/rule
import module_contracts/verify as contract_verify
import module_contracts/violation

/// Decoded package-interface model exported by the compiler.
pub type PackageInterface =
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import gleam/package_interface.{
TypeDefinition, Variable,
}
import gleam/string
import gleam_contracts/rule.{
import module_contracts/rule.{
type ExportSpec, type ParamSpec, type Rule, ExportSpec, Labeled, MirrorRule,
RequireExports, SharedTypes, Unlabeled,
}
import gleam_contracts/violation.{
import module_contracts/violation.{
type Violation, MissingExport, MissingFunction, MissingType, ModuleNotFound,
ParameterMismatch, TypeMismatch,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import gleam/int
import gleam/list
import gleam/string
import gleam_contracts/loader.{type LoadError}
import module_contracts/loader.{type LoadError}

/// A single contract violation.
pub type Violation {
Expand Down
Loading