1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

refactor(cli): remove unnecessary format! calls (#8315)

This commit is contained in:
KNnut 2020-11-09 22:38:29 +08:00 committed by GitHub
parent 8b7f5531ee
commit aaf7166a9d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 42 additions and 42 deletions

View file

@ -299,5 +299,5 @@ fn node_tcp() -> Result<HttpBenchmarkResult> {
fn hyper_http(exe: &str) -> Result<HttpBenchmarkResult> { fn hyper_http(exe: &str) -> Result<HttpBenchmarkResult> {
let port = get_port(); let port = get_port();
println!("http_benchmark testing RUST hyper"); println!("http_benchmark testing RUST hyper");
run(&[exe, &format!("{}", port)], port, None, None) run(&[exe, &port.to_string()], port, None, None)
} }

View file

@ -546,7 +546,7 @@ mod tests {
} }
]); ]);
let diagnostics: Diagnostics = serde_json::from_value(value).unwrap(); let diagnostics: Diagnostics = serde_json::from_value(value).unwrap();
let actual = format!("{}", diagnostics); let actual = diagnostics.to_string();
assert_eq!( assert_eq!(
strip_ansi_codes(&actual), strip_ansi_codes(&actual),
"TS5023 [ERROR]: Unknown compiler option \'invalid\'." "TS5023 [ERROR]: Unknown compiler option \'invalid\'."
@ -573,7 +573,7 @@ mod tests {
} }
]); ]);
let diagnostics: Diagnostics = serde_json::from_value(value).unwrap(); let diagnostics: Diagnostics = serde_json::from_value(value).unwrap();
let actual = format!("{}", diagnostics); let actual = diagnostics.to_string();
assert_eq!(strip_ansi_codes(&actual), "TS2584 [ERROR]: Cannot find name \'console\'. Do you need to change your target library? Try changing the `lib` compiler option to include \'dom\'.\nconsole.log(\"a\");\n~~~~~~~\n at test.ts:1:1"); assert_eq!(strip_ansi_codes(&actual), "TS2584 [ERROR]: Cannot find name \'console\'. Do you need to change your target library? Try changing the `lib` compiler option to include \'dom\'.\nconsole.log(\"a\");\n~~~~~~~\n at test.ts:1:1");
} }
@ -614,7 +614,7 @@ mod tests {
} }
]); ]);
let diagnostics: Diagnostics = serde_json::from_value(value).unwrap(); let diagnostics: Diagnostics = serde_json::from_value(value).unwrap();
let actual = format!("{}", diagnostics); let actual = diagnostics.to_string();
assert_eq!(strip_ansi_codes(&actual), "TS2552 [ERROR]: Cannot find name \'foo_Bar\'. Did you mean \'foo_bar\'?\nfoo_Bar();\n~~~~~~~\n at test.ts:8:1\n\n \'foo_bar\' is declared here.\n function foo_bar() {\n ~~~~~~~\n at test.ts:4:10"); assert_eq!(strip_ansi_codes(&actual), "TS2552 [ERROR]: Cannot find name \'foo_Bar\'. Did you mean \'foo_bar\'?\nfoo_Bar();\n~~~~~~~\n at test.ts:8:1\n\n \'foo_bar\' is declared here.\n function foo_bar() {\n ~~~~~~~\n at test.ts:4:10");
} }
@ -655,7 +655,7 @@ mod tests {
} }
]; ];
let diagnostics: Diagnostic = serde_json::from_value(value).unwrap(); let diagnostics: Diagnostic = serde_json::from_value(value).unwrap();
let actual = format!("{}", diagnostics); let actual = diagnostics.to_string();
assert_eq!(strip_ansi_codes(&actual), "TS2551 [ERROR]: Property \'ppid\' does not exist on type \'typeof Deno\'. \'Deno.ppid\' is an unstable API. Did you forget to run with the \'--unstable\' flag, or did you mean \'pid\'?\nconsole.log(Deno.ppid);\n ~~~~\n at file:///cli/tests/unstable_ts2551.ts:1:18\n\n \'pid\' is declared here.\n export const pid: number;\n ~~~\n at asset:///lib.deno.ns.d.ts:90:16"); assert_eq!(strip_ansi_codes(&actual), "TS2551 [ERROR]: Property \'ppid\' does not exist on type \'typeof Deno\'. \'Deno.ppid\' is an unstable API. Did you forget to run with the \'--unstable\' flag, or did you mean \'pid\'?\nconsole.log(Deno.ppid);\n ~~~~\n at file:///cli/tests/unstable_ts2551.ts:1:18\n\n \'pid\' is declared here.\n export const pid: number;\n ~~~\n at asset:///lib.deno.ns.d.ts:90:16");
} }
} }

