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

Silence clippy warnings and format source code

This commit is contained in:
Bert Belder 2019-04-09 07:15:49 +02:00
parent fe2f3ba889
commit 4ffe1612ff
6 changed files with 55 additions and 49 deletions

View file

@ -143,7 +143,7 @@ fn lazy_start(parent_state: ThreadSafeState) -> ResourceId {
}).map_err(|_| ())
}));
rid
}).clone()
}).to_owned()
}
fn req(specifier: &str, referrer: &str, cmd_id: u32) -> Buf {

View file

@ -579,8 +579,8 @@ fn fetch_remote_source_async(
),
|(
dir,
maybe_initial_module_name,
maybe_initial_filename,
mut maybe_initial_module_name,
mut maybe_initial_filename,
module_name,
filename,
)| {
@ -595,8 +595,6 @@ fn fetch_remote_source_async(
.map_err(DenoError::from);
match resolve_result {
Ok((new_module_name, new_filename)) => {
let mut maybe_initial_module_name = maybe_initial_module_name;
let mut maybe_initial_filename = maybe_initial_filename;
if maybe_initial_module_name.is_none() {
maybe_initial_module_name = Some(module_name.clone());
maybe_initial_filename = Some(filename.clone());
@ -623,7 +621,11 @@ fn fetch_remote_source_async(
// Write file and create .headers.json for the file.
deno_fs::write_file(&p, &source, 0o666)?;
{
save_source_code_headers(&filename, maybe_content_type.clone(), None);
save_source_code_headers(
&filename,
maybe_content_type.clone(),
None,
);
}
// Check if this file is downloaded due to some old redirect request.
if maybe_initial_filename.is_some() {
@ -834,7 +836,7 @@ fn save_source_code_headers(
value_map.insert(REDIRECT_TO.to_string(), json!(redirect_to.unwrap()));
}
// Only save to file when there is actually data.
if value_map.len() > 0 {
if !value_map.is_empty() {
let _ = serde_json::to_string(&value_map).map(|s| {
// It is possible that we need to create file
// with parent folders not yet created.

View file

@ -101,7 +101,7 @@ pub fn set_flags(
NO_COLOR Set to disable color";
let clap_app = App::new("deno")
.global_settings(&vec![AppSettings::ColorNever])
.global_settings(&[AppSettings::ColorNever])
.settings(&app_settings[..])
.after_help(env_variables_help)
.arg(

View file

@ -47,7 +47,7 @@ fn resolve_uri_from_location(base_uri: &Uri, location: &str) -> Uri {
// assuming path-noscheme | path-empty
let mut new_uri_parts = base_uri.clone().into_parts();
let base_uri_path_str = base_uri.path().to_owned();
let segs: Vec<&str> = base_uri_path_str.rsplitn(2, "/").collect();
let segs: Vec<&str> = base_uri_path_str.rsplitn(2, '/').collect();
new_uri_parts.path_and_query = Some(
format!("{}/{}", segs.last().unwrap_or(&""), location)
.parse()
@ -86,50 +86,54 @@ pub fn fetch_string_once(
client
.get(url.clone())
.map_err(DenoError::from)
.and_then(move |response| -> Box<dyn Future<Item = FetchAttempt, Error = DenoError> + Send> {
if response.status().is_redirection() {
let location_string = response
.headers()
.get("location")
.expect("url redirection should provide 'location' header")
.to_str()
.unwrap()
.to_string();
debug!("Redirecting to {}...", &location_string);
let new_url = resolve_uri_from_location(&url, &location_string);
// Boxed trait object turns out to be the savior for 2+ types yielding same results.
return Box::new(
future::ok(None).join3(
.and_then(
move |response| -> Box<
dyn Future<Item = FetchAttempt, Error = DenoError> + Send,
> {
if response.status().is_redirection() {
let location_string = response
.headers()
.get("location")
.expect("url redirection should provide 'location' header")
.to_str()
.unwrap()
.to_string();
debug!("Redirecting to {}...", &location_string);
let new_url = resolve_uri_from_location(&url, &location_string);
// Boxed trait object turns out to be the savior for 2+ types yielding same results.
return Box::new(future::ok(None).join3(
future::ok(None),
future::ok(Some(FetchOnceResult::Redirect(new_url))
))
);
} else if response.status().is_client_error() || response.status().is_server_error() {
return Box::new(future::err(
errors::new(errors::ErrorKind::Other,
format!("Import '{}' failed: {}", &url, response.status()))
future::ok(Some(FetchOnceResult::Redirect(new_url))),
));
}
let content_type = response
.headers()
.get(CONTENT_TYPE)
.map(|content_type| content_type.to_str().unwrap().to_owned());
let body = response
.into_body()
.concat2()
.map(|body| String::from_utf8(body.to_vec()).ok())
.map_err(DenoError::from);
Box::new(body.join3(
future::ok(content_type),
future::ok(None)
))
})
} else if response.status().is_client_error()
|| response.status().is_server_error()
{
return Box::new(future::err(errors::new(
errors::ErrorKind::Other,
format!("Import '{}' failed: {}", &url, response.status()),
)));
}
let content_type = response
.headers()
.get(CONTENT_TYPE)
.map(|content_type| content_type.to_str().unwrap().to_owned());
let body = response
.into_body()
.concat2()
.map(|body| String::from_utf8(body.to_vec()).ok())
.map_err(DenoError::from);
Box::new(body.join3(future::ok(content_type), future::ok(None)))
},
)
.and_then(move |(maybe_code, maybe_content_type, maybe_redirect)| {
if let Some(redirect) = maybe_redirect {
future::ok(redirect)
} else {
// maybe_code should always contain code here!
future::ok(FetchOnceResult::Code(maybe_code.unwrap(), maybe_content_type))
future::ok(FetchOnceResult::Code(
maybe_code.unwrap(),
maybe_content_type,
))
}
})
}

View file

@ -214,7 +214,7 @@ fn op_now(
assert_eq!(data.len(), 0);
let seconds = state.start_time.elapsed().as_secs();
let mut subsec_nanos = state.start_time.elapsed().subsec_nanos();
let reduced_time_precision = 2000000; // 2ms in nanoseconds
let reduced_time_precision = 2_000_000; // 2ms in nanoseconds
// If the permission is not enabled
// Round the nano result on 2 milliseconds

View file

@ -268,7 +268,7 @@ impl DenoPermissions {
}
pub fn allows_high_precision(&self) -> bool {
return self.allow_high_precision.is_allow();
self.allow_high_precision.is_allow()
}
pub fn revoke_run(&self) -> DenoResult<()> {
@ -297,7 +297,7 @@ impl DenoPermissions {
}
pub fn revoke_high_precision(&self) -> DenoResult<()> {
self.allow_high_precision.revoke();
return Ok(());
Ok(())
}
}