fontspector_checkhelper/lib.rs
1#![deny(
2 missing_docs,
3 rustdoc::missing_crate_level_docs,
4 clippy::missing_docs_in_private_items
5)]
6//! Checks in fontspector are made up of two parts: the implementation,
7//! which is a Rust function, and metadata: the check's ID, rationale,
8//! proposal URL(s) and so on. This crate provides a procedural macro to
9//! help associate the metadata with the implementation.
10//!
11//! To write a fontspector check, you need to implement a function that
12//! takes a `Testable` and a `Context` as arguments (for checks which operate
13//! on a single font) or a `TestableCollection` and a `Context`. You
14//! then decorate the function with the `#[check(...)]` macro, passing
15//! the metadata as arguments. The macro will generate the necessary
16//! code to associate the metadata with the implementation.
17//!
18//! A function which takes a `TestableCollection` should have the argument
19//! `implementation = "all"` in the `#[check(...)]` attribute. This will
20
21/// Check parser and macro implementation
22mod check;
23use proc_macro::TokenStream;
24
25use check::check_impl;
26
27/// A procedural macro to associate metadata with a check implementation.
28///
29/// Example:
30///
31/// ```ignore
32/// use fontspector_api::prelude::*; // Includes this macro
33///
34/// #[check(
35/// id = "example_check",
36/// title = "Example Check",
37/// rationale = "This is an example check.",
38/// /// proposal = "https://example.com/proposal",
39/// )]
40/// fn example_check(f: &Testable, _context: &Context) -> CheckFnResult {
41/// // Check implementation goes here
42/// }
43/// ```
44#[proc_macro_attribute]
45pub fn check(args: TokenStream, item: TokenStream) -> TokenStream {
46 check_impl(args, item)
47}