U0005 ui-disabled-without-reason¶
Rule: A disabled control says why and what would enable it.
| Code | U0005 (stable, never reused) |
| Id | ui-disabled-without-reason |
| Category | ui |
| Source | spirit_level |
| Fix | by hand |
Level per tier¶
| Tier | Level | Reason |
|---|---|---|
| small | off | |
| small-workspace | off | |
| medium | off | |
| big | off | |
| ai | off | |
| embedded | off | |
| ui | warn |
a greyed-out control that does not say why leaves the person guessing |
| egui | warn |
a disabled egui widget shows only on_disabled_hover_text; on_hover_text stays silent on it |
| units-strict | off | |
| units-paranoid | off |
Parameters¶
| Name | Type | Default | Meaning |
|---|---|---|---|
disable-calls |
list of strings | [] |
methods that disable a control or a region |
reason-calls |
list of strings | [] |
methods that attach the reason a disabled control shows |
toolkits |
list of strings | ["egui", "eframe", "iced", "slint", "gtk4", "relm4", "dioxus", "leptos", "yew", "floem", "xilem", "makepad-widgets"] |
UI toolkits: a crate that depends on one directly is a UI crate, unless the crate map says ui = false |
Why¶
A greyed-out control that does not say why leaves the person guessing what to do. The practice: never hide a control that cannot be used now, show it disabled, and say why and what would enable it, in a tooltip or, where there is no hover, a short line.
The lint reports, in UI crates, a call of disable-calls (egui: add_enabled, add_enabled_ui, disable) when no call of reason-calls (egui: on_disabled_hover_text) is in the same statement. A disable call that is a statement of its own (ui.disable();) may also take its reasons from the later statements of its block or an enclosing one. A disable call whose first argument is true is skipped. Findings are estimates: a reason given through a helper of the project is not seen.
In egui, on_hover_text does not show on a disabled widget; only on_disabled_hover_text does.
ui.add_enabled(connected, Button::new("Flash")); // reported
ui.add_enabled(connected, Button::new("Flash"))
.on_disabled_hover_text("Not connected: plug the probe in first"); // passes
How to fix¶
Attach the reason and what would enable the control. When the cause is on screen, hovering the control highlights it (vhrd_egui: ve_basics::hover_link).
Configure¶
[lints.ui-disabled-without-reason]
level = "deny"
disable-calls = []
reason-calls = []
toolkits = ["egui", "eframe", "iced", "slint", "gtk4", "relm4", "dioxus", "leptos", "yew", "floem", "xilem", "makepad-widgets"]
reason = "why this project wants it at this level"
Allow one finding in the code with // spirit-level: allow(ui-disabled-without-reason) <reason> (waivers); the code works there too, as in [lints.U0005].