OxL Reference

module std.comptime

std.comptime — the read-only AST seen by lint plugins (ч. III.4, §15.4; D-6560..).

A plugin is an OxL file listed in [lint] plugins = ["lints/my_rule.oxl"] of oxl.toml. Every comptime fn of the file with one parameter of type Decl is called by the compiler for every declaration of the package (types, functions, methods, rpcs, actor messages, fields, variants, consts, ...). The values are plain data built by the compiler; the plugin reads them and reports problems with warn(at, message) or by failing with CompileError. The rule's level is [lint] my_rule = "warn" | "error" | "off" (the name is the file name without .oxl; default warn). Kinds are lower-case strings, listed in docs/analyzer.md.

Example:

oxl✓ checked in CI
use std.comptime { Decl, warn }

// lints/short_names.oxl, listed in `[lint] plugins = ["lints/short_names.oxl"]`

comptime fn short_names(d: Decl) {
  if d.isPub && d.name.len() < 3 {
    warn(d.span, "public name `{d.name}` is too short")
  }
}

Types

data AttrAn attribute @name(args).
data AttrArgAn argument of an attribute
data CompileErrorThe error of a plugin
data DeclA declaration or a member of one.
data ExprAn expression of a body, in pre-order.
data SpanA source range: file path, 1-based line and column of the start, byte offset and length.

Functions

warnReports a diagnostic of the plugin's rule at at (its level comes from [lint], default warning).

See also