View file

@ -6,27 +6,27 @@ use std::fmt;
use std::fmt::Write; use std::fmt::Write;
fn fmt_add() -> String { fn fmt_add() -> String {
format!("{}", colors::green_bold("+")) colors::green_bold("+").to_string()
} }
fn fmt_add_text(x: &str) -> String { fn fmt_add_text(x: &str) -> String {
format!("{}", colors::green(x)) colors::green(x).to_string()
} }
fn fmt_add_text_highlight(x: &str) -> String { fn fmt_add_text_highlight(x: &str) -> String {
format!("{}", colors::black_on_green(x)) colors::black_on_green(x).to_string()
} }
fn fmt_rem() -> String { fn fmt_rem() -> String {
format!("{}", colors::red_bold("-")) colors::red_bold("-").to_string()
} }
fn fmt_rem_text(x: &str) -> String { fn fmt_rem_text(x: &str) -> String {
format!("{}", colors::red(x)) colors::red(x).to_string()
} }
fn fmt_rem_text_highlight(x: &str) -> String { fn fmt_rem_text_highlight(x: &str) -> String {
format!("{}", colors::white_on_red(x)) colors::white_on_red(x).to_string()
} }
fn write_line_diff( fn write_line_diff(

View file

@ -272,7 +272,7 @@ mod test {
#[test] #[test]
fn test_module_graph_info_display() { fn test_module_graph_info_display() {
let fixture = get_fixture(); let fixture = get_fixture();
let actual = format!("{}", fixture); let actual = fixture.to_string();
assert!(actual.contains(" /a/b/c.ts")); assert!(actual.contains(" /a/b/c.ts"));
assert!(actual.contains(" 99 unique")); assert!(actual.contains(" 99 unique"));
assert!(actual.contains("(12.06KB)")); assert!(actual.contains("(12.06KB)"));

View file

@ -934,7 +934,7 @@ impl InspectorSession {
let response = response_rx.await.unwrap(); let response = response_rx.await.unwrap();
if let Some(error) = response.get("error") { if let Some(error) = response.get("error") {
return Err(generic_error(format!("{}", error))); return Err(generic_error(error.to_string()));
} }
let result = response.get("result").unwrap().clone(); let result = response.get("result").unwrap().clone();

View file

@ -276,9 +276,9 @@ pub fn format_diagnostic(
colors::red(&"^".repeat(line_len - range.start.col)) colors::red(&"^".repeat(line_len - range.start.col))
)); ));
} else if range.end.line == i { } else if range.end.line == i {
lines.push(format!("{}", colors::red(&"^".repeat(range.end.col)))); lines.push(colors::red(&"^".repeat(range.end.col)).to_string());
} else if line_len != 0 { } else if line_len != 0 {
lines.push(format!("{}", colors::red(&"^".repeat(line_len)))); lines.push(colors::red(&"^".repeat(line_len)).to_string());
} }
} }
} }

View file

@ -187,7 +187,7 @@ async fn info_command(
if json { if json {
write_json_to_stdout(&json!(info))?; write_json_to_stdout(&json!(info))?;
} else { } else {
write_to_stdout_ignore_sigpipe(format!("{}", info).as_bytes())?; write_to_stdout_ignore_sigpipe(info.to_string().as_bytes())?;
} }
Ok(()) Ok(())
} else { } else {

View file

@ -194,7 +194,7 @@ pub fn serialize_media_type<S>(mt: &MediaType, s: S) -> Result<S::Ok, S::Error>
where where
S: Serializer, S: Serializer,
{ {
s.serialize_str(&format!("{}", mt)) s.serialize_str(&mt.to_string())
} }
#[cfg(test)] #[cfg(test)]
@ -269,15 +269,15 @@ mod tests {
#[test] #[test]
fn test_display() { fn test_display() {
assert_eq!(format!("{}", MediaType::JavaScript), "JavaScript"); assert_eq!(MediaType::JavaScript.to_string(), "JavaScript");
assert_eq!(format!("{}", MediaType::JSX), "JSX"); assert_eq!(MediaType::JSX.to_string(), "JSX");
assert_eq!(format!("{}", MediaType::TypeScript), "TypeScript"); assert_eq!(MediaType::TypeScript.to_string(), "TypeScript");
assert_eq!(format!("{}", MediaType::Dts), "Dts"); assert_eq!(MediaType::Dts.to_string(), "Dts");
assert_eq!(format!("{}", MediaType::TSX), "TSX"); assert_eq!(MediaType::TSX.to_string(), "TSX");
assert_eq!(format!("{}", MediaType::Json), "Json"); assert_eq!(MediaType::Json.to_string(), "Json");
assert_eq!(format!("{}", MediaType::Wasm), "Wasm"); assert_eq!(MediaType::Wasm.to_string(), "Wasm");
assert_eq!(format!("{}", MediaType::TsBuildInfo), "TsBuildInfo"); assert_eq!(MediaType::TsBuildInfo.to_string(), "TsBuildInfo");
assert_eq!(format!("{}", MediaType::SourceMap), "SourceMap"); assert_eq!(MediaType::SourceMap.to_string(), "SourceMap");
assert_eq!(format!("{}", MediaType::Unknown), "Unknown"); assert_eq!(MediaType::Unknown.to_string(), "Unknown");
} }
} }

