Skip to main content

Crate ravenrs_lint

Crate ravenrs_lint 

Source
Expand description

Lints for applications built with RavenRS.

The compiler and Clippy know Rust, not the rules an interface must follow to stay right in every theme, for screen readers and across rebuilds. ravenrs-lint reads the syntax tree of an application’s sources and reports those rules the way the compiler does:

error[ravenrs::raw_color]: literal color in the interface
  --> src/ui.rs:12:21
   |
12 |         .background(Color::rgb(0.1, 0.2, 0.3))
   |                     ^^^^^^^^^^
   |
   = help: use a `Semantic` role, such as `.background(Semantic::Control)`, so it stays right in every theme

§Running it

From the command line, after cargo install ravenrs-lint:

cargo ravenrs-lint            # every package of the workspace that depends on RavenRS
cargo ravenrs-lint --init     # recommended rustc and Clippy lints, the test below and AGENTS.md

From cargo test, so nothing passes while a rule is broken, with ravenrs-lint as a dev-dependency and a file such as tests/ravenrs_lint.rs:

#[test]
fn follows_the_ravenrs_rules() {
    ravenrs_lint::assert_clean();
}

§Configuring it

Levels follow Cargo’s [lints]: allow, warn or deny. They go in the package’s or the workspace’s metadata, and the package wins:

[package.metadata.ravenrs-lint]
language = "pt-BR"            # how button captions are checked: "en" (default) or "pt-BR"
extra-verbs = ["Ok"]          # first words accepted as verbs besides the built-in ones

[package.metadata.ravenrs-lint.lints]
off_grid_spacing = "deny"

A single place is excused with a comment that says why, on the same line or on its own line right above:

// ravenrs-lint: allow(raw_color) the church's logo keeps its brand color in every theme

allow-file(...) excuses the whole file. Test code (#[test], #[cfg(test)]) is not checked.

The rules are listed in Lint.

Structs§

Config
The configuration of one package.
Diagnostic
One broken rule at one place in a source file.
InitReport
What init did.
Package
One package of the workspace.

Enums§

Error
Why a check could not run.
Language
The language of the interface’s text, for the checks that read it.
Level
How a broken rule is reported, as in Cargo’s [lints].
Lint
A rule ravenrs-lint checks. Every rule is deny unless the configuration lowers it, and lowering one to allow needs a reason.

Functions§

assert_clean
Checks the package whose tests are running and panics with every diagnostic, warnings included, the way cargo clippy -- -D warnings fails. Call it from a #[test].
check_dir
Checks every .rs file under dir, in a stable order. Paths in the diagnostics are relative to base when they are inside it.
check_package
Checks the sources of one package: the directories of its library and binaries.
check_source
Checks one source file. file is only used in the diagnostics.
init
Prepares the package in dir for the strict rules. Running it again updates the agents’ block and leaves the rest as it is.
packages
The packages of the workspace that manifest belongs to.
recommended_clippy
The clippy.toml init writes.
recommended_lints
The [lints] tables init writes.
render
The diagnostics as the compiler would print them, followed by a summary line when summary.
render_json
One JSON object per line, for editors and agents.