diff --git a/Cargo.toml b/Cargo.toml index ac04aabe..2d24bc83 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 } diff --git a/clippy.toml b/clippy.toml index 0d0ff26c..2986cbed 100644 --- a/clippy.toml +++ b/clippy.toml @@ -1 +1,2 @@ cognitive-complexity-threshold = 1337 +source-item-ordering = ['enum', 'struct', 'trait'] diff --git a/src/assignment_resolver.rs b/src/assignment_resolver.rs index 511464d4..bdcd2c96 100644 --- a/src/assignment_resolver.rs +++ b/src/assignment_resolver.rs @@ -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> { diff --git a/src/compile_error.rs b/src/compile_error.rs index 2bc77361..750d72f5 100644 --- a/src/compile_error.rs +++ b/src/compile_error.rs @@ -2,8 +2,8 @@ use super::*; #[derive(Debug, PartialEq)] pub(crate) struct CompileError<'src> { - pub(crate) token: Token<'src>, pub(crate) kind: Box>, + pub(crate) token: Token<'src>, } impl<'src> CompileError<'src> { diff --git a/src/compile_error_kind.rs b/src/compile_error_kind.rs index 0de1da29..cd42c41a 100644 --- a/src/compile_error_kind.rs +++ b/src/compile_error_kind.rs @@ -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, }, diff --git a/src/condition.rs b/src/condition.rs index 8ab31f71..6eb21631 100644 --- a/src/condition.rs +++ b/src/condition.rs @@ -3,8 +3,8 @@ use super::*; #[derive(PartialEq, Debug, Clone)] pub(crate) struct Condition<'src> { pub(crate) lhs: Box>, - pub(crate) rhs: Box>, pub(crate) operator: ConditionalOperator, + pub(crate) rhs: Box>, } impl Display for Condition<'_> { diff --git a/src/error.rs b/src/error.rs index a07c4efd..668f16a7 100644 --- a/src/error.rs +++ b/src/error.rs @@ -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, }, - UnknownSubmodule { - path: String, - }, UnknownOverrides { overrides: Vec, }, @@ -182,6 +179,9 @@ pub(crate) enum Error<'src> { recipe: String, suggestion: Option>, }, + UnknownSubmodule { + path: String, + }, UnstableFeature { unstable_feature: UnstableFeature, }, diff --git a/src/fragment.rs b/src/fragment.rs index a6aa316a..fb097381 100644 --- a/src/fragment.rs +++ b/src/fragment.rs @@ -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<'_> { diff --git a/src/function.rs b/src/function.rs index 4852f407..7fd0fcf8 100644 --- a/src/function.rs +++ b/src/function.rs @@ -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), diff --git a/src/justfile.rs b/src/justfile.rs index 2ce96ece..342a6109 100644 --- a/src/justfile.rs +++ b/src/justfile.rs @@ -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, #[serde(rename = "first", serialize_with = "keyed::serialize_option")] pub(crate) default: Option>>, + pub(crate) doc: Option, + pub(crate) groups: Vec, #[serde(skip)] pub(crate) loaded: Vec, - pub(crate) groups: Vec, pub(crate) modules: Table<'src, Justfile<'src>>, #[serde(skip)] pub(crate) name: Option>, diff --git a/src/lexer.rs b/src/lexer.rs index 3efdad2b..24661520 100644 --- a/src/lexer.rs +++ b/src/lexer.rs @@ -27,12 +27,12 @@ pub(crate) struct Lexer<'src> { recipe_body_pending: bool, /// Source text src: &'src str, - /// Tokens - tokens: Vec>, /// Current token end token_end: Position, /// Current token start token_start: Position, + /// Tokens + tokens: Vec>, } 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::*; diff --git a/src/loader.rs b/src/loader.rs index ccc8a45c..1d543c13 100644 --- a/src/loader.rs +++ b/src/loader.rs @@ -1,8 +1,8 @@ use super::*; pub(crate) struct Loader { - srcs: Arena, paths: Arena, + srcs: Arena, } impl Loader { diff --git a/src/parameter_kind.rs b/src/parameter_kind.rs index cc49cba4..f16e0517 100644 --- a/src/parameter_kind.rs +++ b/src/parameter_kind.rs @@ -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, } diff --git a/src/parser.rs b/src/parser.rs index 6a10523a..1767ef9b 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -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 }, } diff --git a/src/platform_interface.rs b/src/platform_interface.rs index 463f6650..573d6abb 100644 --- a/src/platform_interface.rs +++ b/src/platform_interface.rs @@ -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; - - /// Translate a path from a "native" path to a path the interpreter expects - fn convert_native_path(working_directory: &Path, path: &Path) -> FunctionResult; } diff --git a/src/position.rs b/src/position.rs index face629b..bf50f173 100644 --- a/src/position.rs +++ b/src/position.rs @@ -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, } diff --git a/src/positional.rs b/src/positional.rs index a74a4740..2db8ffee 100644 --- a/src/positional.rs +++ b/src/positional.rs @@ -28,12 +28,12 @@ use super::*; /// prepended to rest. #[cfg_attr(test, derive(PartialEq, Eq, Debug))] pub struct Positional { + /// Everything else + pub arguments: Vec, /// 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, - /// Everything else - pub arguments: Vec, } impl Positional { @@ -67,9 +67,9 @@ impl Positional { } Self { + arguments, overrides, search_directory, - arguments, } } diff --git a/src/range_ext.rs b/src/range_ext.rs index 4773d22b..45aee38d 100644 --- a/src/range_ext.rs +++ b/src/range_ext.rs @@ -1,11 +1,11 @@ use super::*; pub(crate) trait RangeExt { - 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); diff --git a/src/recipe_resolver.rs b/src/recipe_resolver.rs index 936b76ed..9a962aad 100644 --- a/src/recipe_resolver.rs +++ b/src/recipe_resolver.rs @@ -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>>, assignments: &'run Table<'src, Assignment<'src>>, + resolved_recipes: Table<'src, Rc>>, + unresolved_recipes: Table<'src, UnresolvedRecipe<'src>>, } impl<'src: 'run, 'run> RecipeResolver<'src, 'run> { diff --git a/src/scope.rs b/src/scope.rs index 78d12ca0..1aac919c 100644 --- a/src/scope.rs +++ b/src/scope.rs @@ -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> { diff --git a/src/shebang.rs b/src/shebang.rs index 0fc03862..539785ed 100644 --- a/src/shebang.rs +++ b/src/shebang.rs @@ -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, }) } diff --git a/src/summary.rs b/src/summary.rs index 79adaba4..e9841daa 100644 --- a/src/summary.rs +++ b/src/summary.rs @@ -80,31 +80,31 @@ pub struct Recipe { pub aliases: Vec, pub dependencies: Vec, pub lines: Vec, + pub parameters: Vec, pub private: bool, pub quiet: bool, pub shebang: bool, - pub parameters: Vec, } impl Recipe { fn new(recipe: &full::Recipe, aliases: Vec) -> 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, pub kind: ParameterKind, pub name: String, - pub default: Option, } 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, - rhs: Box, operator: ConditionalOperator, + rhs: Box, } #[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, + pub recipe: String, } impl Dependency { diff --git a/src/thunk.rs b/src/thunk.rs index 0da9c855..df17dec0 100644 --- a/src/thunk.rs +++ b/src/thunk.rs @@ -1,5 +1,6 @@ use super::*; +#[allow(clippy::arbitrary_source_item_ordering)] #[derive_where(Debug, PartialEq)] #[derive(Clone)] pub(crate) enum Thunk<'src> { diff --git a/src/unresolved_dependency.rs b/src/unresolved_dependency.rs index 5f600ce3..b7172f52 100644 --- a/src/unresolved_dependency.rs +++ b/src/unresolved_dependency.rs @@ -2,8 +2,8 @@ use super::*; #[derive(PartialEq, Debug, Clone)] pub(crate) struct UnresolvedDependency<'src> { - pub(crate) recipe: Name<'src>, pub(crate) arguments: Vec>, + pub(crate) recipe: Name<'src>, } impl Display for UnresolvedDependency<'_> { diff --git a/src/use_color.rs b/src/use_color.rs index 8086989a..808eae1e 100644 --- a/src/use_color.rs +++ b/src/use_color.rs @@ -2,7 +2,7 @@ use super::*; #[derive(Copy, Clone, Debug, PartialEq, ValueEnum)] pub(crate) enum UseColor { - Auto, Always, + Auto, Never, } diff --git a/src/verbosity.rs b/src/verbosity.rs index f3ba3e45..65db6952 100644 --- a/src/verbosity.rs +++ b/src/verbosity.rs @@ -1,3 +1,4 @@ +#[allow(clippy::arbitrary_source_item_ordering)] #[derive(Copy, Clone, Debug, PartialEq, PartialOrd)] pub(crate) enum Verbosity { Quiet, diff --git a/tests/json.rs b/tests/json.rs index d7a1a1c3..30f713be 100644 --- a/tests/json.rs +++ b/tests/json.rs @@ -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)]