Skip to content

Commit

Permalink
Clippy/fix ruleset (#598)
Browse files Browse the repository at this point in the history
* Added clippy configurations in .cargo/config.toml
* clippy --fix
* cargo clippy --fix -- -W clippy::uninlined_format_args
  • Loading branch information
mkatychev authored Jul 16, 2023
1 parent 9787b1d commit 031d203
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 152 deletions.
11 changes: 11 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[target.'cfg(all())']
rustflags = [
# BEGIN - Embark standard lints v0.4
# do not change or add/remove here, but one can add exceptions after this section
# for more info see: <https://github.com/EmbarkStudios/rust-ecosystem/issues/59>
"-Aclippy::inconsistent_digit_grouping",
"-Aclippy::large_digit_groups",
"-Aclippy::excessive_precision",
"-Aclippy::zero_prefixed_literal",
]

4 changes: 2 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ fn prepare(readme: &str) -> Result<String, Box<dyn std::error::Error>> {
writeln!(cleaned, "```rust")?;
writeln!(cleaned, "# use rust_decimal::Decimal;")?;
writeln!(cleaned, "# use serde::{{Serialize, Deserialize}};")?;
write!(cleaned, "# #[cfg(features = \"{}\")]", feature)?;
write!(cleaned, "# #[cfg(features = \"{feature}\")]")?;
} else {
if !feature_section && line.starts_with("## Features") {
feature_section = true;
} else if feature_section && line.starts_with("### ") {
feature = line.replace("### ", "").replace('`', "");
}
write!(cleaned, "{}", line)?;
write!(cleaned, "{line}")?;
}
writeln!(cleaned)?;
}
Expand Down
5 changes: 2 additions & 3 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,11 @@ impl fmt::Display for Error {
Self::ScaleExceedsMaximumPrecision(ref scale) => {
write!(
f,
"Scale exceeds the maximum precision allowed: {} > {}",
scale, MAX_PRECISION_U32
"Scale exceeds the maximum precision allowed: {scale} > {MAX_PRECISION_U32}"
)
}
Self::ConversionTo(ref type_name) => {
write!(f, "Error while converting to {}", type_name)
write!(f, "Error while converting to {type_name}")
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/ops/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,7 @@ mod test {
assert_eq!(value, expected_value);
assert_eq!(
value_scale, expected_scale,
"value: {}, requested scale: {}",
value_raw, new_scale
"value: {value_raw}, requested scale: {new_scale}"
);
}
}
Expand Down
22 changes: 11 additions & 11 deletions src/postgres/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ mod test {

// Test NULL
let result: Option<Decimal> = match client.query("SELECT NULL::numeric", &[]) {
Ok(x) => x.iter().next().unwrap().get(0),
Ok(x) => x.first().unwrap().get(0),
Err(err) => panic!("{:#?}", err),
};
assert_eq!(None, result);
Expand All @@ -229,9 +229,9 @@ mod test {
let connection = connection.map(|e| e.unwrap());
tokio::spawn(connection);

let statement = client.prepare(&"SELECT NULL::numeric").await.unwrap();
let statement = client.prepare("SELECT NULL::numeric").await.unwrap();
let rows = client.query(&statement, &[]).await.unwrap();
let result: Option<Decimal> = rows.iter().next().unwrap().get(0);
let result: Option<Decimal> = rows.first().unwrap().get(0);

assert_eq!(None, result);
}
Expand All @@ -243,7 +243,7 @@ mod test {
Err(err) => panic!("{:#?}", err),
};
let result: Decimal = match client.query("SELECT 1e-130::NUMERIC(130, 0)", &[]) {
Ok(x) => x.iter().next().unwrap().get(0),
Ok(x) => x.first().unwrap().get(0),
Err(err) => panic!("error - {:#?}", err),
};
// We compare this to zero since it is so small that it is effectively zero
Expand All @@ -259,7 +259,7 @@ mod test {
for &(precision, scale, sent, expected) in TEST_DECIMALS.iter() {
let result: Decimal =
match client.query(&*format!("SELECT {}::NUMERIC({}, {})", sent, precision, scale), &[]) {
Ok(x) => x.iter().next().unwrap().get(0),
Ok(x) => x.first().unwrap().get(0),
Err(err) => panic!("SELECT {}::NUMERIC({}, {}), error - {:#?}", sent, precision, scale, err),
};
assert_eq!(
Expand All @@ -284,11 +284,11 @@ mod test {
tokio::spawn(connection);
for &(precision, scale, sent, expected) in TEST_DECIMALS.iter() {
let statement = client
.prepare(&*format!("SELECT {}::NUMERIC({}, {})", sent, precision, scale))
.prepare(&format!("SELECT {}::NUMERIC({}, {})", sent, precision, scale))
.await
.unwrap();
let rows = client.query(&statement, &[]).await.unwrap();
let result: Decimal = rows.iter().next().unwrap().get(0);
let result: Decimal = rows.first().unwrap().get(0);

assert_eq!(expected, result.to_string(), "NUMERIC({}, {})", precision, scale);
}
Expand All @@ -304,7 +304,7 @@ mod test {
let number = Decimal::from_str(sent).unwrap();
let result: Decimal =
match client.query(&*format!("SELECT $1::NUMERIC({}, {})", precision, scale), &[&number]) {
Ok(x) => x.iter().next().unwrap().get(0),
Ok(x) => x.first().unwrap().get(0),
Err(err) => panic!("{:#?}", err),
};
assert_eq!(expected, result.to_string(), "NUMERIC({}, {})", precision, scale);
Expand All @@ -323,12 +323,12 @@ mod test {

for &(precision, scale, sent, expected) in TEST_DECIMALS.iter() {
let statement = client
.prepare(&*format!("SELECT $1::NUMERIC({}, {})", precision, scale))
.prepare(&format!("SELECT $1::NUMERIC({}, {})", precision, scale))
.await
.unwrap();
let number = Decimal::from_str(sent).unwrap();
let rows = client.query(&statement, &[&number]).await.unwrap();
let result: Decimal = rows.iter().next().unwrap().get(0);
let result: Decimal = rows.first().unwrap().get(0);

assert_eq!(expected, result.to_string(), "NUMERIC({}, {})", precision, scale);
}
Expand Down Expand Up @@ -367,7 +367,7 @@ mod test {

for &(precision, scale, sent) in tests.iter() {
let statement = client
.prepare(&*format!("SELECT {}::NUMERIC({}, {})", sent, precision, scale))
.prepare(&format!("SELECT {}::NUMERIC({}, {})", sent, precision, scale))
.await
.unwrap();

Expand Down
5 changes: 2 additions & 3 deletions src/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,8 +555,7 @@ mod test {
];
for &(serialized, value) in data.iter() {
let result = serde_json::from_str(serialized);
assert_eq!(
true,
assert!(
result.is_ok(),
"expected successful deserialization for {}. Error: {:?}",
serialized,
Expand All @@ -568,7 +567,7 @@ mod test {
record.amount.to_string(),
"expected: {}, actual: {}",
value,
record.amount.to_string()
record.amount
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ mod test {
fn display_does_not_overflow_max_capacity() {
let num = Decimal::from_str("1.2").unwrap();
let mut buffer = ArrayString::<64>::new();
let _ = buffer.write_fmt(format_args!("{:.31}", num)).unwrap();
buffer.write_fmt(format_args!("{num:.31}")).unwrap();
assert_eq!("1.2000000000000000000000000000000", buffer.as_str());
}

Expand Down
Loading

0 comments on commit 031d203

Please sign in to comment.