Unverified Commit 16cc5fab authored by Hamir Mahal's avatar Hamir Mahal Committed by GitHub

style: simplify string formatting (#66772)

Co-authored-by: 's avatarJiwon Choi <devjiwonchoi@gmail.com>
parent 0849391b
...@@ -264,8 +264,7 @@ impl Fold for OptimizeBarrel { ...@@ -264,8 +264,7 @@ impl Fold for OptimizeBarrel {
span: DUMMY_SP, span: DUMMY_SP,
src: Box::new(Str { src: Box::new(Str {
span: DUMMY_SP, span: DUMMY_SP,
value: format!("__barrel_optimize__?names=__PLACEHOLDER__!=!{}", src) value: format!("__barrel_optimize__?names=__PLACEHOLDER__!=!{src}").into(),
.into(),
raw: None, raw: None,
}), }),
with: None, with: None,
......
...@@ -55,7 +55,7 @@ impl Fold for PageConfig { ...@@ -55,7 +55,7 @@ impl Fold for PageConfig {
type_ann: None, type_ann: None,
}), }),
init: Some(Box::new(Expr::Lit(Lit::Str(Str { init: Some(Box::new(Expr::Lit(Lit::Str(Str {
value: format!("{} {}", STRING_LITERAL_DROP_BUNDLE, timestamp).into(), value: format!("{STRING_LITERAL_DROP_BUNDLE} {timestamp}").into(),
span: DUMMY_SP, span: DUMMY_SP,
raw: None, raw: None,
})))), })))),
...@@ -171,8 +171,8 @@ impl Fold for PageConfig { ...@@ -171,8 +171,8 @@ impl Fold for PageConfig {
impl PageConfig { impl PageConfig {
fn handle_error(&mut self, details: &str, span: Span) { fn handle_error(&mut self, details: &str, span: Span) {
if self.is_page_file { if self.is_page_file {
let message = format!("Invalid page config export found. {} \ let message = format!("Invalid page config export found. {details} \
See: https://nextjs.org/docs/messages/invalid-page-config", details); See: https://nextjs.org/docs/messages/invalid-page-config");
HANDLER.with(|handler| handler.struct_span_err(span, &message).emit()); HANDLER.with(|handler| handler.struct_span_err(span, &message).emit());
} }
} }
......
...@@ -101,8 +101,7 @@ fn extract_value(ctx: &ExprCtx, init: &Expr, id: String) -> Option<Const> { ...@@ -101,8 +101,7 @@ fn extract_value(ctx: &ExprCtx, init: &Expr, id: String) -> Option<Const> {
Some(elem) => { Some(elem) => {
if elem.spread.is_some() { if elem.spread.is_some() {
return Some(Const::Unsupported(format!( return Some(Const::Unsupported(format!(
"Unsupported spread operator in the Array Expression at \"{}\"", "Unsupported spread operator in the Array Expression at \"{id}\""
id
))); )));
} }
...@@ -139,8 +138,7 @@ fn extract_value(ctx: &ExprCtx, init: &Expr, id: String) -> Option<Const> { ...@@ -139,8 +138,7 @@ fn extract_value(ctx: &ExprCtx, init: &Expr, id: String) -> Option<Const> {
PropName::Str(s) => s.value.as_ref(), PropName::Str(s) => s.value.as_ref(),
_ => { _ => {
return Some(Const::Unsupported(format!( return Some(Const::Unsupported(format!(
"Unsupported key type in the Object Expression at \"{}\"", "Unsupported key type in the Object Expression at \"{id}\""
id
))) )))
} }
}, },
...@@ -148,12 +146,11 @@ fn extract_value(ctx: &ExprCtx, init: &Expr, id: String) -> Option<Const> { ...@@ -148,12 +146,11 @@ fn extract_value(ctx: &ExprCtx, init: &Expr, id: String) -> Option<Const> {
), ),
_ => { _ => {
return Some(Const::Unsupported(format!( return Some(Const::Unsupported(format!(
"Unsupported spread operator in the Object Expression at \"{}\"", "Unsupported spread operator in the Object Expression at \"{id}\""
id
))) )))
} }
}; };
let new_value = extract_value(ctx, value, format!("{}.{}", id, key)); let new_value = extract_value(ctx, value, format!("{id}.{key}"));
if let Some(Const::Unsupported(msg)) = new_value { if let Some(Const::Unsupported(msg)) = new_value {
return Some(Const::Unsupported(msg)); return Some(Const::Unsupported(msg));
} }
...@@ -169,8 +166,7 @@ fn extract_value(ctx: &ExprCtx, init: &Expr, id: String) -> Option<Const> { ...@@ -169,8 +166,7 @@ fn extract_value(ctx: &ExprCtx, init: &Expr, id: String) -> Option<Const> {
// [TODO] should we add support for `${'e'}d${'g'}'e'`? // [TODO] should we add support for `${'e'}d${'g'}'e'`?
if !tpl.exprs.is_empty() { if !tpl.exprs.is_empty() {
Some(Const::Unsupported(format!( Some(Const::Unsupported(format!(
"Unsupported template literal with expressions at \"{}\".", "Unsupported template literal with expressions at \"{id}\"."
id
))) )))
} else { } else {
Some( Some(
...@@ -196,15 +192,13 @@ fn extract_value(ctx: &ExprCtx, init: &Expr, id: String) -> Option<Const> { ...@@ -196,15 +192,13 @@ fn extract_value(ctx: &ExprCtx, init: &Expr, id: String) -> Option<Const> {
)) ))
}) })
.unwrap_or(Const::Unsupported(format!( .unwrap_or(Const::Unsupported(format!(
"Unsupported node type at \"{}\"", "Unsupported node type at \"{id}\""
id
))), ))),
) )
} }
} }
_ => Some(Const::Unsupported(format!( _ => Some(Const::Unsupported(format!(
"Unsupported node type at \"{}\"", "Unsupported node type at \"{id}\""
id
))), ))),
} }
} }
...@@ -239,7 +239,7 @@ fn report_error(app_dir: &Option<PathBuf>, filepath: &str, error_kind: RSCErrorK ...@@ -239,7 +239,7 @@ fn report_error(app_dir: &Option<PathBuf>, filepath: &str, error_kind: RSCErrorK
"react-dom/server" => "You're importing a component that imports react-dom/server. To fix it, render or return the content directly as a Server Component instead for perf and security.\nLearn more: https://nextjs.org/docs/getting-started/react-essentials".to_string(), "react-dom/server" => "You're importing a component that imports react-dom/server. To fix it, render or return the content directly as a Server Component instead for perf and security.\nLearn more: https://nextjs.org/docs/getting-started/react-essentials".to_string(),
// If importing "next/router", we should tell them to use "next/navigation". // If importing "next/router", we should tell them to use "next/navigation".
"next/router" => r#"You have a Server Component that imports next/router. Use next/navigation instead.\nLearn more: https://nextjs.org/docs/app/api-reference/functions/use-router"#.to_string(), "next/router" => r#"You have a Server Component that imports next/router. Use next/navigation instead.\nLearn more: https://nextjs.org/docs/app/api-reference/functions/use-router"#.to_string(),
_ => format!(r#"You're importing a component that imports {}. It only works in a Client Component but none of its parents are marked with "use client", so they're Server Components by default.\nLearn more: https://nextjs.org/docs/getting-started/react-essentials\n\n"#, source) _ => format!(r#"You're importing a component that imports {source}. It only works in a Client Component but none of its parents are marked with "use client", so they're Server Components by default.\nLearn more: https://nextjs.org/docs/getting-started/react-essentials\n\n"#)
}; };
(msg, span) (msg, span)
...@@ -257,9 +257,9 @@ fn report_error(app_dir: &Option<PathBuf>, filepath: &str, error_kind: RSCErrorK ...@@ -257,9 +257,9 @@ fn report_error(app_dir: &Option<PathBuf>, filepath: &str, error_kind: RSCErrorK
.unwrap_or_default(); .unwrap_or_default();
let msg = if !is_app_dir { let msg = if !is_app_dir {
format!("You're importing a component that needs \"{}\". That only works in a Server Component which is not supported in the pages/ directory. Read more: https://nextjs.org/docs/getting-started/react-essentials#server-components\n\n", source) format!("You're importing a component that needs \"{source}\". That only works in a Server Component which is not supported in the pages/ directory. Read more: https://nextjs.org/docs/getting-started/react-essentials#server-components\n\n")
} else { } else {
format!("You're importing a component that needs \"{}\". That only works in a Server Component but one of its parents is marked with \"use client\", so it's a Client Component.\nLearn more: https://nextjs.org/docs/getting-started/react-essentials\n\n", source) format!("You're importing a component that needs \"{source}\". That only works in a Server Component but one of its parents is marked with \"use client\", so it's a Client Component.\nLearn more: https://nextjs.org/docs/getting-started/react-essentials\n\n")
}; };
(msg, span) (msg, span)
} }
...@@ -267,19 +267,19 @@ fn report_error(app_dir: &Option<PathBuf>, filepath: &str, error_kind: RSCErrorK ...@@ -267,19 +267,19 @@ fn report_error(app_dir: &Option<PathBuf>, filepath: &str, error_kind: RSCErrorK
let msg = if source == "Component" { let msg = if source == "Component" {
"You’re importing a class component. It only works in a Client Component but none of its parents are marked with \"use client\", so they're Server Components by default.\nLearn more: https://nextjs.org/docs/getting-started/react-essentials#client-components\n\n".to_string() "You’re importing a class component. It only works in a Client Component but none of its parents are marked with \"use client\", so they're Server Components by default.\nLearn more: https://nextjs.org/docs/getting-started/react-essentials#client-components\n\n".to_string()
} else { } else {
format!("You're importing a component that needs `{}`. This React hook only works in a client component. To fix, mark the file (or its parent) with the `\"use client\"` directive.\n\n Learn more: https://nextjs.org/docs/app/building-your-application/rendering/client-components\n\n", source) format!("You're importing a component that needs `{source}`. This React hook only works in a client component. To fix, mark the file (or its parent) with the `\"use client\"` directive.\n\n Learn more: https://nextjs.org/docs/app/building-your-application/rendering/client-components\n\n")
}; };
(msg,span) (msg,span)
}, },
RSCErrorKind::NextRscErrErrorFileServerComponent(span) => { RSCErrorKind::NextRscErrErrorFileServerComponent(span) => {
( (
format!("{} must be a Client Component. Add the \"use client\" directive the top of the file to resolve this issue.\nLearn more: https://nextjs.org/docs/getting-started/react-essentials#client-components\n\n", filepath), format!("{filepath} must be a Client Component. Add the \"use client\" directive the top of the file to resolve this issue.\nLearn more: https://nextjs.org/docs/getting-started/react-essentials#client-components\n\n"),
span span
) )
}, },
RSCErrorKind::NextRscErrClientMetadataExport((source, span)) => { RSCErrorKind::NextRscErrClientMetadataExport((source, span)) => {
(format!("You are attempting to export \"{}\" from a component marked with \"use client\", which is disallowed. Either remove the export, or the \"use client\" directive. Read more: https://nextjs.org/docs/getting-started/react-essentials#the-use-client-directive\n\n", source), span) (format!("You are attempting to export \"{source}\" from a component marked with \"use client\", which is disallowed. Either remove the export, or the \"use client\" directive. Read more: https://nextjs.org/docs/getting-started/react-essentials#the-use-client-directive\n\n"), span)
}, },
RSCErrorKind::NextRscErrConflictMetadataExport(span) => ( RSCErrorKind::NextRscErrConflictMetadataExport(span) => (
"\"metadata\" and \"generateMetadata\" cannot be exported at the same time, please keep one of them. Read more: https://nextjs.org/docs/app/api-reference/file-conventions/metadata\n\n".to_string(), "\"metadata\" and \"generateMetadata\" cannot be exported at the same time, please keep one of them. Read more: https://nextjs.org/docs/app/api-reference/file-conventions/metadata\n\n".to_string(),
...@@ -287,7 +287,7 @@ fn report_error(app_dir: &Option<PathBuf>, filepath: &str, error_kind: RSCErrorK ...@@ -287,7 +287,7 @@ fn report_error(app_dir: &Option<PathBuf>, filepath: &str, error_kind: RSCErrorK
), ),
//NEXT_RSC_ERR_INVALID_API //NEXT_RSC_ERR_INVALID_API
RSCErrorKind::NextRscErrInvalidApi((source, span)) => ( RSCErrorKind::NextRscErrInvalidApi((source, span)) => (
format!("\"{}\" is not supported in app/. Read more: https://nextjs.org/docs/app/building-your-application/data-fetching\n\n", source), span format!("\"{source}\" is not supported in app/. Read more: https://nextjs.org/docs/app/building-your-application/data-fetching\n\n"), span
), ),
}; };
...@@ -833,7 +833,7 @@ pub fn server_components_assert( ...@@ -833,7 +833,7 @@ pub fn server_components_assert(
}; };
let filename = match filename { let filename = match filename {
FileName::Custom(path) => format!("<{}>", path), FileName::Custom(path) => format!("<{path}>"),
_ => filename.to_string(), _ => filename.to_string(),
}; };
ReactServerComponentValidator::new(is_react_server_layer, filename, app_dir) ReactServerComponentValidator::new(is_react_server_layer, filename, app_dir)
...@@ -855,7 +855,7 @@ pub fn server_components<C: Comments>( ...@@ -855,7 +855,7 @@ pub fn server_components<C: Comments>(
is_react_server_layer, is_react_server_layer,
comments, comments,
filepath: match filename { filepath: match filename {
FileName::Custom(path) => format!("<{}>", path), FileName::Custom(path) => format!("<{path}>"),
_ => filename.to_string(), _ => filename.to_string(),
}, },
app_dir, app_dir,
......
...@@ -202,7 +202,7 @@ impl<C: Comments> ServerActions<C> { ...@@ -202,7 +202,7 @@ impl<C: Comments> ServerActions<C> {
let mut pats = vec![]; let mut pats = vec![];
for i in 0..ids_from_closure.len() { for i in 0..ids_from_closure.len() {
pats.push(Some(Pat::Ident( pats.push(Some(Pat::Ident(
Ident::new(format!("$$ACTION_ARG_{}", i).into(), DUMMY_SP).into(), Ident::new(format!("$$ACTION_ARG_{i}").into(), DUMMY_SP).into(),
))); )));
} }
let decryption_decl = VarDecl { let decryption_decl = VarDecl {
...@@ -326,7 +326,7 @@ impl<C: Comments> ServerActions<C> { ...@@ -326,7 +326,7 @@ impl<C: Comments> ServerActions<C> {
let mut pats = vec![]; let mut pats = vec![];
for i in 0..ids_from_closure.len() { for i in 0..ids_from_closure.len() {
pats.push(Some(Pat::Ident( pats.push(Some(Pat::Ident(
Ident::new(format!("$$ACTION_ARG_{}", i).into(), DUMMY_SP).into(), Ident::new(format!("$$ACTION_ARG_{i}").into(), DUMMY_SP).into(),
))); )));
} }
let decryption_decl = VarDecl { let decryption_decl = VarDecl {
...@@ -1228,7 +1228,7 @@ fn retain_names_from_declared_idents(child_names: &mut Vec<Name>, current_declar ...@@ -1228,7 +1228,7 @@ fn retain_names_from_declared_idents(child_names: &mut Vec<Name>, current_declar
} }
fn gen_ident(cnt: &mut u32) -> JsWord { fn gen_ident(cnt: &mut u32) -> JsWord {
let id: JsWord = format!("$$ACTION_{}", cnt).into(); let id: JsWord = format!("$$ACTION_{cnt}").into();
*cnt += 1; *cnt += 1;
id id
} }
...@@ -1402,9 +1402,8 @@ fn remove_server_directive_index_in_module( ...@@ -1402,9 +1402,8 @@ fn remove_server_directive_index_in_module(
.struct_span_err( .struct_span_err(
*span, *span,
format!( format!(
"Did you mean \"use server\"? \"{}\" is not a supported \ "Did you mean \"use server\"? \"{value}\" is not a supported \
directive name.", directive name."
value
) )
.as_str(), .as_str(),
) )
...@@ -1507,9 +1506,8 @@ fn remove_server_directive_index_in_fn( ...@@ -1507,9 +1506,8 @@ fn remove_server_directive_index_in_fn(
.struct_span_err( .struct_span_err(
*span, *span,
format!( format!(
"Did you mean \"use server\"? \"{}\" is not a supported \ "Did you mean \"use server\"? \"{value}\" is not a supported \
directive name.", directive name."
value
) )
.as_str(), .as_str(),
) )
...@@ -1635,7 +1633,7 @@ impl VisitMut for ClosureReplacer<'_> { ...@@ -1635,7 +1633,7 @@ impl VisitMut for ClosureReplacer<'_> {
if let Some(index) = self.index(e) { if let Some(index) = self.index(e) {
*e = Expr::Ident(Ident::new( *e = Expr::Ident(Ident::new(
// $$ACTION_ARG_0 // $$ACTION_ARG_0
format!("$$ACTION_ARG_{}", index).into(), format!("$$ACTION_ARG_{index}").into(),
DUMMY_SP, DUMMY_SP,
)); ));
} }
...@@ -1651,7 +1649,7 @@ impl VisitMut for ClosureReplacer<'_> { ...@@ -1651,7 +1649,7 @@ impl VisitMut for ClosureReplacer<'_> {
key: PropName::Ident(i.clone()), key: PropName::Ident(i.clone()),
value: Box::new(Expr::Ident(Ident::new( value: Box::new(Expr::Ident(Ident::new(
// $$ACTION_ARG_0 // $$ACTION_ARG_0
format!("$$ACTION_ARG_{}", index).into(), format!("$$ACTION_ARG_{index}").into(),
DUMMY_SP, DUMMY_SP,
))), ))),
}))); })));
......
...@@ -19,10 +19,7 @@ where ...@@ -19,10 +19,7 @@ where
/// Log the url to view the trace in the browser. /// Log the url to view the trace in the browser.
fn log_web_url(jaeger_web_ui_url: &str, trace_id: &str) { fn log_web_url(jaeger_web_ui_url: &str, trace_id: &str) {
println!( println!("Jaeger trace will be available on {jaeger_web_ui_url}/trace/{trace_id}")
"Jaeger trace will be available on {}/trace/{}",
jaeger_web_ui_url, trace_id
)
} }
/// Send trace JSON to Jaeger using ZipKin API. /// Send trace JSON to Jaeger using ZipKin API.
...@@ -45,7 +42,7 @@ fn send_json_to_zipkin(zipkin_api: &str, value: String) { ...@@ -45,7 +42,7 @@ fn send_json_to_zipkin(zipkin_api: &str, value: String) {
fn pad_zeros(num: u64) -> String { fn pad_zeros(num: u64) -> String {
let mut num_str = num.to_string(); let mut num_str = num.to_string();
while num_str.len() < 16 { while num_str.len() < 16 {
num_str = format!("0{}", num_str); num_str = format!("0{num_str}");
} }
num_str num_str
} }
...@@ -54,9 +51,9 @@ fn main() { ...@@ -54,9 +51,9 @@ fn main() {
let service_name = "nextjs"; let service_name = "nextjs";
let ipv4 = "127.0.0.1"; let ipv4 = "127.0.0.1";
let port = 9411; let port = 9411;
let zipkin_url = format!("http://{}:{}", ipv4, port); let zipkin_url = format!("http://{ipv4}:{port}");
let jaeger_web_ui_url = format!("http://{}:16686", ipv4); let jaeger_web_ui_url = format!("http://{ipv4}:16686");
let zipkin_api = format!("{}/api/v2/spans", zipkin_url); let zipkin_api = format!("{zipkin_url}/api/v2/spans");
let mut logged_url = false; let mut logged_url = false;
let mut local_endpoint = Map::new(); let mut local_endpoint = Map::new();
...@@ -100,7 +97,7 @@ fn main() { ...@@ -100,7 +97,7 @@ fn main() {
}) })
.collect::<Value>(), .collect::<Value>(),
Err(e) => { Err(e) => {
println!("{}", e); println!("{e}");
continue; continue;
} }
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment