Sort enum variant, struct member, and trait members alphabetically (#2646)

This commit is contained in:
Casey Rodarmor 2025-03-01 12:35:01 -08:00 committed by GitHub
parent 5a2b4554f4
commit 5d36e8fb74
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
27 changed files with 63 additions and 58 deletions

View file

@ -65,6 +65,7 @@ unexpected_cfgs = { level = "warn", check-cfg = ['cfg(fuzzing)'] }
[lints.clippy]
all = { level = "deny", priority = -1 }
arbitrary-source-item-ordering = "deny"
enum_glob_use = "allow"
needless_pass_by_value = "allow"
pedantic = { level = "deny", priority = -1 }

View file

@ -1 +1,2 @@
cognitive-complexity-threshold = 1337
source-item-ordering = ['enum', 'struct', 'trait']

View file

@ -2,8 +2,8 @@ use {super::*, CompileErrorKind::*};
pub(crate) struct AssignmentResolver<'src: 'run, 'run> {
assignments: &'run Table<'src, Assignment<'src>>,
stack: Vec<&'src str>,
evaluated: BTreeSet<&'src str>,
stack: Vec<&'src str>,
}
impl<'src: 'run, 'run> AssignmentResolver<'src, 'run> {

View file

@ -2,8 +2,8 @@ use super::*;
#[derive(Debug, PartialEq)]
pub(crate) struct CompileError<'src> {
pub(crate) token: Token<'src>,
pub(crate) kind: Box<CompileErrorKind<'src>>,
pub(crate) token: Token<'src>,
}
impl<'src> CompileError<'src> {

View file

@ -23,12 +23,6 @@ pub(crate) enum CompileErrorKind<'src> {
min: usize,
max: usize,
},
Redefinition {
first: usize,
first_type: &'static str,
name: &'src str,
second_type: &'static str,
},
DuplicateAttribute {
attribute: &'src str,
first: usize,
@ -41,10 +35,10 @@ pub(crate) enum CompileErrorKind<'src> {
setting: &'src str,
first: usize,
},
DuplicateVariable {
DuplicateUnexport {
variable: &'src str,
},
DuplicateUnexport {
DuplicateVariable {
variable: &'src str,
},
ExitMessageAndNoExitMessageAttribute {
@ -97,6 +91,12 @@ pub(crate) enum CompileErrorKind<'src> {
parameter: &'src str,
},
ParsingRecursionDepthExceeded,
Redefinition {
first: usize,
first_type: &'static str,
name: &'src str,
second_type: &'static str,
},
RequiredParameterFollowsDefaultParameter {
parameter: &'src str,
},

View file

@ -3,8 +3,8 @@ use super::*;
#[derive(PartialEq, Debug, Clone)]
pub(crate) struct Condition<'src> {
pub(crate) lhs: Box<Expression<'src>>,
pub(crate) rhs: Box<Expression<'src>>,
pub(crate) operator: ConditionalOperator,
pub(crate) rhs: Box<Expression<'src>>,
}
impl Display for Condition<'_> {

View file

@ -20,10 +20,6 @@ pub(crate) enum Error<'src> {
token: Token<'src>,
output_error: OutputError,
},
RuntimeDirIo {
io_error: io::Error,
path: PathBuf,
},
ChooserInvoke {
shell_binary: String,
shell_arguments: String,
@ -139,6 +135,10 @@ pub(crate) enum Error<'src> {
RegexCompile {
source: regex::Error,
},
RuntimeDirIo {
io_error: io::Error,
path: PathBuf,
},
Script {
command: String,
io_error: io::Error,
@ -172,9 +172,6 @@ pub(crate) enum Error<'src> {
recipe: &'src str,
line_number: Option<usize>,
},
UnknownSubmodule {
path: String,
},
UnknownOverrides {
overrides: Vec<String>,
},
@ -182,6 +179,9 @@ pub(crate) enum Error<'src> {
recipe: String,
suggestion: Option<Suggestion<'src>>,
},
UnknownSubmodule {
path: String,
},
UnstableFeature {
unstable_feature: UnstableFeature,
},

View file

