Skip to main content

frs/cmds/rsl/output/format/
nonadjacent_impl.rs

1use super::super::ViolationOutputFormat;
2use super::FormattedRuleViolation;
3use super::format_violation;
4use crate::cmds::rsl::rules::TypedRule;
5use crate::cmds::rsl::rules::nonadjacent_impl::NonadjacentImplRule;
6use crate::cmds::rsl::rules::nonadjacent_impl::NonadjacentImplViolation;
7
8impl FormattedRuleViolation for NonadjacentImplViolation {
9    fn format(&self, output_format: ViolationOutputFormat) -> String {
10        format_violation(
11            &self.location,
12            <NonadjacentImplRule as TypedRule>::code(),
13            &format!(
14                "move `{}` after `{}`",
15                self.details.item.label(),
16                self.details.expected_after
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::ItemKind;
30    use crate::cmds::rsl::rules::common::Location;
31    use crate::cmds::rsl::rules::nonadjacent_impl::NonadjacentImplDetails;
32    use crate::cmds::rsl::rules::nonadjacent_impl::NonadjacentImplViolation;
33
34    #[test]
35    fn test_nonadjacent_impl_violation_when_details_are_present_formats_compact_output() {
36        let violation = NonadjacentImplViolation {
37            location: Location::new(PathBuf::from("test.rs"), 4, 13),
38            details: NonadjacentImplDetails {
39                expected_after: "struct Data".to_owned(),
40                item: ItemKind::Impl,
41            },
42        };
43
44        assert_eq!(
45            FormattedRuleViolation::format(&violation, ViolationOutputFormat::Compact),
46            "test.rs:4:13,move `impl` after `struct Data`"
47        );
48    }
49}