Skip to content

Commit

Permalink
chore: updates rustfmt to use version = "Two"
Browse files Browse the repository at this point in the history
  • Loading branch information
claymcleod committed Dec 17, 2023
1 parent e2436ce commit f63c188
Show file tree
Hide file tree
Showing 48 changed files with 212 additions and 115 deletions.
15 changes: 14 additions & 1 deletion rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
# Unstable settings
condense_wildcard_suffixes = true
format_code_in_doc_comments = true
group_imports = "StdExternalCrate"
format_macro_matchers = true
format_strings = true
group_imports = "StdExternalCrate"
hex_literal_case = "Upper"
imports_granularity = "Item"
newline_style = "Unix"
normalize_comments = true
normalize_doc_attributes = true
reorder_impl_items = true
use_field_init_shorthand = true
wrap_comments = true
version = "Two"
4 changes: 2 additions & 2 deletions wdl-ast/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ pub mod v1;
pub enum Error {
/// An error occurred while linting a parse tree.
///
/// **Note:** this is not a lint _warning_! A lint error is an unrecoverable
/// error that occurs during the process of linting.
/// **Note:** this is not a lint _warning_! A lint error is an
/// unrecoverable error that occurs during the process of linting.
Lint(Box<dyn std::error::Error>),

/// An error occurred while parsing a WDL v1.x abstract syntax tree.
Expand Down
4 changes: 2 additions & 2 deletions wdl-ast/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ struct Args {
#[arg(short, long, global = true)]
quiet: bool,

/// All available information, including trace information, is logged in the
/// console.
/// All available information, including trace information, is logged in
/// the console.
#[arg(short, long, global = true)]
trace: bool,

Expand Down
12 changes: 9 additions & 3 deletions wdl-ast/src/v1/document/declaration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@ pub enum Error {
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Error::BoundDeclaration(err) => write!(f, "bound declaration error: {err}"),
Error::UnboundDeclaration(err) => write!(f, "unbound declaration error: {err}"),
Error::BoundDeclaration(err) => {
write!(f, "bound declaration error: {err}")
}
Error::UnboundDeclaration(err) => {
write!(f, "unbound declaration error: {err}")
}
}
}
}
Expand Down Expand Up @@ -367,7 +371,9 @@ impl TryFrom<Pair<'_, grammar::v1::Rule>> for Declaration {
unbound::Declaration::try_from(node).map_err(Error::UnboundDeclaration)?;
Ok(Declaration::Unbound(declaration))
}
rule => panic!("declaration cannot be parsed from node type {:?}", rule),
rule => {
panic!("declaration cannot be parsed from node type {:?}", rule)
}
}
}
}
9 changes: 6 additions & 3 deletions wdl-ast/src/v1/document/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ mod r#struct;
mod unary_signed;

pub use array::Array;
pub use r#if::If;
pub use literal::Literal;
pub use map::Map;
pub use object::Object;
pub use pair::Pair;
pub use r#if::If;
pub use r#struct::Struct;
pub use unary_signed::UnarySigned;

