Skip to content

Commit

Permalink
Fixed clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
tkmcmaster committed Jan 26, 2023
1 parent ffa9b69 commit 887082f
Show file tree
Hide file tree
Showing 18 changed files with 96 additions and 99 deletions.
1 change: 1 addition & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
large-error-threshold = 256
8 changes: 4 additions & 4 deletions lib/config-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl Config {
init_logging(log_level);
let env_vars = serde_wasm_bindgen::from_value(env_vars.into())?;
let load_test = LoadTest::from_config(bytes, &PathBuf::default(), &env_vars)
.map_err(|e| JsValue::from_str(&format!("{:?}", e)))?;
.map_err(|e| JsValue::from_str(&format!("{e:?}")))?;
Ok(Config(load_test))
}

Expand All @@ -73,8 +73,8 @@ impl Config {
pub fn get_logger_files(&self) -> Box<[JsValue]> {
self.0
.loggers
.iter()
.map(|(_, l)| l.to.as_str().into())
.values()
.map(|l| l.to.as_str().into())
.collect::<Vec<_>>()
.into_boxed_slice()
}
Expand Down Expand Up @@ -126,6 +126,6 @@ impl Config {
pub fn check_ok(&self) -> Result<(), JsValue> {
self.0
.ok_for_loadtest()
.map_err(|e| JsValue::from_str(&format!("{:?}", e)))
.map_err(|e| JsValue::from_str(&format!("{e:?}")))
}
}
2 changes: 1 addition & 1 deletion lib/config/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ impl fmt::Display for Error {
InvalidLoadPattern(m) => write!(f, "invalid load_pattern at line {} column {}", m.line(), m.col()),
InvalidPeakLoad(p, m) => write!(f, "invalid peak_load `{}` at line {} column {}", p, m.line(), m.col()),
InvalidPercent(p, m) => write!(f, "invalid percent `{}` at line {} column {}", p, m.line(), m.col()),
InvalidYaml(e) => write!(f, "yaml syntax error:\n\t{}", e),
InvalidYaml(e) => write!(f, "yaml syntax error:\n\t{e}"),
MissingEnvironmentVariable(v, m) => write!(f, "undefined environment variable `{}` at line {} column {}", v, m.line(), m.col()),
MissingForEach(m) => write!(f, "missing `for_each` at line {} column {}", m.line(), m.col()),
MissingLoadPattern(m) => write!(f, "endpoint is missing a load_pattern at line {} column {}", m.line(), m.col()),
Expand Down
30 changes: 15 additions & 15 deletions lib/config/src/expression_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ impl Encode {
) -> Result<Cow<'a, json::Value>, ExecutingExpressionError> {
self.arg
.evaluate(d, no_recoverable_error, for_each)
.map(|v| Cow::Owned(Encode::evaluate_with_arg(self.encoding, &*v)))
.map(|v| Cow::Owned(Encode::evaluate_with_arg(self.encoding, &v)))
}

pub(super) fn evaluate_as_iter<'a, 'b: 'a>(
Expand Down Expand Up @@ -544,7 +544,7 @@ impl If {
let first = self
.first
.evaluate(Cow::Borrowed(&*d), no_recoverable_error, for_each)?;
if bool_value(&*first) {
if bool_value(&first) {
Ok(self.second.evaluate(d, no_recoverable_error, for_each)?)
} else {
Ok(self.third.evaluate(d, no_recoverable_error, for_each)?)
Expand Down Expand Up @@ -705,7 +705,7 @@ impl Join {
) -> Result<Cow<'a, json::Value>, ExecutingExpressionError> {
self.arg
.evaluate(d, no_recoverable_error, for_each)
.map(|d| Cow::Owned(Join::evaluate_with_arg(&self.sep, &self.sep2, &*d)))
.map(|d| Cow::Owned(Join::evaluate_with_arg(&self.sep, &self.sep2, &d)))
}

pub(super) fn evaluate_as_iter<'a, 'b: 'a>(
Expand Down Expand Up @@ -779,9 +779,9 @@ impl JsonPath {
};
// jsonpath requires the query to start with `$.`, so add it in
let json_path = if json_path.starts_with('[') {
format!("${}", json_path)
format!("${json_path}")
} else {
format!("$.{}", json_path)
format!("$.{json_path}")
};
let json_path = json_path::Parser::compile(&json_path).map_err(|_| {
ExecutingExpressionError::InvalidFunctionArguments("json_path", marker)
Expand Down Expand Up @@ -817,15 +817,15 @@ impl JsonPath {
}

pub(super) fn evaluate<'a, 'b: 'a>(&'b self, d: Cow<'a, json::Value>) -> Cow<'a, json::Value> {
let v = self.evaluate_to_vec(&*d);
let v = self.evaluate_to_vec(&d);
Cow::Owned(v.into())
}

pub(super) fn evaluate_as_iter<'a, 'b: 'a>(
&'b self,
d: Cow<'a, json::Value>,
) -> impl Iterator<Item = Cow<'a, json::Value>> + Clone {
self.evaluate_to_vec(&*d).into_iter().map(Cow::Owned)
self.evaluate_to_vec(&d).into_iter().map(Cow::Owned)
}

pub(super) fn into_stream<
Expand Down Expand Up @@ -889,7 +889,7 @@ impl Match {

fn evaluate_with_arg(regex: &Regex, capture_names: &[String], d: &json::Value) -> json::Value {
let search_str = json_value_to_string(Cow::Borrowed(d));
if let Some(captures) = regex.captures(&*search_str) {
if let Some(captures) = regex.captures(&search_str) {
let map: json::Map<String, json::Value> = capture_names
.iter()
.zip(captures.iter())
Expand All @@ -916,7 +916,7 @@ impl Match {
self.arg
.evaluate(d, no_recoverable_error, for_each)
.map(|d| {
let v = Match::evaluate_with_arg(&self.regex, &self.capture_names, &*d);
let v = Match::evaluate_with_arg(&self.regex, &self.capture_names, &d);
Cow::Owned(v)
})
}
Expand Down Expand Up @@ -990,8 +990,8 @@ impl MinMax {
(Cow::Owned(json::Value::Null), 0),
|(left, count), right| {
let right = right?;
let l = f64_value(&*left);
let r = f64_value(&*right);
let l = f64_value(&left);
let r = f64_value(&right);
let v = match (l.partial_cmp(&r), min, l.is_finite()) {
(Some(Ordering::Less), true, _)
| (Some(Ordering::Greater), false, _)
Expand All @@ -1013,7 +1013,7 @@ impl MinMax {
let mut left: Option<(f64, json::Value)> = None;
for fa in &self.args {
let right = fa.evaluate(Cow::Borrowed(&*d), no_recoverable_error, for_each)?;
let r = f64_value(&*right);
let r = f64_value(&right);
if let Some((l, _)) = &left {
match (l.partial_cmp(&r), self.min, l.is_finite()) {
(Some(Ordering::Less), true, _)
Expand Down Expand Up @@ -1142,7 +1142,7 @@ impl Pad {
self.arg
.evaluate(d, no_recoverable_error, for_each)
.map(|d| {
let v = Pad::evaluate_with_arg(&self.padding, self.min_length, self.start, &*d);
let v = Pad::evaluate_with_arg(&self.padding, self.min_length, self.start, &d);
Cow::Owned(v)
})
}
Expand Down Expand Up @@ -1539,7 +1539,7 @@ impl Replace {
.evaluate(Cow::Borrowed(&*d), no_recoverable_error, for_each)?;
let replacer = json_value_to_string(replacer_value).into_owned();
let mut haystack = self.haystack.evaluate(d, no_recoverable_error, for_each)?;
Replace::replace(haystack.to_mut(), &*needle, &*replacer);
Replace::replace(haystack.to_mut(), &needle, &replacer);
Ok(haystack)
}

Expand Down Expand Up @@ -1647,7 +1647,7 @@ impl ParseNum {
self.arg
.evaluate(d, no_recoverable_error, for_each)
.map(|d| {
let v = ParseNum::evaluate_with_arg(is_float, &*d);
let v = ParseNum::evaluate_with_arg(is_float, &d);
Cow::Owned(v)
})
}
Expand Down
3 changes: 1 addition & 2 deletions lib/config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2265,8 +2265,7 @@ pub fn duration_from_string(dur: String) -> Result<Duration, Error> {

fn duration_from_string2(dur: String, marker: Marker) -> Result<Duration, Error> {
let base_re = r"(?i)(\d+)\s*(d|h|m|s|days?|hrs?|mins?|secs?|hours?|minutes?|seconds?)";
let sanity_re =
Regex::new(&format!(r"^(?:{}\s*)+$", base_re)).expect("should be a valid regex");
let sanity_re = Regex::new(&format!(r"^(?:{base_re}\s*)+$")).expect("should be a valid regex");
if !sanity_re.is_match(&dur) {
return Err(Error::InvalidDuration(dur, marker));
}
Expand Down
12 changes: 6 additions & 6 deletions lib/config/src/select_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl RequiredProviders {
}

pub fn unique_providers(self) -> BTreeSet<String> {
self.inner.into_iter().map(|(k, _)| k).collect()
self.inner.into_keys().collect()
}

pub fn contains(&self, p: &str) -> bool {
Expand Down Expand Up @@ -372,7 +372,7 @@ fn index_json<'a>(
}
(json, Either::B(n)) if !no_err => {
return Err(ExecutingExpressionError::IndexingIntoJson(
format!("[{}]", n),
format!("[{n}]"),
json.into_owned(),
marker,
));
Expand Down Expand Up @@ -428,7 +428,7 @@ fn index_json2<'a>(
}
(json, Either::B(n)) if !no_err => {
return Err(ExecutingExpressionError::IndexingIntoJson(
format!("[{}]", n),
format!("[{n}]"),
json.into_owned(),
marker,
));
Expand Down Expand Up @@ -955,7 +955,7 @@ impl Expression {
}
};
let rhs = rhs.evaluate(Cow::Borrowed(&*d), no_recoverable_error, for_each);
Cow::Owned(op.evaluate(&*v, rhs)?)
Cow::Owned(op.evaluate(&v, rhs)?)
} else {
match &self.lhs {
ExpressionLhs::Expression(e) => e.evaluate(d, no_recoverable_error, for_each)?,
Expand All @@ -968,7 +968,7 @@ impl Expression {
v = Cow::Owned(b.into());
}
Some(false) => {
let b = bool_value(&*v);
let b = bool_value(&v);
v = Cow::Owned(b.into());
}
_ => (),
Expand Down Expand Up @@ -1816,7 +1816,7 @@ fn parse_path(
if let PathStart::Ident(s) = &start {
match rest.first() {
Some(PathSegment::String(next)) if s == "request" || s == "response" => {
providers2.insert(format!("{}.{}", s, next), marker);
providers2.insert(format!("{s}.{next}"), marker);
}
_ => {
providers2.insert(s.clone(), marker);
Expand Down
20 changes: 10 additions & 10 deletions lib/either/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ where
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match &self {
Either::A(a) => write!(f, "{}", a),
Either::B(b) => write!(f, "{}", b),
Either::A(a) => write!(f, "{a}"),
Either::B(b) => write!(f, "{b}"),
}
}
}
Expand All @@ -112,8 +112,8 @@ where
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match &self {
Either::A(a) => write!(f, "Either::A({:?})", a),
Either::B(b) => write!(f, "Either::B({:?})", b),
Either::A(a) => write!(f, "Either::A({a:?})"),
Either::B(b) => write!(f, "Either::B({b:?})"),
}
}
}
Expand Down Expand Up @@ -233,9 +233,9 @@ where
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match &self {
Either3::A(a) => write!(f, "Either::A({:?})", a),
Either3::B(b) => write!(f, "Either::B({:?})", b),
Either3::C(c) => write!(f, "Either::C({:?})", c),
Either3::A(a) => write!(f, "Either::A({a:?})"),
Either3::B(b) => write!(f, "Either::B({b:?})"),
Either3::C(c) => write!(f, "Either::C({c:?})"),
}
}
}
Expand All @@ -248,9 +248,9 @@ where
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match &self {
Either3::A(a) => write!(f, "{}", a),
Either3::B(b) => write!(f, "{}", b),
Either3::C(c) => write!(f, "{}", c),
Either3::A(a) => write!(f, "{a}"),
Either3::B(b) => write!(f, "{b}"),
Either3::C(c) => write!(f, "{c}"),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/mod_interval/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ impl ModInterval {
end_time: now + duration,
current_segment: segment,
segments: std::mem::take(&mut segments),
start_time: now - start_at.unwrap_or_default(),
start_time: now.checked_sub(start_at.unwrap_or_default()).unwrap(),
x_offset: Default::default(),
next_start: now,
following_start: None,
Expand Down
4 changes: 2 additions & 2 deletions lib/test_common/test_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async fn echo_route(req: Request<Body>) -> Response<Body> {
.path_and_query()
.map(|piece| piece.as_str())
.unwrap_or_else(|| uri.path());
let url = Url::parse(&format!("http://127.0.0.1:8080{}", url)).unwrap();
let url = Url::parse(&format!("http://127.0.0.1:8080{url}")).unwrap();
for (k, v) in url.query_pairs() {
match &*k {
"echo" => echo = Some(v.to_string()),
Expand All @@ -52,7 +52,7 @@ async fn echo_route(req: Request<Body>) -> Response<Body> {
.body(Body::empty())
.unwrap(),
};
let ms = wait.and_then(|c| FromStr::from_str(&*c).ok()).unwrap_or(0);
let ms = wait.and_then(|c| FromStr::from_str(&c).ok()).unwrap_or(0);
let old_body = std::mem::replace(response.body_mut(), Body::empty());
if ms > 0 {
debug!("waiting {} ms", ms);
Expand Down
4 changes: 2 additions & 2 deletions src/bin/pewpew.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ fn get_cli_config(matches: ArgMatches) -> ExecConfig {
.unwrap_or_default();
let test_name = config_file.file_stem().and_then(std::ffi::OsStr::to_str);
let file = if let Some(test_name) = test_name {
format!("stats-{}-{}.json", test_name, start_sec)
format!("stats-{test_name}-{start_sec}.json")
} else {
format!("stats-{}.json", start_sec)
format!("stats-{start_sec}.json")
};
PathBuf::from(file)
});
Expand Down
2 changes: 1 addition & 1 deletion src/bin/test_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn main() {
debug!("port = {}", port.unwrap_or_default());
let (port, rx, handle) = start_test_server(port);

println!("Listening on port {}", port);
println!("Listening on port {port}");

handle.await;
drop(rx);
Expand Down
22 changes: 11 additions & 11 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ impl RecoverableError {
impl fmt::Display for RecoverableError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
BodyErr(e) => write!(f, "body error: {}", e),
ConnectionErr(_, e) => write!(f, "connection error: `{}`", e),
BodyErr(e) => write!(f, "body error: {e}"),
ConnectionErr(_, e) => write!(f, "connection error: `{e}`"),
ExecutingExpression(e) => e.fmt(f),
ProviderDelay(p) => write!(f, "endpoint was delayed waiting for provider `{}`", p),
ProviderDelay(p) => write!(f, "endpoint was delayed waiting for provider `{p}`"),
Timeout(..) => write!(f, "request timed out"),
}
}
Expand Down Expand Up @@ -65,19 +65,19 @@ use TestError::*;
impl fmt::Display for TestError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
CannotCreateLoggerFile(s, e) => write!(f, "error creating logger file `{}`: {}", s, e),
CannotCreateStatsFile(s, e) => write!(f, "error creating stats file `{}`: {}", s, e),
CannotCreateLoggerFile(s, e) => write!(f, "error creating logger file `{s}`: {e}"),
CannotCreateStatsFile(s, e) => write!(f, "error creating stats file `{s}`: {e}"),
CannotOpenFile(p, e) => write!(f, "error opening file `{}`: {}", p.display(), e),
Config(e) => e.fmt(f),
FileReading(s, e) => write!(f, "error reading file `{}`: {}", s, e),
FileReading(s, e) => write!(f, "error reading file `{s}`: {e}"),
InvalidConfigFilePath(p) => {
write!(f, "could not find config file at path `{}`", p.display())
}
InvalidUrl(u) => write!(f, "invalid url `{}`", u),
Recoverable(r) => write!(f, "recoverable error: {}", r),
RequestBuilderErr(e) => write!(f, "error creating request: {}", e),
SslError(e) => write!(f, "error creating ssl connector: {}", e),
WritingToFile(l, e) => write!(f, "error writing to file `{}`: {}", l, e),
InvalidUrl(u) => write!(f, "invalid url `{u}`"),
Recoverable(r) => write!(f, "recoverable error: {r}"),
RequestBuilderErr(e) => write!(f, "error creating request: {e}"),
SslError(e) => write!(f, "error creating ssl connector: {e}"),
WritingToFile(l, e) => write!(f, "error writing to file `{l}`: {e}"),
}
}
}
Expand Down
Loading

0 comments on commit 887082f

Please sign in to comment.