G0001 core-crate-deps¶
Rule: A _core crate depends only on other _core crates, the allowed layers and listed vocabulary crates.
| Code | G0001 (stable, never reused) |
| Id | core-crate-deps |
| Category | graph |
| Source | spirit_level |
| Fix | by hand |
Level per tier¶
| Tier | Level | Reason |
|---|---|---|
| small | off | |
| small-workspace | off | |
| medium | warn |
a _core crate holds shared types and drags nothing in |
| big | deny |
a _core crate holds shared types and drags nothing in |
| ai | off | |
| embedded | off | |
| ui | off | |
| egui | off | |
| units-strict | off | |
| units-paranoid | off |
Parameters¶
| Name | Type | Default | Meaning |
|---|---|---|---|
suffix |
string | "_core" |
the name suffix of type-only crates |
layers |
list of strings | [] |
map layers a _core crate may depend on besides other _core crates |
vocabulary |
list of strings | ["serde", "serde_derive", "thiserror"] |
third-party or workspace crates a _core crate may use |
Why¶
A _core crate holds the types others share: ids, data, errors, the vocabulary of a domain. To stay usable by a CLI, a server, a test or a wasm build it must not drag anything in: it depends only on other _core crates, on the layers named in layers, and on a short list of vocabulary crates (serde, thiserror).
vocabulary may also name a workspace crate: a project whose own vocabulary (a units crate, say) does not end in _core lists it there instead of moving it into the crate map's layers. An edge to the workspace-hack package is exempt, as for layer-edges: the one hakari-package names in .config/hakari.toml (or .guppy/hakari.toml), never a crate merely called workspace-hack.
How to fix¶
Move what needs the dependency into the crate above the _core crate, or, when the dependency really is part of the types (a units crate, say), list it in vocabulary with an override reason.
Configure¶
[lints.core-crate-deps]
level = "deny"
suffix = "_core"
layers = []
vocabulary = ["serde", "serde_derive", "thiserror"]
reason = "why this project wants it at this level"
Allow one finding in the code with // spirit-level: allow(core-crate-deps) <reason> (waivers); the code works there too, as in [lints.G0001].