Skip to content

Commit b25b642

Browse files
Improve readability of rule status icons in documentation (#18297)
Co-authored-by: Micha Reiser <[email protected]>
1 parent 175402a commit b25b642

File tree

1 file changed

+24
-31
lines changed

1 file changed

+24
-31
lines changed

crates/ruff_dev/src/generate_rules_table.rs

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,44 +18,43 @@ const FIX_SYMBOL: &str = "🛠️";
1818
const PREVIEW_SYMBOL: &str = "🧪";
1919
const REMOVED_SYMBOL: &str = "❌";
2020
const WARNING_SYMBOL: &str = "⚠️";
21-
const STABLE_SYMBOL: &str = "✔️";
2221
const SPACER: &str = "&nbsp;&nbsp;&nbsp;&nbsp;";
2322

23+
/// Style for the rule's fixability and status icons.
24+
const SYMBOL_STYLE: &str = "style='width: 1em; display: inline-block;'";
25+
/// Style for the container wrapping the fixability and status icons.
26+
const SYMBOLS_CONTAINER: &str = "style='display: flex; gap: 0.5rem; justify-content: end;'";
27+
2428
fn generate_table(table_out: &mut String, rules: impl IntoIterator<Item = Rule>, linter: &Linter) {
25-
table_out.push_str("| Code | Name | Message | |");
29+
table_out.push_str("| Code | Name | Message | |");
2630
table_out.push('\n');
27-
table_out.push_str("| ---- | ---- | ------- | ------: |");
31+
table_out.push_str("| ---- | ---- | ------- | -: |");
2832
table_out.push('\n');
2933
for rule in rules {
3034
let status_token = match rule.group() {
3135
RuleGroup::Removed => {
32-
format!("<span title='Rule has been removed'>{REMOVED_SYMBOL}</span>")
36+
format!(
37+
"<span {SYMBOL_STYLE} title='Rule has been removed'>{REMOVED_SYMBOL}</span>"
38+
)
3339
}
3440
RuleGroup::Deprecated => {
35-
format!("<span title='Rule has been deprecated'>{WARNING_SYMBOL}</span>")
41+
format!(
42+
"<span {SYMBOL_STYLE} title='Rule has been deprecated'>{WARNING_SYMBOL}</span>"
43+
)
3644
}
3745
RuleGroup::Preview => {
38-
format!("<span title='Rule is in preview'>{PREVIEW_SYMBOL}</span>")
39-
}
40-
RuleGroup::Stable => {
41-
// A full opacity checkmark is a bit aggressive for indicating stable
42-
format!("<span title='Rule is stable' style='opacity: 0.6'>{STABLE_SYMBOL}</span>")
46+
format!("<span {SYMBOL_STYLE} title='Rule is in preview'>{PREVIEW_SYMBOL}</span>")
4347
}
48+
RuleGroup::Stable => format!("<span {SYMBOL_STYLE}></span>"),
4449
};
4550

4651
let fix_token = match rule.fixable() {
4752
FixAvailability::Always | FixAvailability::Sometimes => {
48-
format!("<span title='Automatic fix available'>{FIX_SYMBOL}</span>")
49-
}
50-
FixAvailability::None => {
51-
format!(
52-
"<span title='Automatic fix not available' style='opacity: 0.1' aria-hidden='true'>{FIX_SYMBOL}</span>"
53-
)
53+
format!("<span {SYMBOL_STYLE} title='Automatic fix available'>{FIX_SYMBOL}</span>")
5454
}
55+
FixAvailability::None => format!("<span {SYMBOL_STYLE}></span>"),
5556
};
5657

57-
let tokens = format!("{status_token} {fix_token}");
58-
5958
let rule_name = rule.as_ref();
6059

6160
// If the message ends in a bracketed expression (like: "Use {replacement}"), escape the
@@ -82,15 +81,14 @@ fn generate_table(table_out: &mut String, rules: impl IntoIterator<Item = Rule>,
8281
#[expect(clippy::or_fun_call)]
8382
let _ = write!(
8483
table_out,
85-
"| {ss}{0}{1}{se} {{ #{0}{1} }} | {ss}{2}{se} | {ss}{3}{se} | {ss}{4}{se} |",
86-
linter.common_prefix(),
87-
linter.code_for_rule(rule).unwrap(),
88-
rule.explanation()
84+
"| {ss}{prefix}{code}{se} {{ #{prefix}{code} }} | {ss}{explanation}{se} | {ss}{message}{se} | <div {SYMBOLS_CONTAINER}>{status_token}{fix_token}</div>|",
85+
prefix = linter.common_prefix(),
86+
code = linter.code_for_rule(rule).unwrap(),
87+
explanation = rule
88+
.explanation()
8989
.is_some()
9090
.then_some(format_args!("[{rule_name}](rules/{rule_name}.md)"))
9191
.unwrap_or(format_args!("{rule_name}")),
92-
message,
93-
tokens,
9492
);
9593
table_out.push('\n');
9694
}
@@ -104,12 +102,6 @@ pub(crate) fn generate() -> String {
104102
table_out.push_str("### Legend");
105103
table_out.push('\n');
106104

107-
let _ = write!(
108-
&mut table_out,
109-
"{SPACER}{STABLE_SYMBOL}{SPACER} The rule is stable."
110-
);
111-
table_out.push_str("<br />");
112-
113105
let _ = write!(
114106
&mut table_out,
115107
"{SPACER}{PREVIEW_SYMBOL}{SPACER} The rule is unstable and is in [\"preview\"](faq.md#what-is-preview)."
@@ -132,7 +124,8 @@ pub(crate) fn generate() -> String {
132124
&mut table_out,
133125
"{SPACER}{FIX_SYMBOL}{SPACER} The rule is automatically fixable by the `--fix` command-line option."
134126
);
135-
table_out.push_str("<br />");
127+
table_out.push_str("\n\n");
128+
table_out.push_str("All rules not marked as preview, deprecated or removed are stable.");
136129
table_out.push('\n');
137130

138131
for linter in Linter::iter() {

0 commit comments

Comments
 (0)