Expand Down Expand Up @@ -232,7 +232,9 @@ fn parse<'a, P: Iterator<Item = pest::iterators::Pair<'a, grammar::v1::Rule>>>(
Rule::boolean => match node.as_str() {
"true" => Ok(Expression::Literal(Literal::Boolean(true))),
"false" => Ok(Expression::Literal(Literal::Boolean(false))),
value => unreachable!("unknown boolean literal value: {}", value),
value => {
unreachable!("unknown boolean literal value: {}", value)
}
},
Rule::integer => Ok(Expression::Literal(Literal::Integer(
node.as_str().parse::<i64>().map_err(Error::ParseInt)?,
Expand Down Expand Up @@ -313,7 +315,8 @@ impl TryFrom<pest::iterators::Pair<'_, grammar::v1::Rule>> for Expression {
}
}

/// Ensures that an expression is a number. This includes floats and integers that are wrapped in
/// Ensures that an expression is a number. This includes floats and integers
/// that are wrapped in
pub fn ensure_number(expr: &Expression) -> Option<&Expression> {
match expr {
Expression::Literal(Literal::Float(_)) => Some(expr),
Expand Down
4 changes: 3 additions & 1 deletion wdl-ast/src/v1/document/expression/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ impl TryFrom<Pair<'_, grammar::v1::Rule>> for Map {
Rule::WHITESPACE => {}
Rule::COMMA => {}
Rule::COMMENT => {}
rule => unreachable!("map literals should not contain {:?}", rule),
rule => {
unreachable!("map literals should not contain {:?}", rule)
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion wdl-ast/src/v1/document/expression/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ impl TryFrom<Pair<'_, Rule>> for Object {
Rule::COMMA => {}
Rule::COMMENT => {}
Rule::WHITESPACE => {}
rule => unreachable!("object literal should not contain {:?}", rule),
rule => {
unreachable!("object literal should not contain {:?}", rule)
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion wdl-ast/src/v1/document/expression/struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,9 @@ impl TryFrom<Pair<'_, Rule>> for Struct {
Rule::COMMA => {}
Rule::COMMENT => {}
Rule::WHITESPACE => {}
rule => unreachable!("struct literal should not contain {:?}", rule),
rule => {
unreachable!("struct literal should not contain {:?}", rule)
}
}
}

Expand Down
12 changes: 9 additions & 3 deletions wdl-ast/src/v1/document/identifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ pub enum Error {
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Error::Qualified(err) => write!(f, "qualified identifier error: {err}"),
Error::Singular(err) => write!(f, "singular identifier error: {err}"),
Error::Qualified(err) => {
write!(f, "qualified identifier error: {err}")
}
Error::Singular(err) => {
write!(f, "singular identifier error: {err}")
}
}
}
}
Expand Down Expand Up @@ -199,7 +203,9 @@ impl TryFrom<Pair<'_, grammar::v1::Rule>> for Identifier {
let identifier = qualified::Identifier::try_from(node).map_err(Error::Qualified)?;
Ok(Identifier::Qualified(identifier))
}
node => panic!("identifier cannot be parsed from node type {:?}", node),
node => {
panic!("identifier cannot be parsed from node type {:?}", node)
}
}
}
}
Expand Down
12 changes: 9 additions & 3 deletions wdl-ast/src/v1/document/identifier/qualified.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ pub enum Error {
/// A singular identifier error.
///
/// Generally speaking, this error will be returned if there is any issue
/// parsing the singular identifiers that comprise the qualified identifier.
/// parsing the singular identifiers that comprise the qualified
/// identifier.
Singular(singular::Error),
}

