Skip to main content

Crate flynt

Crate flynt 

Source
Expand description

Lint Fluent translation keys against their use in Rust code and Askama templates.

Keys used in templates {{ "key" | t(&lang) }} and in Rust loc("key", &lang) are collected and compared against the .ftl files. A typo then fails the build instead of shipping the key name as user-facing text.

flynt infers what to scan from the target repository. Workspace members come from its Cargo.toml. Locales come from the subdirectories of its locales directory. Every default can be overridden, on the command line or in a .flynt.toml.

§Checks

  • coverage: a used key is defined in every locale.
  • consistency: every locale defines the same set of keys.
  • duplicates: no locale defines a key twice.
  • unused: every defined key is referenced somewhere. This is a warning by default.
  • syntax: every .ftl file parses.

§Example

use flynt::config::{self, PartialConfig};

let cli = PartialConfig {
    root: Some("../my-project".into()),
    ..PartialConfig::default()
};
let config = config::load(&cli)?;
let report = flynt::check(&config)?;

for finding in &report.missing_keys {
    println!("{} is missing in {}", finding.key, finding.missing_in.join(", "));
}
assert_eq!(report.exit_code(), 0);

Re-exports§

pub use config::ColorChoice;
pub use config::Config;
pub use config::OutputFormat;
pub use config::PartialConfig;
pub use config::Severity;
pub use model::DuplicateKey;
pub use model::InconsistentKey;
pub use model::KeyDefinition;
pub use model::KeyUsage;
pub use model::Location;
pub use model::MissingKey;
pub use model::ParseError;
pub use model::Report;
pub use model::SCHEMA_VERSION;
pub use model::Summary;
pub use model::UnusedKey;
pub use model::UsageType;

Modules§

config
Configuration: CLI, .flynt.toml, and manifest discovery.
model
Data model: key usages, key definitions, findings, and the report.
report
Rendering a Report.

Functions§

check
Runs every check and returns the report. Performs no output.