Skip to main content

stern4rust/finding/model/
section.rs

1// Copyright 2025 Umberto Gotti <umberto.gotti@umbertogotti.dev>
2// Licensed under the MIT License
3// SPDX-License-Identifier: MIT
4
5// The four groups a test file is made of, in the order they appear.
6//
7// Helpers are defined by exclusion -- whatever is neither an import, nor a
8// constant, nor a test. That is what makes the set closed: a `struct`, an
9// `impl`, a type alias and a plain `fn` are all helpers, so a new kind of item
10// lands somewhere sensible without the rule needing to learn about it.
11#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
12pub enum Section {
13    Imports,
14    Constants,
15    Helpers,
16    Tests,
17}
18
19impl Section {
20    // Reads as the thing itself, so an offence says "a constant follows a
21    // helper" rather than naming an enum variant at the reader.
22    pub fn label(self) -> &'static str {
23        match self {
24            Self::Imports => "import",
25            Self::Constants => "constant",
26            Self::Helpers => "helper",
27            Self::Tests => "test",
28        }
29    }
30
31    // Imports are the one group written without gaps. Everything else is
32    // separated by exactly one blank line.
33    pub fn blank_lines_between_entries(self) -> usize {
34        match self {
35            Self::Imports => 0,
36            _ => 1,
37        }
38    }
39}