frs/cmds/rsl/output/format/
misordered_item_group.rs1use super::super::ViolationOutputFormat;
2use super::FormattedRuleViolation;
3use super::format_violation;
4use crate::cmds::rsl::rules::TypedRule;
5use crate::cmds::rsl::rules::misordered_item_group::MisorderedItemGroupRule;
6use crate::cmds::rsl::rules::misordered_item_group::MisorderedItemGroupViolation;
7
8impl FormattedRuleViolation for MisorderedItemGroupViolation {
9 fn format(&self, output_format: ViolationOutputFormat) -> String {
10 format_violation(
11 &self.location,
12 <MisorderedItemGroupRule as TypedRule>::code(),
13 &format!(
14 "move `{}` after `{}`",
15 self.details.item.label(),
16 self.details.expected_group
17 ),
18 output_format,
19 )
20 }
21}
22
23#[cfg(test)]
24mod tests {
25 use std::path::PathBuf;
26
27 use super::super::super::ViolationOutputFormat;
28 use super::super::FormattedRuleViolation;
29 use crate::cmds::rsl::ast::ItemGroup;
30 use crate::cmds::rsl::ast::ItemKind;
31 use crate::cmds::rsl::rules::common::Location;
32 use crate::cmds::rsl::rules::misordered_item_group::MisorderedItemGroupDetails;
33 use crate::cmds::rsl::rules::misordered_item_group::MisorderedItemGroupViolation;
34
35 #[test]
36 fn test_misordered_item_group_violation_when_details_are_present_formats_compact_output() {
37 let violation = MisorderedItemGroupViolation {
38 location: Location::new(PathBuf::from("test.rs"), 4, 13),
39 details: MisorderedItemGroupDetails {
40 expected_group: ItemGroup::Items,
41 item: ItemKind::Const,
42 },
43 };
44
45 assert_eq!(
46 FormattedRuleViolation::format(&violation, ViolationOutputFormat::Compact),
47 "test.rs:4:13,move `const` after `items`"
48 );
49 }
50}