Expand All @@ -32,7 +33,9 @@ impl std::fmt::Display for Error {
Error::InvalidFormat(value, reason) => {
write!(f, "invalid format for \"{value}\": {reason}")
}
Error::Singular(err) => write!(f, "singular identifier error: {err}"),
Error::Singular(err) => {
write!(f, "singular identifier error: {err}")
}
}
}
}
Expand Down Expand Up @@ -183,7 +186,10 @@ mod tests {
let err = Identifier::try_from("hello_world").unwrap_err();
assert_eq!(
err.to_string(),
String::from("invalid format for \"hello_world\": cannot create qualified identifier with no scope")
String::from(
"invalid format for \"hello_world\": cannot create qualified identifier with no \
scope"
)
);

Ok(())
Expand Down
6 changes: 3 additions & 3 deletions wdl-ast/src/v1/document/identifier/singular.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ type Result<T> = std::result::Result<T, Error>;

/// A singular identifier.
///
/// An [`Identifier`] must match the pattern `^[a-zA-Z][a-zA-Z0-9_]*$`. If an ones
/// attempts to create an [`Identifier`] that does not match this pattern, an
/// [`Error::InvalidFormat`] is returned.
/// An [`Identifier`] must match the pattern `^[a-zA-Z][a-zA-Z0-9_]*$`. If an
/// ones attempts to create an [`Identifier`] that does not match this pattern,
/// an [`Error::InvalidFormat`] is returned.
#[derive(Clone, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct Identifier(String);

Expand Down
4 changes: 2 additions & 2 deletions wdl-ast/src/v1/document/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ mod tests {
use super::*;

#[test]
fn it_parses_a_complicated_import_correctly(
) -> std::result::Result<(), Box<dyn std::error::Error>> {
fn it_parses_a_complicated_import_correctly()
-> std::result::Result<(), Box<dyn std::error::Error>> {
let import = wdl_grammar::v1::parse_rule(
wdl_grammar::v1::Rule::import,
r#"import "hello.wdl" as hello alias foo as bar alias baz as quux"#,
Expand Down
4 changes: 3 additions & 1 deletion wdl-ast/src/v1/document/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ impl TryFrom<Pair<'_, grammar::v1::Rule>> for Input {
}
Rule::COMMENT => {}
Rule::WHITESPACE => {}
rule => unreachable!("workflow input should not contain {:?}", rule),
rule => {
unreachable!("workflow input should not contain {:?}", rule)
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion wdl-ast/src/v1/document/metadata/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ impl TryFrom<Pair<'_, grammar::v1::Rule>> for Value {
Rule::boolean => match node.as_str() {
"true" => Ok(Value::Boolean(true)),
"false" => Ok(Value::Boolean(false)),
value => unreachable!("unknown boolean literal value: {}", value),
value => {
unreachable!("unknown boolean literal value: {}", value)
}
},
Rule::null => Ok(Value::Null),
Rule::metadata_object => {
Expand Down
3 changes: 2 additions & 1 deletion wdl-ast/src/v1/document/private_declarations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ impl std::fmt::Display for Error {

impl std::error::Error for Error {}

/// The inner list of [bound declarations](`Declaration`) for [`PrivateDeclarations`].
/// The inner list of [bound declarations](`Declaration`) for
/// [`PrivateDeclarations`].
type Declarations = NonEmpty<Declaration>;

/// A set of private declarations.
Expand Down
4 changes: 3 additions & 1 deletion wdl-ast/src/v1/document/struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ impl std::fmt::Display for Error {
match self {
Error::Builder(err) => write!(f, "builder error: {err}"),
Error::Identifier(err) => write!(f, "identifier error: {err}"),
Error::UnboundDeclaration(err) => write!(f, "unbound declaration error: {err}"),
Error::UnboundDeclaration(err) => {
write!(f, "unbound declaration error: {err}")
}
}
}
}
Expand Down
8 changes: 6 additions & 2 deletions wdl-ast/src/v1/document/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,12 @@ impl std::fmt::Display for Error {
Error::Input(err) => write!(f, "input error: {err}"),
Error::Metadata(err) => write!(f, "metadata error: {err}"),
Error::Output(err) => write!(f, "output error: {err}"),
Error::ParameterMetadata(err) => write!(f, "parameter metadata error: {err}"),
Error::PrivateDeclarations(err) => write!(f, "private declarations error: {err}"),
Error::ParameterMetadata(err) => {
write!(f, "parameter metadata error: {err}")
}
Error::PrivateDeclarations(err) => {
write!(f, "private declarations error: {err}")
}
Error::Runtime(err) => write!(f, "runtime error: {err}"),
}
}
Expand Down
8 changes: 4 additions & 4 deletions wdl-ast/src/v1/document/task/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ pub enum MultipleError {
/// [`Builder`].
Output,

/// Attempted to set multiple values for the parameter metadata field within
/// the [`Builder`].
/// Attempted to set multiple values for the parameter metadata field
/// within the [`Builder`].
ParameterMetadata,

/// Attempted to set multiple values for the runtime field within the
Expand Down Expand Up @@ -552,8 +552,8 @@ impl Builder {
.collect::<Vec<_>>();

let private_declarations = if !private_declarations.is_empty() {
// SAFETY: The check above ensures that the declarations aren't empty,
// so unwrapping is safe here.
// SAFETY: The check above ensures that the declarations aren't
// empty, so unwrapping is safe here.
let mut private_declarations = private_declarations.into_iter();

let mut result = NonEmpty::new(private_declarations.next().unwrap());
Expand Down
12 changes: 6 additions & 6 deletions wdl-ast/src/v1/document/task/command/contents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ mod tests {
use super::*;

#[test]
fn it_parses_contents_with_spaces_correctly(
) -> std::result::Result<(), Box<dyn std::error::Error>> {
fn it_parses_contents_with_spaces_correctly()
-> std::result::Result<(), Box<dyn std::error::Error>> {
let contents = "echo 'hello,'
echo 'there'
echo 'world'"
Expand Down Expand Up @@ -138,8 +138,8 @@ mod tests {
}

#[test]
fn it_parses_contents_with_tabs_correctly(
) -> std::result::Result<(), Box<dyn std::error::Error>> {
fn it_parses_contents_with_tabs_correctly()
-> std::result::Result<(), Box<dyn std::error::Error>> {
let contents = "
\t\techo 'hello,'
\t\techo 'there'
Expand All @@ -154,8 +154,8 @@ mod tests {
}

#[test]
fn it_keeps_preceeding_whitespace_on_the_same_line_as_the_command(
) -> std::result::Result<(), Box<dyn std::error::Error>> {
fn it_keeps_preceeding_whitespace_on_the_same_line_as_the_command()
-> std::result::Result<(), Box<dyn std::error::Error>> {
let contents = " \nhello".parse::<Contents>()?;
assert_eq!(contents.as_str(), " \nhello");

Expand Down
4 changes: 3 additions & 1 deletion wdl-ast/src/v1/document/task/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,9 @@ impl TryFrom<Pair<'_, Rule>> for Runtime {
}
Rule::WHITESPACE => {}
Rule::COMMENT => {}
rule => unreachable!("task runtime should not contain {:?}", rule),
rule => {
unreachable!("task runtime should not contain {:?}", rule)
}
}
}

Expand Down
8 changes: 5 additions & 3 deletions wdl-ast/src/v1/document/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ pub enum ParseError {
impl std::fmt::Display for ParseError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
ParseError::UnknownVersion(version) => write!(f, "unknown version: {version}"),
ParseError::UnknownVersion(version) => {
write!(f, "unknown version: {version}")
}
}
}
}
Expand Down Expand Up @@ -89,8 +91,8 @@ impl TryFrom<Pair<'_, grammar::v1::Rule>> for Version {
}

unreachable!(
"`version` node must be required by the grammar to always contain \
a `version_release` node"
"`version` node must be required by the grammar to always contain a `version_release` \
node"
)
}
}
Expand Down
8 changes: 6 additions & 2 deletions wdl-ast/src/v1/document/workflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,16 @@ impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Error::Builder(err) => write!(f, "builder error: {err}"),
Error::ExecutionStatement(err) => write!(f, "execution statement error: {err}"),
Error::ExecutionStatement(err) => {
write!(f, "execution statement error: {err}")
}
Error::Identifier(err) => write!(f, "identifier error: {err}"),
Error::Input(err) => write!(f, "input error: {err}"),
Error::Metadata(err) => write!(f, "metadata error: {err}"),
Error::Output(err) => write!(f, "output error: {err}"),
Error::ParameterMetadata(err) => write!(f, "parameter metadata error: {err}"),
Error::ParameterMetadata(err) => {
write!(f, "parameter metadata error: {err}")
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions wdl-ast/src/v1/document/workflow/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ pub enum MultipleError {
/// [`Builder`].
Output,

/// Attempted to set multiple values for the parameter metadata field within
/// the [`Builder`].
/// Attempted to set multiple values for the parameter metadata field
/// within the [`Builder`].
ParameterMetadata,
}

Expand Down
Loading

0 comments on commit f63c188

Please sign in to comment.