summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
Diffstat (limited to 'cli')
-rw-r--r--cli/diff.rs13
-rw-r--r--cli/fmt_errors.rs25
-rw-r--r--cli/lsp/language_server.rs13
-rw-r--r--cli/lsp/path_to_regex.rs17
-rw-r--r--cli/tests/integration/vendor_tests.rs26
-rw-r--r--cli/tools/test.rs27
-rw-r--r--cli/tools/vendor/analyze.rs2
-rw-r--r--cli/tools/vendor/build.rs21
8 files changed, 86 insertions, 58 deletions
diff --git a/cli/diff.rs b/cli/diff.rs
index f5596bef5..9aa0b5a44 100644
--- a/cli/diff.rs
+++ b/cli/diff.rs
@@ -2,6 +2,7 @@
use crate::colors;
use dissimilar::{diff as difference, Chunk};
+use std::fmt::Write as _;
/// Print diff of the same file_path, before and after formatting.
///
@@ -113,12 +114,14 @@ impl DiffBuilder {
fn write_line_diff(&mut self) {
let split = self.orig.split('\n').enumerate();
for (i, s) in split {
- self.output.push_str(&format!(
+ write!(
+ self.output,
"{:width$}{} ",
self.orig_line + i,
colors::gray(" |"),
width = self.line_number_width
- ));
+ )
+ .unwrap();
self.output.push_str(&fmt_rem());
self.output.push_str(s);
self.output.push('\n');
@@ -126,12 +129,14 @@ impl DiffBuilder {
let split = self.edit.split('\n').enumerate();
for (i, s) in split {
- self.output.push_str(&format!(
+ write!(
+ self.output,
"{:width$}{} ",
self.edit_line + i,
colors::gray(" |"),
width = self.line_number_width
- ));
+ )
+ .unwrap();
self.output.push_str(&fmt_add());
self.output.push_str(s);
self.output.push('\n');
diff --git a/cli/fmt_errors.rs b/cli/fmt_errors.rs
index 37a58364a..759850cec 100644
--- a/cli/fmt_errors.rs
+++ b/cli/fmt_errors.rs
@@ -7,6 +7,7 @@ use crate::colors::yellow;
use deno_core::error::format_file_name;
use deno_core::error::JsError;
use deno_core::error::JsStackFrame;
+use std::fmt::Write as _;
// Keep in sync with `/core/error.js`.
pub fn format_location(frame: &JsStackFrame) -> String {
@@ -29,9 +30,9 @@ pub fn format_location(frame: &JsStackFrame) -> String {
result += &cyan("<anonymous>").to_string();
}
if let Some(line_number) = frame.line_number {
- result += &format!("{}{}", ":", yellow(&line_number.to_string()));
+ write!(result, ":{}", yellow(&line_number.to_string())).unwrap();
if let Some(column_number) = frame.column_number {
- result += &format!("{}{}", ":", yellow(&column_number.to_string()));
+ write!(result, ":{}", yellow(&column_number.to_string())).unwrap();
}
}
result
@@ -61,18 +62,18 @@ fn format_frame(frame: &JsStackFrame) -> String {
if let Some(function_name) = &frame.function_name {
if let Some(type_name) = &frame.type_name {
if !function_name.starts_with(type_name) {
- formatted_method += &format!("{}.", type_name);
+ write!(formatted_method, "{}.", type_name).unwrap();
}
}
formatted_method += function_name;
if let Some(method_name) = &frame.method_name {
if !function_name.ends_with(method_name) {
- formatted_method += &format!(" [as {}]", method_name);
+ write!(formatted_method, " [as {}]", method_name).unwrap();
}
}
} else {
if let Some(type_name) = &frame.type_name {
- formatted_method += &format!("{}.", type_name);
+ write!(formatted_method, "{}.", type_name).unwrap();
}
if let Some(method_name) = &frame.method_name {
formatted_method += method_name
@@ -84,7 +85,7 @@ fn format_frame(frame: &JsStackFrame) -> String {
} else if frame.is_constructor {
result += "new ";
if let Some(function_name) = &frame.function_name {
- result += &italic_bold(&function_name).to_string();
+ write!(result, "{}", italic_bold(&function_name)).unwrap();
} else {
result += &cyan("<anonymous>").to_string();
}
@@ -94,7 +95,7 @@ fn format_frame(frame: &JsStackFrame) -> String {
result += &format_location(frame);
return result;
}
- result += &format!(" ({})", format_location(frame));
+ write!(result, " ({})", format_location(frame)).unwrap();
result
}
@@ -156,7 +157,7 @@ fn format_js_error_inner(js_error: &JsError, is_child: bool) -> String {
for aggregated_error in aggregated {
let error_string = format_js_error_inner(aggregated_error, true);
for line in error_string.trim_start_matches("Uncaught ").lines() {
- s.push_str(&format!("\n {}", line));
+ write!(s, "\n {}", line).unwrap();
}
}
}
@@ -174,14 +175,16 @@ fn format_js_error_inner(js_error: &JsError, is_child: bool) -> String {
0,
));
for frame in &js_error.frames {
- s.push_str(&format!("\n at {}", format_frame(frame)));
+ write!(s, "\n at {}", format_frame(frame)).unwrap();
}
if let Some(cause) = &js_error.cause {
let error_string = format_js_error_inner(cause, true);
- s.push_str(&format!(
+ write!(
+ s,
"\nCaused by: {}",
error_string.trim_start_matches("Uncaught ")
- ));
+ )
+ .unwrap();
}
s
}
diff --git a/cli/lsp/language_server.rs b/cli/lsp/language_server.rs
index 909d17bfe..1e9da54d6 100644
--- a/cli/lsp/language_server.rs
+++ b/cli/lsp/language_server.rs
@@ -13,6 +13,7 @@ use log::error;
use log::warn;
use serde_json::from_value;
use std::env;
+use std::fmt::Write as _;
use std::path::PathBuf;
use std::sync::Arc;
use tokio::fs;
@@ -2878,7 +2879,8 @@ impl Inner {
let measures = self.performance.to_vec();
let workspace_settings = self.config.get_workspace_settings();
- contents.push_str(&format!(
+ write!(
+ contents,
r#"# Deno Language Server Status
## Workspace Settings
@@ -2914,16 +2916,19 @@ impl Inner {
.map(|m| m.to_string())
.collect::<Vec<String>>()
.join("\n - ")
- ));
+ )
+ .unwrap();
contents
.push_str("\n## Performance\n\n|Name|Duration|Count|\n|---|---|---|\n");
let mut averages = self.performance.averages();
averages.sort();
for average in averages {
- contents.push_str(&format!(
+ writeln!(
+ contents,
"|{}|{}ms|{}|\n",
average.name, average.average_duration, average.count
- ));
+ )
+ .unwrap();
}
Some(contents)
} else {
diff --git a/cli/lsp/path_to_regex.rs b/cli/lsp/path_to_regex.rs
index b1929c9b9..937136ce3 100644
--- a/cli/lsp/path_to_regex.rs
+++ b/cli/lsp/path_to_regex.rs
@@ -33,6 +33,7 @@ use once_cell::sync::Lazy;
use regex::Regex;
use std::collections::HashMap;
use std::fmt;
+use std::fmt::Write as _;
use std::iter::Peekable;
static ESCAPE_STRING_RE: Lazy<Regex> =
@@ -268,9 +269,9 @@ impl StringOrVec {
let mut s = String::new();
for (i, segment) in v.iter().enumerate() {
if omit_initial_prefix && i == 0 {
- s.push_str(&format!("{}{}", segment, suffix));
+ write!(s, "{}{}", segment, suffix).unwrap();
} else {
- s.push_str(&format!("{}{}{}", prefix, segment, suffix));
+ write!(s, "{}{}{}", prefix, segment, suffix).unwrap();
}
}
s
@@ -618,10 +619,10 @@ pub fn tokens_to_regex(
if end {
if !strict {
- route.push_str(&format!(r"{}?", delimiter));
+ write!(route, r"{}?", delimiter).unwrap();
}
if has_ends_with {
- route.push_str(&format!(r"(?={})", ends_with));
+ write!(route, r"(?={})", ends_with).unwrap();
} else {
route.push('$');
}
@@ -639,11 +640,11 @@ pub fn tokens_to_regex(
};
if !strict {
- route.push_str(&format!(r"(?:{}(?={}))?", delimiter, ends_with));
+ write!(route, r"(?:{}(?={}))?", delimiter, ends_with).unwrap();
}
if !is_end_deliminated {
- route.push_str(&format!(r"(?={}|{})", delimiter, ends_with));
+ write!(route, r"(?={}|{})", delimiter, ends_with).unwrap();
}
}
@@ -753,7 +754,7 @@ impl Compiler {
}
}
}
- path.push_str(&format!("{}{}{}", prefix, segment, suffix));
+ write!(path, "{}{}{}", prefix, segment, suffix).unwrap();
}
}
}
@@ -772,7 +773,7 @@ impl Compiler {
}
let prefix = k.prefix.clone().unwrap_or_default();
let suffix = k.suffix.clone().unwrap_or_default();
- path.push_str(&format!("{}{}{}", prefix, s, suffix));
+ write!(path, "{}{}{}", prefix, s, suffix).unwrap();
}
None => {
if !optional {
diff --git a/cli/tests/integration/vendor_tests.rs b/cli/tests/integration/vendor_tests.rs
index 9b8211cd1..54809dacf 100644
--- a/cli/tests/integration/vendor_tests.rs
+++ b/cli/tests/integration/vendor_tests.rs
@@ -3,6 +3,7 @@
use deno_core::serde_json;
use deno_core::serde_json::json;
use pretty_assertions::assert_eq;
+use std::fmt::Write as _;
use std::path::PathBuf;
use std::process::Stdio;
use test_util as util;
@@ -530,20 +531,19 @@ fn update_existing_config_test() {
fn success_text(module_count: &str, dir: &str, has_import_map: bool) -> String {
let mut text = format!("Vendored {} into {} directory.", module_count, dir);
if has_import_map {
- text.push_str(&
- format!(
- concat!(
- "\n\nTo use vendored modules, specify the `--import-map {}import_map.json` flag when ",
- r#"invoking Deno subcommands or add an `"importMap": "<path_to_vendored_import_map>"` "#,
- "entry to a deno.json file.",
- ),
- if dir != "vendor/" {
- format!("{}{}", dir.trim_end_matches('/'), if cfg!(windows) { '\\' } else {'/'})
- } else {
- dir.to_string()
- }
- )
+ let f = format!(
+ concat!(
+ "\n\nTo use vendored modules, specify the `--import-map {}import_map.json` flag when ",
+ r#"invoking Deno subcommands or add an `"importMap": "<path_to_vendored_import_map>"` "#,
+ "entry to a deno.json file.",
+ ),
+ if dir != "vendor/" {
+ format!("{}{}", dir.trim_end_matches('/'), if cfg!(windows) { '\\' } else {'/'})
+ } else {
+ dir.to_string()
+ }
);
+ write!(text, "{}", f).unwrap();
}
text
}
diff --git a/cli/tools/test.rs b/cli/tools/test.rs
index ab6ded1b0..4bebe6fee 100644
--- a/cli/tools/test.rs
+++ b/cli/tools/test.rs
@@ -53,6 +53,7 @@ use serde::Deserialize;
use std::collections::BTreeMap;
use std::collections::HashMap;
use std::collections::HashSet;
+use std::fmt::Write as _;
use std::io::Read;
use std::io::Write;
use std::num::NonZeroUsize;
@@ -618,27 +619,33 @@ impl TestReporter for PrettyTestReporter {
let mut summary_result = String::new();
- summary_result.push_str(&format!(
+ write!(
+ summary_result,
"{} passed{} | {} failed{}",
summary.passed,
get_steps_text(summary.passed_steps),
summary.failed,
get_steps_text(summary.failed_steps + summary.pending_steps),
- ));
+ )
+ .unwrap();
let ignored_steps = get_steps_text(summary.ignored_steps);
if summary.ignored > 0 || !ignored_steps.is_empty() {
- summary_result
- .push_str(&format!(" | {} ignored{}", summary.ignored, ignored_steps))
- };
+ write!(
+ summary_result,
+ " | {} ignored{}",
+ summary.ignored, ignored_steps
+ )
+ .unwrap()
+ }
if summary.measured > 0 {
- summary_result.push_str(&format!(" | {} measured", summary.measured,))
- };
+ write!(summary_result, " | {} measured", summary.measured,).unwrap();
+ }
if summary.filtered_out > 0 {
- summary_result
- .push_str(&format!(" | {} filtered out", summary.filtered_out,))
+ write!(summary_result, " | {} filtered out", summary.filtered_out)
+ .unwrap()
};
println!(
@@ -891,7 +898,7 @@ fn extract_files_from_regex_blocks(
let mut file_source = String::new();
for line in lines_regex.captures_iter(text) {
let text = line.get(1).unwrap();
- file_source.push_str(&format!("{}\n", text.as_str()));
+ writeln!(file_source, "{}", text.as_str()).unwrap();
}
let file_specifier = deno_core::resolve_url_or_path(&format!(
diff --git a/cli/tools/vendor/analyze.rs b/cli/tools/vendor/analyze.rs
index 6a1f53aae..0aa7010c7 100644
--- a/cli/tools/vendor/analyze.rs
+++ b/cli/tools/vendor/analyze.rs
@@ -25,7 +25,7 @@ struct DefaultExportFinder {
has_default_export: bool,
}
-impl<'a> Visit for DefaultExportFinder {
+impl Visit for DefaultExportFinder {
noop_visit_type!();
fn visit_export_default_decl(&mut self, _: &ExportDefaultDecl) {
diff --git a/cli/tools/vendor/build.rs b/cli/tools/vendor/build.rs
index ecb7db717..341ef8684 100644
--- a/cli/tools/vendor/build.rs
+++ b/cli/tools/vendor/build.rs
@@ -1,5 +1,6 @@
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
+use std::fmt::Write as _;
use std::path::Path;
use std::path::PathBuf;
@@ -164,10 +165,14 @@ fn build_proxy_module_source(
module: &Module,
proxied_module: &ProxiedModule,
) -> String {
- let mut text = format!(
- "// @deno-types=\"{}\"\n",
+ let mut text = String::new();
+ writeln!(
+ text,
+ "// @deno-types=\"{}\"",
proxied_module.declaration_specifier
- );
+ )
+ .unwrap();
+
let relative_specifier = format!(
"./{}",
proxied_module
@@ -179,15 +184,17 @@ fn build_proxy_module_source(
// for simplicity, always include the `export *` statement as it won't error
// even when the module does not contain a named export
- text.push_str(&format!("export * from \"{}\";\n", relative_specifier));
+ writeln!(text, "export * from \"{}\";", relative_specifier).unwrap();
// add a default export if one exists in the module
if let Some(parsed_source) = module.maybe_parsed_source.as_ref() {
if has_default_export(parsed_source) {
- text.push_str(&format!(
- "export {{ default }} from \"{}\";\n",
+ writeln!(
+ text,
+ "export {{ default }} from \"{}\";",
relative_specifier
- ));
+ )
+ .unwrap();
}
}