@ -3,10 +3,10 @@ use super::*;
/// A line fragment consisting either of…
#[derive(PartialEq, Debug, Clone)]
pub(crate) enum Fragment<'src> {
/// …raw text…
Text { token: Token<'src> },
/// …an interpolation containing `expression`.
Interpolation { expression: Expression<'src> },
/// …raw text…
Text { token: Token<'src> },
}
impl Serialize for Fragment<'_> {

View file

@ -10,6 +10,7 @@ use {
Function::*,
};
#[allow(clippy::arbitrary_source_item_ordering)]
pub(crate) enum Function {
Nullary(fn(Context) -> FunctionResult),
Unary(fn(Context, &str) -> FunctionResult),

View file

@ -12,12 +12,12 @@ struct Invocation<'src: 'run, 'run> {
pub(crate) struct Justfile<'src> {
pub(crate) aliases: Table<'src, Alias<'src>>,
pub(crate) assignments: Table<'src, Assignment<'src>>,
pub(crate) doc: Option<String>,
#[serde(rename = "first", serialize_with = "keyed::serialize_option")]
pub(crate) default: Option<Rc<Recipe<'src>>>,
pub(crate) doc: Option<String>,
pub(crate) groups: Vec<String>,
#[serde(skip)]
pub(crate) loaded: Vec<PathBuf>,
pub(crate) groups: Vec<String>,
pub(crate) modules: Table<'src, Justfile<'src>>,
#[serde(skip)]
pub(crate) name: Option<Name<'src>>,

View file

@ -27,12 +27,12 @@ pub(crate) struct Lexer<'src> {
recipe_body_pending: bool,
/// Source text
src: &'src str,
/// Tokens
tokens: Vec<Token<'src>>,
/// Current token end
token_end: Position,
/// Current token start
token_start: Position,
/// Tokens
tokens: Vec<Token<'src>>,
}
impl<'src> Lexer<'src> {
@ -540,10 +540,10 @@ impl<'src> Lexer<'src> {
/// Lex token while in recipe body
fn lex_body(&mut self) -> CompileResult<'src> {
enum Terminator {
EndOfFile,
Interpolation,
Newline,
NewlineCarriageReturn,
Interpolation,
EndOfFile,
}
use Terminator::*;

View file

@ -1,8 +1,8 @@
use super::*;
pub(crate) struct Loader {
srcs: Arena<String>,
paths: Arena<PathBuf>,
srcs: Arena<String>,
}
impl Loader {

View file

@ -4,10 +4,10 @@ use super::*;
#[derive(Debug, Copy, Clone, Eq, PartialEq, Serialize)]
#[serde(rename_all = "snake_case")]
pub(crate) enum ParameterKind {
/// …singular, accepting a single argument
Singular,
/// …variadic, accepting one or more arguments
Plus,
/// …singular, accepting a single argument
Singular,
/// …variadic, accepting zero or more arguments
Star,
}

View file

@ -282,7 +282,7 @@ impl<'run, 'src> Parser<'run, 'src> {
arguments.push(self.parse_expression()?);
}
Ok(Some(UnresolvedDependency { recipe, arguments }))
Ok(Some(UnresolvedDependency { arguments, recipe }))
} else {
Ok(None)
}
@ -774,8 +774,8 @@ impl<'run, 'src> Parser<'run, 'src> {
fn cook_string(token: Token<'src>, text: &str) -> CompileResult<'src, String> {
#[derive(PartialEq, Eq)]
enum State {
Initial,
Backslash,
Initial,
Unicode,
UnicodeValue { hex: String },
}

View file

@ -1,6 +1,9 @@
use super::*;
pub(crate) trait PlatformInterface {
/// Translate a path from a "native" path to a path the interpreter expects
fn convert_native_path(working_directory: &Path, path: &Path) -> FunctionResult;
/// Construct a command equivalent to running the script at `path` with the
/// shebang line `shebang`
fn make_shebang_command(
@ -15,7 +18,4 @@ pub(crate) trait PlatformInterface {
/// Extract the signal from a process exit status, if it was terminated by a
/// signal
fn signal_from_exit_status(exit_status: ExitStatus) -> Option<i32>;
/// Translate a path from a "native" path to a path the interpreter expects
fn convert_native_path(working_directory: &Path, path: &Path) -> FunctionResult;
}

View file

@ -1,7 +1,7 @@
/// Source position
#[derive(Copy, Clone, PartialEq, Debug)]
pub(crate) struct Position {
pub(crate) offset: usize,
pub(crate) column: usize,
pub(crate) line: usize,
pub(crate) offset: usize,
}

View file

@ -28,12 +28,12 @@ use super::*;
/// prepended to rest.
#[cfg_attr(test, derive(PartialEq, Eq, Debug))]
pub struct Positional {
/// Everything else
pub arguments: Vec<String>,
/// Overrides from values of the form `[a-zA-Z_][a-zA-Z0-9_-]*=.*`
pub overrides: Vec<(String, String)>,
/// An argument equal to '.', '..', or ending with `/`
pub search_directory: Option<String>,
/// Everything else
pub arguments: Vec<String>,
}
impl Positional {
@ -67,9 +67,9 @@ impl Positional {
}
Self {
arguments,
overrides,
search_directory,
arguments,
}
}

View file

@ -1,11 +1,11 @@
use super::*;
pub(crate) trait RangeExt<T> {
fn range_contains(&self, i: &T) -> bool;
fn display(&self) -> DisplayRange<&Self> {
DisplayRange(self)
}
fn range_contains(&self, i: &T) -> bool;
}
pub(crate) struct DisplayRange<T>(T);

View file

@ -1,9 +1,9 @@
use {super::*, CompileErrorKind::*};
pub(crate) struct RecipeResolver<'src: 'run, 'run> {
unresolved_recipes: Table<'src, UnresolvedRecipe<'src>>,
resolved_recipes: Table<'src, Rc<Recipe<'src>>>,
assignments: &'run Table<'src, Assignment<'src>>,
resolved_recipes: Table<'src, Rc<Recipe<'src>>>,
unresolved_recipes: Table<'src, UnresolvedRecipe<'src>>,
}
impl<'src: 'run, 'run> RecipeResolver<'src, 'run> {

View file

@ -2,8 +2,8 @@ use super::*;
#[derive(Debug)]
pub(crate) struct Scope<'src: 'run, 'run> {
parent: Option<&'run Self>,
bindings: Table<'src, Binding<'src, String>>,
parent: Option<&'run Self>,
}
impl<'src, 'run> Scope<'src, 'run> {

View file

@ -1,7 +1,7 @@
#[derive(Copy, Clone)]
pub(crate) struct Shebang<'line> {
pub(crate) interpreter: &'line str,
pub(crate) argument: Option<&'line str>,
pub(crate) interpreter: &'line str,
}
impl<'line> Shebang<'line> {
@ -25,8 +25,8 @@ impl<'line> Shebang<'line> {
}
Some(Self {
interpreter,
argument,
interpreter,
})
}

View file

@ -80,31 +80,31 @@ pub struct Recipe {
pub aliases: Vec<String>,
pub dependencies: Vec<Dependency>,
pub lines: Vec<Line>,
pub parameters: Vec<Parameter>,
pub private: bool,
pub quiet: bool,
pub shebang: bool,
pub parameters: Vec<Parameter>,
}
impl Recipe {
fn new(recipe: &full::Recipe, aliases: Vec<String>) -> Self {
Self {
private: recipe.private,
shebang: recipe.shebang,
quiet: recipe.quiet,
aliases,
dependencies: recipe.dependencies.iter().map(Dependency::new).collect(),
lines: recipe.body.iter().map(Line::new).collect(),
parameters: recipe.parameters.iter().map(Parameter::new).collect(),
aliases,
private: recipe.private,
quiet: recipe.quiet,
shebang: recipe.shebang,
}
}
}
#[derive(Eq, PartialEq, Hash, Ord, PartialOrd, Debug, Clone)]
pub struct Parameter {
pub default: Option<Expression>,
pub kind: ParameterKind,
pub name: String,
pub default: Option<Expression>,
}
impl Parameter {
@ -119,8 +119,8 @@ impl Parameter {
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Ord, PartialOrd)]
pub enum ParameterKind {
Singular,
Plus,
Singular,
Star,
}
@ -149,8 +149,8 @@ impl Line {
#[derive(Eq, PartialEq, Hash, Ord, PartialOrd, Debug, Clone)]
pub enum Fragment {
Text { text: String },
Expression { expression: Expression },
Text { text: String },
}
impl Fragment {
@ -351,8 +351,8 @@ impl Expression {
#[derive(Eq, PartialEq, Hash, Ord, PartialOrd, Debug, Clone)]
pub struct Condition {
lhs: Box<Expression>,
rhs: Box<Expression>,
operator: ConditionalOperator,
rhs: Box<Expression>,
}
#[derive(Eq, PartialEq, Hash, Ord, PartialOrd, Debug, Clone)]
@ -376,8 +376,8 @@ impl ConditionalOperator {
#[derive(Eq, PartialEq, Hash, Ord, PartialOrd, Debug, Clone)]
pub struct Dependency {
pub recipe: String,
pub arguments: Vec<Expression>,
pub recipe: String,
}
impl Dependency {

View file

@ -1,5 +1,6 @@
use super::*;
#[allow(clippy::arbitrary_source_item_ordering)]
#[derive_where(Debug, PartialEq)]
#[derive(Clone)]
pub(crate) enum Thunk<'src> {

View file

@ -2,8 +2,8 @@ use super::*;
#[derive(PartialEq, Debug, Clone)]
pub(crate) struct UnresolvedDependency<'src> {
pub(crate) recipe: Name<'src>,
pub(crate) arguments: Vec<Expression<'src>>,
pub(crate) recipe: Name<'src>,
}
impl Display for UnresolvedDependency<'_> {

View file

@ -2,7 +2,7 @@ use super::*;
#[derive(Copy, Clone, Debug, PartialEq, ValueEnum)]
pub(crate) enum UseColor {
Auto,
Always,
Auto,
Never,
}

View file

@ -1,3 +1,4 @@
#[allow(clippy::arbitrary_source_item_ordering)]
#[derive(Copy, Clone, Debug, PartialEq, PartialOrd)]
pub(crate) enum Verbosity {
Quiet,

View file

@ -42,9 +42,9 @@ struct Module<'a> {
modules: BTreeMap<&'a str, Module<'a>>,
recipes: BTreeMap<&'a str, Recipe<'a>>,
settings: Settings<'a>,
source: PathBuf,
unexports: Vec<&'a str>,
warnings: Vec<&'a str>,
source: PathBuf,
}
#[derive(Debug, Default, Deserialize, PartialEq, Serialize)]