mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 18:57:44 +02:00
Use variable names directly in the format strings (#7906)
# Description Lint: `clippy::uninlined_format_args` More readable in most situations. (May be slightly confusing for modifier format strings https://doc.rust-lang.org/std/fmt/index.html#formatting-parameters) Alternative to #7865 # User-Facing Changes None intended # Tests + Formatting (Ran `cargo +stable clippy --fix --workspace -- -A clippy::all -D clippy::uninlined_format_args` to achieve this. Depends on Rust `1.67`)
This commit is contained in:
committed by
GitHub
parent
6ae497eedc
commit
ab480856a5
@ -167,17 +167,17 @@ fn helper(
|
||||
let login = match (user, password) {
|
||||
(Some(user), Some(password)) => {
|
||||
let mut enc_str = String::new();
|
||||
base64_engine.encode_string(&format!("{}:{}", user, password), &mut enc_str);
|
||||
base64_engine.encode_string(&format!("{user}:{password}"), &mut enc_str);
|
||||
Some(enc_str)
|
||||
}
|
||||
(Some(user), _) => {
|
||||
let mut enc_str = String::new();
|
||||
base64_engine.encode_string(&format!("{}:", user), &mut enc_str);
|
||||
base64_engine.encode_string(&format!("{user}:"), &mut enc_str);
|
||||
Some(enc_str)
|
||||
}
|
||||
(_, Some(password)) => {
|
||||
let mut enc_str = String::new();
|
||||
base64_engine.encode_string(&format!(":{}", password), &mut enc_str);
|
||||
base64_engine.encode_string(&format!(":{password}"), &mut enc_str);
|
||||
Some(enc_str)
|
||||
}
|
||||
_ => None,
|
||||
@ -200,7 +200,7 @@ fn helper(
|
||||
}
|
||||
|
||||
if let Some(login) = login {
|
||||
request = request.header("Authorization", format!("Basic {}", login));
|
||||
request = request.header("Authorization", format!("Basic {login}"));
|
||||
}
|
||||
|
||||
if let Some(headers) = headers {
|
||||
@ -268,7 +268,7 @@ fn helper(
|
||||
})?;
|
||||
let content_type = mime::Mime::from_str(content_type).map_err(|_| {
|
||||
ShellError::GenericError(
|
||||
format!("MIME type unknown: {}", content_type),
|
||||
format!("MIME type unknown: {content_type}"),
|
||||
"".to_string(),
|
||||
None,
|
||||
Some("given unknown MIME type".to_string()),
|
||||
@ -280,7 +280,7 @@ fn helper(
|
||||
let path_extension = url::Url::parse(&requested_url)
|
||||
.map_err(|_| {
|
||||
ShellError::GenericError(
|
||||
format!("Cannot parse URL: {}", requested_url),
|
||||
format!("Cannot parse URL: {requested_url}"),
|
||||
"".to_string(),
|
||||
None,
|
||||
Some("cannot parse".to_string()),
|
||||
@ -307,7 +307,7 @@ fn helper(
|
||||
}
|
||||
|
||||
if let Some(ext) = ext {
|
||||
match engine_state.find_decl(format!("from {}", ext).as_bytes(), &[]) {
|
||||
match engine_state.find_decl(format!("from {ext}").as_bytes(), &[]) {
|
||||
Some(converter_id) => engine_state.get_decl(converter_id).run(
|
||||
engine_state,
|
||||
stack,
|
||||
@ -323,28 +323,25 @@ fn helper(
|
||||
None => Ok(response_to_buffer(resp, engine_state, span)),
|
||||
},
|
||||
Err(e) if e.is_timeout() => Err(ShellError::NetworkFailure(
|
||||
format!("Request to {} has timed out", requested_url),
|
||||
format!("Request to {requested_url} has timed out"),
|
||||
span,
|
||||
)),
|
||||
Err(e) if e.is_status() => match e.status() {
|
||||
Some(err_code) if err_code == StatusCode::NOT_FOUND => Err(ShellError::NetworkFailure(
|
||||
format!("Requested file not found (404): {:?}", requested_url),
|
||||
format!("Requested file not found (404): {requested_url:?}"),
|
||||
span,
|
||||
)),
|
||||
Some(err_code) if err_code == StatusCode::MOVED_PERMANENTLY => {
|
||||
Err(ShellError::NetworkFailure(
|
||||
format!("Resource moved permanently (301): {:?}", requested_url),
|
||||
span,
|
||||
))
|
||||
}
|
||||
Some(err_code) if err_code == StatusCode::BAD_REQUEST => {
|
||||
Err(ShellError::NetworkFailure(
|
||||
format!("Bad request (400) to {:?}", requested_url),
|
||||
format!("Resource moved permanently (301): {requested_url:?}"),
|
||||
span,
|
||||
))
|
||||
}
|
||||
Some(err_code) if err_code == StatusCode::BAD_REQUEST => Err(
|
||||
ShellError::NetworkFailure(format!("Bad request (400) to {requested_url:?}"), span),
|
||||
),
|
||||
Some(err_code) if err_code == StatusCode::FORBIDDEN => Err(ShellError::NetworkFailure(
|
||||
format!("Access forbidden (403) to {:?}", requested_url),
|
||||
format!("Access forbidden (403) to {requested_url:?}"),
|
||||
span,
|
||||
)),
|
||||
_ => Err(ShellError::NetworkFailure(
|
||||
|
@ -174,7 +174,7 @@ fn helper(
|
||||
return Err(ShellError::UnsupportedInput(
|
||||
"Incomplete or incorrect URL. Expected a full URL, e.g., https://www.example.com"
|
||||
.to_string(),
|
||||
format!("value: '{:?}'", requested_url),
|
||||
format!("value: '{requested_url:?}'"),
|
||||
call.head,
|
||||
span,
|
||||
));
|
||||
@ -190,12 +190,12 @@ fn helper(
|
||||
let login = match (user, password) {
|
||||
(Some(user), Some(password)) => {
|
||||
let mut enc_str = String::new();
|
||||
base64_engine.encode_string(&format!("{}:{}", user, password), &mut enc_str);
|
||||
base64_engine.encode_string(&format!("{user}:{password}"), &mut enc_str);
|
||||
Some(enc_str)
|
||||
}
|
||||
(Some(user), _) => {
|
||||
let mut enc_str = String::new();
|
||||
base64_engine.encode_string(&format!("{}:", user), &mut enc_str);
|
||||
base64_engine.encode_string(&format!("{user}:"), &mut enc_str);
|
||||
Some(enc_str)
|
||||
}
|
||||
_ => None,
|
||||
@ -249,7 +249,7 @@ fn helper(
|
||||
request = request.header("Content-Length", val);
|
||||
}
|
||||
if let Some(login) = login {
|
||||
request = request.header("Authorization", format!("Basic {}", login));
|
||||
request = request.header("Authorization", format!("Basic {login}"));
|
||||
}
|
||||
|
||||
if let Some(headers) = headers {
|
||||
@ -317,7 +317,7 @@ fn helper(
|
||||
})?;
|
||||
let content_type = mime::Mime::from_str(content_type).map_err(|_| {
|
||||
ShellError::GenericError(
|
||||
format!("MIME type unknown: {}", content_type),
|
||||
format!("MIME type unknown: {content_type}"),
|
||||
"".to_string(),
|
||||
None,
|
||||
Some("given unknown MIME type".to_string()),
|
||||
@ -329,7 +329,7 @@ fn helper(
|
||||
let path_extension = url::Url::parse(&requested_url)
|
||||
.map_err(|_| {
|
||||
ShellError::GenericError(
|
||||
format!("Cannot parse URL: {}", requested_url),
|
||||
format!("Cannot parse URL: {requested_url}"),
|
||||
"".to_string(),
|
||||
None,
|
||||
Some("cannot parse".to_string()),
|
||||
@ -354,7 +354,7 @@ fn helper(
|
||||
return Ok(output);
|
||||
}
|
||||
if let Some(ext) = ext {
|
||||
match engine_state.find_decl(format!("from {}", ext).as_bytes(), &[]) {
|
||||
match engine_state.find_decl(format!("from {ext}").as_bytes(), &[]) {
|
||||
Some(converter_id) => engine_state.get_decl(converter_id).run(
|
||||
engine_state,
|
||||
stack,
|
||||
@ -371,23 +371,20 @@ fn helper(
|
||||
},
|
||||
Err(e) if e.is_status() => match e.status() {
|
||||
Some(err_code) if err_code == StatusCode::NOT_FOUND => Err(ShellError::NetworkFailure(
|
||||
format!("Requested file not found (404): {:?}", requested_url),
|
||||
format!("Requested file not found (404): {requested_url:?}"),
|
||||
span,
|
||||
)),
|
||||
Some(err_code) if err_code == StatusCode::MOVED_PERMANENTLY => {
|
||||
Err(ShellError::NetworkFailure(
|
||||
format!("Resource moved permanently (301): {:?}", requested_url),
|
||||
span,
|
||||
))
|
||||
}
|
||||
Some(err_code) if err_code == StatusCode::BAD_REQUEST => {
|
||||
Err(ShellError::NetworkFailure(
|
||||
format!("Bad request (400) to {:?}", requested_url),
|
||||
format!("Resource moved permanently (301): {requested_url:?}"),
|
||||
span,
|
||||
))
|
||||
}
|
||||
Some(err_code) if err_code == StatusCode::BAD_REQUEST => Err(
|
||||
ShellError::NetworkFailure(format!("Bad request (400) to {requested_url:?}"), span),
|
||||
),
|
||||
Some(err_code) if err_code == StatusCode::FORBIDDEN => Err(ShellError::NetworkFailure(
|
||||
format!("Access forbidden (403) to {:?}", requested_url),
|
||||
format!("Access forbidden (403) to {requested_url:?}"),
|
||||
span,
|
||||
)),
|
||||
_ => Err(ShellError::NetworkFailure(
|
||||
|
@ -180,21 +180,21 @@ impl UrlComponents {
|
||||
.iter()
|
||||
.zip(vals.iter())
|
||||
.map(|(k, v)| match v.as_string() {
|
||||
Ok(val) => Ok(format!("{}={}", k, val)),
|
||||
Ok(val) => Ok(format!("{k}={val}")),
|
||||
Err(err) => Err(err),
|
||||
})
|
||||
.collect::<Result<Vec<String>, ShellError>>()?
|
||||
.join("&");
|
||||
|
||||
qs = format!("?{}", qs);
|
||||
qs = format!("?{qs}");
|
||||
|
||||
if let Some(q) = self.query {
|
||||
if q != qs {
|
||||
// if query is present it means that also query_span is set.
|
||||
return Err(ShellError::IncompatibleParameters {
|
||||
left_message: format!("Mismatch, qs from params is: {}", qs),
|
||||
left_message: format!("Mismatch, qs from params is: {qs}"),
|
||||
left_span: value.expect_span(),
|
||||
right_message: format!("instead query is: {}", q),
|
||||
right_message: format!("instead query is: {q}"),
|
||||
right_span: self.query_span.unwrap_or(Span::unknown()),
|
||||
});
|
||||
}
|
||||
@ -241,7 +241,7 @@ impl UrlComponents {
|
||||
path: Some(if s.starts_with('/') {
|
||||
s
|
||||
} else {
|
||||
format!("/{}", s)
|
||||
format!("/{s}")
|
||||
}),
|
||||
..self
|
||||
}),
|
||||
@ -250,16 +250,16 @@ impl UrlComponents {
|
||||
if q != s {
|
||||
// if query is present it means that also params_span is set.
|
||||
return Err(ShellError::IncompatibleParameters {
|
||||
left_message: format!("Mismatch, query param is: {}", s),
|
||||
left_message: format!("Mismatch, query param is: {s}"),
|
||||
left_span: value.expect_span(),
|
||||
right_message: format!("instead qs from params is: {}", q),
|
||||
right_message: format!("instead qs from params is: {q}"),
|
||||
right_span: self.params_span.unwrap_or(Span::unknown()),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Ok(Self {
|
||||
query: Some(format!("?{}", s)),
|
||||
query: Some(format!("?{s}")),
|
||||
query_span: Some(value.expect_span()),
|
||||
..self
|
||||
})
|
||||
@ -268,7 +268,7 @@ impl UrlComponents {
|
||||
fragment: Some(if s.starts_with('#') {
|
||||
s
|
||||
} else {
|
||||
format!("#{}", s)
|
||||
format!("#{s}")
|
||||
}),
|
||||
..self
|
||||
}),
|
||||
@ -285,7 +285,7 @@ impl UrlComponents {
|
||||
|
||||
if let Some(usr) = &self.username {
|
||||
if let Some(pwd) = &self.password {
|
||||
user_and_pwd = format!("{}:{}@", usr, pwd);
|
||||
user_and_pwd = format!("{usr}:{pwd}@");
|
||||
}
|
||||
}
|
||||
|
||||
@ -311,7 +311,7 @@ impl UrlComponents {
|
||||
user_and_pwd,
|
||||
host_result?,
|
||||
self.port
|
||||
.map(|p| format!(":{}", p))
|
||||
.map(|p| format!(":{p}"))
|
||||
.as_deref()
|
||||
.unwrap_or_default(),
|
||||
self.path.as_deref().unwrap_or_default(),
|
||||
|
Reference in New Issue
Block a user