refactor: Reduce code duplication

This commit is contained in:
Martin Fischer 2023-02-10 09:32:31 +01:00 committed by Charlie Marsh
parent 9011456aa1
commit 6f16f1c39b
2 changed files with 43 additions and 69 deletions

View file

@ -34,25 +34,18 @@ fn generate_table(table_out: &mut String, rules: impl IntoIterator<Item = Rule>)
Some(_) => "🛠",
};
if rule.explanation().is_some() {
table_out.push_str(&format!(
"| {} | [{}]({}/{}.md) | {} | {} |",
rule.code(),
rule.as_ref(),
URL_PREFIX,
rule.as_ref(),
rule.message_formats()[0].replace('|', r"\|"),
fix_token
));
} else {
table_out.push_str(&format!(
"| {} | {} | {} | {} |",
rule.code(),
rule.as_ref(),
rule.message_formats()[0].replace('|', r"\|"),
fix_token
));
}
let rule_name = rule.as_ref();
table_out.push_str(&format!(
"| {} | {} | {} | {} |",
rule.code(),
rule.explanation()
.is_some()
.then_some(format_args!("[{rule_name}]({URL_PREFIX}/{rule_name}.md)",))
.unwrap_or(format_args!("{rule_name}")),
rule.message_formats()[0].replace('|', r"\|"),
fix_token
));
table_out.push('\n');
}
table_out.push('\n');