Skip to main content

sofie_check/rules/
clients.rs

1use sofie_model::{App, AreaClient};
2
3use super::manifest::{declaration_line, manifest_text};
4use super::{Finding, Rule};
5
6const FRAMEWORK_PACKAGE: &str = "sofie-framework";
7const CLIENTS_FEATURE: &str = "clients";
8
9/// The wiring hands each client area its bundle through sofie's `clients` feature, so without
10/// it the app fails to compile on a name the error does not explain.
11#[must_use]
12pub fn check_client_feature(app: &App, framework_features: &[String]) -> Vec<Finding> {
13    if framework_features
14        .iter()
15        .any(|feature| feature == CLIENTS_FEATURE)
16    {
17        return Vec::new();
18    }
19    let areas = app.areas();
20    let Some(area) = areas.iter().find(|area| {
21        area.definition
22            .is_some_and(|definition| definition.client != AreaClient::Html)
23    }) else {
24        return Vec::new();
25    };
26    let (manifest, text) = manifest_text(&app.app);
27    let line = app
28        .app
29        .dependencies
30        .iter()
31        .find(|dependency| dependency.package == FRAMEWORK_PACKAGE)
32        .map_or(1, |dependency| {
33            declaration_line(&text, &dependency.crate_name)
34        });
35    vec![Finding {
36        rule: Rule::ClientFeature,
37        file: manifest,
38        line,
39        message: format!(
40            "area `{}` names a client, but the app does not enable sofie's `{CLIENTS_FEATURE}` \
41             feature, which serves client areas",
42            area.name
43        ),
44        fix: format!(
45            "add \"{CLIENTS_FEATURE}\" to the `features` of the app's `sofie` dependency in \
46             app/Cargo.toml"
47        ),
48    }]
49}