View file

@ -232,7 +232,7 @@ impl Permissions {
)); ));
} }
Ok(self.query_net( Ok(self.query_net(
&format!("{}", parsed.host().unwrap()), &parsed.host().unwrap().to_string(),
parsed.port_or_known_default(), parsed.port_or_known_default(),
)) ))
} }

View file

@ -245,31 +245,31 @@ impl Highlighter for LineHighlighter {
.regex .regex
.replace_all(&line.to_string(), |caps: &Captures<'_>| { .replace_all(&line.to_string(), |caps: &Captures<'_>| {
if let Some(cap) = caps.name("comment") { if let Some(cap) = caps.name("comment") {
format!("{}", colors::gray(cap.as_str())) colors::gray(cap.as_str()).to_string()
} else if let Some(cap) = caps.name("string") { } else if let Some(cap) = caps.name("string") {
format!("{}", colors::green(cap.as_str())) colors::green(cap.as_str()).to_string()
} else if let Some(cap) = caps.name("regexp") { } else if let Some(cap) = caps.name("regexp") {
format!("{}", colors::red(cap.as_str())) colors::red(cap.as_str()).to_string()
} else if let Some(cap) = caps.name("number") { } else if let Some(cap) = caps.name("number") {
format!("{}", colors::yellow(cap.as_str())) colors::yellow(cap.as_str()).to_string()
} else if let Some(cap) = caps.name("boolean") { } else if let Some(cap) = caps.name("boolean") {
format!("{}", colors::yellow(cap.as_str())) colors::yellow(cap.as_str()).to_string()
} else if let Some(cap) = caps.name("null") { } else if let Some(cap) = caps.name("null") {
format!("{}", colors::yellow(cap.as_str())) colors::yellow(cap.as_str()).to_string()
} else if let Some(cap) = caps.name("undefined") { } else if let Some(cap) = caps.name("undefined") {
format!("{}", colors::gray(cap.as_str())) colors::gray(cap.as_str()).to_string()
} else if let Some(cap) = caps.name("keyword") { } else if let Some(cap) = caps.name("keyword") {
format!("{}", colors::cyan(cap.as_str())) colors::cyan(cap.as_str()).to_string()
} else if let Some(cap) = caps.name("infinity") { } else if let Some(cap) = caps.name("infinity") {
format!("{}", colors::yellow(cap.as_str())) colors::yellow(cap.as_str()).to_string()
} else if let Some(cap) = caps.name("classes") { } else if let Some(cap) = caps.name("classes") {
format!("{}", colors::green_bold(cap.as_str())) colors::green_bold(cap.as_str()).to_string()
} else if let Some(cap) = caps.name("hexnumber") { } else if let Some(cap) = caps.name("hexnumber") {
format!("{}", colors::yellow(cap.as_str())) colors::yellow(cap.as_str()).to_string()
} else if let Some(cap) = caps.name("octalnumber") { } else if let Some(cap) = caps.name("octalnumber") {
format!("{}", colors::yellow(cap.as_str())) colors::yellow(cap.as_str()).to_string()
} else if let Some(cap) = caps.name("binarynumber") { } else if let Some(cap) = caps.name("binarynumber") {
format!("{}", colors::yellow(cap.as_str())) colors::yellow(cap.as_str()).to_string()
} else { } else {
caps[0].to_string() caps[0].to_string()
} }

View file

@ -3814,7 +3814,7 @@ async fn inspector_does_not_hang() {
for i in 0..128u32 { for i in 0..128u32 {
let request_id = i + 10; let request_id = i + 10;
// Expect the number {i} on stdout. // Expect the number {i} on stdout.
let s = format!("{}", i); let s = i.to_string();
assert_eq!(stdout_lines.next().unwrap(), s); assert_eq!(stdout_lines.next().unwrap(), s);
// Expect hitting the `debugger` statement. // Expect hitting the `debugger` statement.
let s = r#"{"method":"Debugger.paused","#; let s = r#"{"method":"Debugger.paused","#;