Rule.h header

#include <ew/app/Rule.h>

Namespace ew::app

Rule struct

struct ew::app::Rule

The description of one check: what it is called, what it asserts, and how it is run.

A description, not the code. The evaluation lives with the validator that owns it – the timeline's pairwise walk cannot usefully be expressed as data, and pretending otherwise would mean a rule table that lied about half its entries. What this carries is everything a consumer needs: to list the rule, to name it in a finding, to enable or disable it, to raise or lower its severity, and to know what it costs before running it.

assertion and fix are the two fields a user-authored rule fills in and a built-in one leaves empty. They are here rather than on a separate type so that a built-in rule and a rule the user wrote are the same kind of thing to every surface that lists them.

Members

QString ew::app::diagnostics::Rule::id

Stable identity, kebab-case and namespaced by the validator that owns it – "timeline/two-places-at-once", "branch/unreachable", "style/repeated-word". It is what a finding reports and what a suppression names, so it must outlive any renaming of the display text.

QString ew::app::diagnostics::Rule::name

What the rule is called in a list, in the author's language.

QString ew::app::diagnostics::Rule::description

One or two sentences on what it checks and why that matters.

std::vector<QString> ew::app::diagnostics::Rule::tags

Free-text labels for grouping and filtering – "continuity", "craft", "structure".

bool ew::app::diagnostics::Rule::enabled = true

Whether the rule runs at all. A disabled rule produces no findings anywhere.

Severity ew::app::diagnostics::Rule::severity =

The severity its findings carry unless a finding overrides it.

RuleScope ew::app::diagnostics::Rule::scope =

What it is evaluated against.

RuleTrigger ew::app::diagnostics::Rule::trigger =

When it is worth running.

RuleCost ew::app::diagnostics::Rule::cost =

Roughly what it costs.

QString ew::app::diagnostics::Rule::assertion

For a user-authored rule, the expression that must hold. Empty for a built-in, whose assertion is code.

QString ew::app::diagnostics::Rule::message

The message template its findings use. Empty for a built-in, which phrases each finding against the objects involved.

QString ew::app::diagnostics::Rule::fix

For a user-authored rule, the expression producing a suggested correction. Empty when the rule offers no mechanical fix, which is the common case.

bool operator==(const Rule &, const Rule &)=default

Rules compare equal when every field matches.

Enumerations

enum class RuleCost { Cheap, Moderate, Expensive }

Roughly what a rule costs to evaluate, so a caller can order or budget a sweep.

enum class RuleScope { Project, ContentType, Category, CategoryTree, Object }

What a rule is evaluated against.

Scope is also the performance lever, not only a filter: a rule scoped to one category must be evaluated against that category and never against the project, or a world bible of twenty thousand objects pays for every rule on every object.

enum class RuleTrigger { OnEdit, OnSave, OnDemand }

What makes a rule worth running now.

Recorded so a caller can run the cheap rules on every keystroke and the expensive ones on demand, rather than discovering the difference by feel.

Functions

std::optional< RuleCost > ew::app::diagnostics::ruleCostFromToken(QStringView token)

Parses a rule cost from its serialization token; std::nullopt if unrecognized or absent.

std::optional< RuleScope > ew::app::diagnostics::ruleScopeFromToken(QStringView token)

Parses a rule scope from its serialization token; std::nullopt if unrecognized or absent.

std::optional< RuleTrigger > ew::app::diagnostics::ruleTriggerFromToken(QStringView token)

Parses a rule trigger from its serialization token; std::nullopt if unrecognized or absent.

QString ew::app::diagnostics::toToken(RuleScope scope)

Returns the stable serialization token for scope.

QString ew::app::diagnostics::toToken(RuleTrigger trigger)

Returns the stable serialization token for trigger.

QString ew::app::diagnostics::toToken(RuleCost cost)

Returns the stable serialization token for cost.