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] [lints.clippy]
all = { level = "deny", priority = -1 } all = { level = "deny", priority = -1 }
arbitrary-source-item-ordering = "deny"
enum_glob_use = "allow" enum_glob_use = "allow"
needless_pass_by_value = "allow" needless_pass_by_value = "allow"
pedantic = { level = "deny", priority = -1 } pedantic = { level = "deny", priority = -1 }

View file

@ -1 +1,2 @@
cognitive-complexity-threshold = 1337 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> { pub(crate) struct AssignmentResolver<'src: 'run, 'run> {
assignments: &'run Table<'src, Assignment<'src>>, assignments: &'run Table<'src, Assignment<'src>>,
stack: Vec<&'src str>,
evaluated: BTreeSet<&'src str>, evaluated: BTreeSet<&'src str>,
stack: Vec<&'src str>,
} }
impl<'src: 'run, 'run> AssignmentResolver<'src, 'run> { impl<'src: 'run, 'run> AssignmentResolver<'src, 'run> {

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,6 +1,9 @@
use super::*; use super::*;
pub(crate) trait PlatformInterface { 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 /// Construct a command equivalent to running the script at `path` with the
/// shebang line `shebang` /// shebang line `shebang`
fn make_shebang_command( 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 /// Extract the signal from a process exit status, if it was terminated by a
/// signal /// signal
fn signal_from_exit_status(exit_status: ExitStatus) -> Option<i32>; 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 /// Source position
#[derive(Copy, Clone, PartialEq, Debug)] #[derive(Copy, Clone, PartialEq, Debug)]
pub(crate) struct Position { pub(crate) struct Position {
pub(crate) offset: usize,
pub(crate) column: usize, pub(crate) column: usize,
pub(crate) line: usize, pub(crate) line: usize,
pub(crate) offset: usize,
} }

View file

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

View file

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

View file

@ -1,9 +1,9 @@
use {super::*, CompileErrorKind::*}; use {super::*, CompileErrorKind::*};
pub(crate) struct RecipeResolver<'src: 'run, 'run> { 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>>, 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> { impl<'src: 'run, 'run> RecipeResolver<'src, 'run> {

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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