mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 17:34:47 -05:00
Clippy fixes (also fixes build with nightly) (#1527)
This commit is contained in:
parent
48ca06e420
commit
d8adeb41de
12 changed files with 32 additions and 76 deletions
|
@ -29,9 +29,9 @@ pub struct CodeFetchOutput {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CodeFetchOutput {
|
impl CodeFetchOutput {
|
||||||
pub fn js_source<'a>(&'a self) -> String {
|
pub fn js_source(&self) -> String {
|
||||||
if self.media_type == msg::MediaType::Json {
|
if self.media_type == msg::MediaType::Json {
|
||||||
return String::from(format!("export default {};", self.source_code));
|
return format!("export default {};", self.source_code);
|
||||||
}
|
}
|
||||||
match self.maybe_output_code {
|
match self.maybe_output_code {
|
||||||
None => self.source_code.clone(),
|
None => self.source_code.clone(),
|
||||||
|
|
|
@ -265,10 +265,10 @@ impl DenoDir {
|
||||||
if let Some(output) = maybe_remote_source {
|
if let Some(output) = maybe_remote_source {
|
||||||
return Ok(output);
|
return Ok(output);
|
||||||
}
|
}
|
||||||
return Err(DenoError::from(std::io::Error::new(
|
Err(DenoError::from(std::io::Error::new(
|
||||||
std::io::ErrorKind::NotFound,
|
std::io::ErrorKind::NotFound,
|
||||||
format!("cannot find remote file '{}'", filename),
|
format!("cannot find remote file '{}'", filename),
|
||||||
)));
|
)))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn code_fetch(
|
pub fn code_fetch(
|
||||||
|
@ -371,7 +371,7 @@ impl DenoDir {
|
||||||
specifier, referrer
|
specifier, referrer
|
||||||
);
|
);
|
||||||
|
|
||||||
if referrer.starts_with(".") {
|
if referrer.starts_with('.') {
|
||||||
let cwd = std::env::current_dir().unwrap();
|
let cwd = std::env::current_dir().unwrap();
|
||||||
let referrer_path = cwd.join(referrer);
|
let referrer_path = cwd.join(referrer);
|
||||||
referrer = referrer_path.to_str().unwrap().to_string() + "/";
|
referrer = referrer_path.to_str().unwrap().to_string() + "/";
|
||||||
|
@ -423,16 +423,10 @@ impl DenoDir {
|
||||||
impl SourceMapGetter for DenoDir {
|
impl SourceMapGetter for DenoDir {
|
||||||
fn get_source_map(&self, script_name: &str) -> Option<String> {
|
fn get_source_map(&self, script_name: &str) -> Option<String> {
|
||||||
match self.code_fetch(script_name, ".") {
|
match self.code_fetch(script_name, ".") {
|
||||||
Err(_e) => {
|
Err(_e) => None,
|
||||||
return None;
|
|
||||||
}
|
|
||||||
Ok(out) => match out.maybe_source_map {
|
Ok(out) => match out.maybe_source_map {
|
||||||
None => {
|
None => None,
|
||||||
return None;
|
Some(source_map) => Some(source_map),
|
||||||
}
|
|
||||||
Some(source_map) => {
|
|
||||||
return Some(source_map);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -941,15 +935,9 @@ mod tests {
|
||||||
let test_cases = [
|
let test_cases = [
|
||||||
(
|
(
|
||||||
"./subdir/print_hello.ts",
|
"./subdir/print_hello.ts",
|
||||||
add_root!(
|
add_root!("/Users/rld/go/src/github.com/denoland/deno/testdata/006_url_imports.ts"),
|
||||||
"/Users/rld/go/src/github.com/denoland/deno/testdata/006_url_imports.ts"
|
add_root!("/Users/rld/go/src/github.com/denoland/deno/testdata/subdir/print_hello.ts"),
|
||||||
),
|
add_root!("/Users/rld/go/src/github.com/denoland/deno/testdata/subdir/print_hello.ts"),
|
||||||
add_root!(
|
|
||||||
"/Users/rld/go/src/github.com/denoland/deno/testdata/subdir/print_hello.ts"
|
|
||||||
),
|
|
||||||
add_root!(
|
|
||||||
"/Users/rld/go/src/github.com/denoland/deno/testdata/subdir/print_hello.ts"
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"testdata/001_hello.js",
|
"testdata/001_hello.js",
|
||||||
|
|
|
@ -312,17 +312,12 @@ pub fn v8_set_flags(args: Vec<String>) -> Vec<String> {
|
||||||
// Store the length of the c_argv array in a local variable. We'll pass
|
// Store the length of the c_argv array in a local variable. We'll pass
|
||||||
// a pointer to this local variable to deno_set_v8_flags(), which then
|
// a pointer to this local variable to deno_set_v8_flags(), which then
|
||||||
// updates its value.
|
// updates its value.
|
||||||
#[cfg_attr(
|
|
||||||
feature = "cargo-clippy",
|
|
||||||
allow(cast_possible_truncation, cast_possible_wrap)
|
|
||||||
)]
|
|
||||||
let mut c_argv_len = c_argv.len() as c_int;
|
let mut c_argv_len = c_argv.len() as c_int;
|
||||||
// Let v8 parse the arguments it recognizes and remove them from c_argv.
|
// Let v8 parse the arguments it recognizes and remove them from c_argv.
|
||||||
unsafe {
|
unsafe {
|
||||||
libdeno::deno_set_v8_flags(&mut c_argv_len, c_argv.as_mut_ptr());
|
libdeno::deno_set_v8_flags(&mut c_argv_len, c_argv.as_mut_ptr());
|
||||||
};
|
};
|
||||||
// If c_argv_len was updated we have to change the length of c_argv to match.
|
// If c_argv_len was updated we have to change the length of c_argv to match.
|
||||||
#[cfg_attr(feature = "cargo-clippy", allow(cast_sign_loss))]
|
|
||||||
c_argv.truncate(c_argv_len as usize);
|
c_argv.truncate(c_argv_len as usize);
|
||||||
// Copy the modified arguments list into a proper rust vec and return it.
|
// Copy the modified arguments list into a proper rust vec and return it.
|
||||||
c_argv
|
c_argv
|
||||||
|
|
|
@ -89,7 +89,7 @@ impl IsolateState {
|
||||||
permissions: DenoPermissions::new(&flags),
|
permissions: DenoPermissions::new(&flags),
|
||||||
flags,
|
flags,
|
||||||
metrics: Metrics::default(),
|
metrics: Metrics::default(),
|
||||||
worker_channels: worker_channels.map(|wc| Mutex::new(wc)),
|
worker_channels: worker_channels.map(Mutex::new),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,7 +212,7 @@ impl Isolate {
|
||||||
|
|
||||||
pub fn last_exception(&self) -> Option<JSError> {
|
pub fn last_exception(&self) -> Option<JSError> {
|
||||||
let ptr = unsafe { libdeno::deno_last_exception(self.libdeno_isolate) };
|
let ptr = unsafe { libdeno::deno_last_exception(self.libdeno_isolate) };
|
||||||
if ptr == std::ptr::null() {
|
if ptr.is_null() {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
let cstr = unsafe { CStr::from_ptr(ptr) };
|
let cstr = unsafe { CStr::from_ptr(ptr) };
|
||||||
|
@ -220,7 +220,7 @@ impl Isolate {
|
||||||
debug!("v8_exception\n{}\n", v8_exception);
|
debug!("v8_exception\n{}\n", v8_exception);
|
||||||
let js_error = JSError::from_v8_exception(v8_exception).unwrap();
|
let js_error = JSError::from_v8_exception(v8_exception).unwrap();
|
||||||
let js_error_mapped = js_error.apply_source_map(&self.state.dir);
|
let js_error_mapped = js_error.apply_source_map(&self.state.dir);
|
||||||
return Some(js_error_mapped);
|
Some(js_error_mapped)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,7 +60,7 @@ impl ToString for StackFrame {
|
||||||
fn to_string(&self) -> String {
|
fn to_string(&self) -> String {
|
||||||
// Note when we print to string, we change from 0-indexed to 1-indexed.
|
// Note when we print to string, we change from 0-indexed to 1-indexed.
|
||||||
let (line, column) = (self.line + 1, self.column + 1);
|
let (line, column) = (self.line + 1, self.column + 1);
|
||||||
if self.function_name.len() > 0 {
|
if !self.function_name.is_empty() {
|
||||||
format!(
|
format!(
|
||||||
" at {} ({}:{}:{})",
|
" at {} ({}:{}:{})",
|
||||||
self.function_name, self.script_name, line, column
|
self.function_name, self.script_name, line, column
|
||||||
|
@ -228,10 +228,10 @@ impl SourceMap {
|
||||||
// Ugly. Maybe use serde_derive.
|
// Ugly. Maybe use serde_derive.
|
||||||
match serde_json::from_str::<serde_json::Value>(json_str) {
|
match serde_json::from_str::<serde_json::Value>(json_str) {
|
||||||
Ok(serde_json::Value::Object(map)) => match map["mappings"].as_str() {
|
Ok(serde_json::Value::Object(map)) => match map["mappings"].as_str() {
|
||||||
None => return None,
|
None => None,
|
||||||
Some(mappings_str) => {
|
Some(mappings_str) => {
|
||||||
match parse_mappings::<()>(mappings_str.as_bytes()) {
|
match parse_mappings::<()>(mappings_str.as_bytes()) {
|
||||||
Err(_) => return None,
|
Err(_) => None,
|
||||||
Ok(mappings) => {
|
Ok(mappings) => {
|
||||||
if !map["sources"].is_array() {
|
if !map["sources"].is_array() {
|
||||||
return None;
|
return None;
|
||||||
|
@ -248,12 +248,12 @@ impl SourceMap {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Some(SourceMap { sources, mappings });
|
Some(SourceMap { sources, mappings })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
_ => return None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
21
src/main.rs
21
src/main.rs
|
@ -1,25 +1,4 @@
|
||||||
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
||||||
use dirs;
|
|
||||||
use flatbuffers;
|
|
||||||
use getopts;
|
|
||||||
use http;
|
|
||||||
use hyper;
|
|
||||||
use hyper_rustls;
|
|
||||||
use libc;
|
|
||||||
use rand;
|
|
||||||
use remove_dir_all;
|
|
||||||
use ring;
|
|
||||||
use rustyline;
|
|
||||||
use source_map_mappings;
|
|
||||||
use tempfile;
|
|
||||||
use tokio;
|
|
||||||
use tokio_executor;
|
|
||||||
use tokio_fs;
|
|
||||||
use tokio_io;
|
|
||||||
use tokio_process;
|
|
||||||
use tokio_threadpool;
|
|
||||||
use url;
|
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate lazy_static;
|
extern crate lazy_static;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
#![allow(unused_imports)]
|
#![allow(unused_imports)]
|
||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
#![cfg_attr(feature = "cargo-clippy", allow(clippy, pedantic))]
|
#![cfg_attr(
|
||||||
|
feature = "cargo-clippy",
|
||||||
|
allow(clippy::all, clippy::pedantic)
|
||||||
|
)]
|
||||||
use flatbuffers;
|
use flatbuffers;
|
||||||
use std::sync::atomic::Ordering;
|
use std::sync::atomic::Ordering;
|
||||||
|
|
||||||
|
|
|
@ -1003,7 +1003,6 @@ fn op_read_dir(
|
||||||
path: Some(path),
|
path: Some(path),
|
||||||
mode: get_mode(&metadata.permissions()),
|
mode: get_mode(&metadata.permissions()),
|
||||||
has_mode: cfg!(target_family = "unix"),
|
has_mode: cfg!(target_family = "unix"),
|
||||||
..Default::default()
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}).collect();
|
}).collect();
|
||||||
|
@ -1172,9 +1171,6 @@ fn op_repl_readline(
|
||||||
let prompt = inner.prompt().unwrap().to_owned();
|
let prompt = inner.prompt().unwrap().to_owned();
|
||||||
debug!("op_repl_readline {} {}", rid, prompt);
|
debug!("op_repl_readline {} {}", rid, prompt);
|
||||||
|
|
||||||
// Ignore this clippy warning until this issue is addressed:
|
|
||||||
// https://github.com/rust-lang-nursery/rust-clippy/issues/1684
|
|
||||||
#[cfg_attr(feature = "cargo-clippy", allow(redundant_closure_call))]
|
|
||||||
blocking(base.sync(), move || -> OpResult {
|
blocking(base.sync(), move || -> OpResult {
|
||||||
let line = resources::readline(rid, &prompt)?;
|
let line = resources::readline(rid, &prompt)?;
|
||||||
|
|
||||||
|
@ -1237,9 +1233,6 @@ fn op_listen(
|
||||||
assert_eq!(network, "tcp");
|
assert_eq!(network, "tcp");
|
||||||
let address = inner.address().unwrap();
|
let address = inner.address().unwrap();
|
||||||
|
|
||||||
// Ignore this clippy warning until this issue is addressed:
|
|
||||||
// https://github.com/rust-lang-nursery/rust-clippy/issues/1684
|
|
||||||
#[cfg_attr(feature = "cargo-clippy", allow(redundant_closure_call))]
|
|
||||||
Box::new(futures::future::result((move || {
|
Box::new(futures::future::result((move || {
|
||||||
let addr = resolve_addr(address).wait()?;
|
let addr = resolve_addr(address).wait()?;
|
||||||
|
|
||||||
|
|
|
@ -71,7 +71,7 @@ impl Repl {
|
||||||
repl
|
repl
|
||||||
}
|
}
|
||||||
|
|
||||||
fn load_history(&mut self) -> () {
|
fn load_history(&mut self) {
|
||||||
debug!("Loading REPL history: {:?}", self.history_file);
|
debug!("Loading REPL history: {:?}", self.history_file);
|
||||||
self
|
self
|
||||||
.editor
|
.editor
|
||||||
|
|
|
@ -60,7 +60,7 @@ impl Future for ResolveAddrFuture {
|
||||||
// I absolutely despise the .to_socket_addrs() API.
|
// I absolutely despise the .to_socket_addrs() API.
|
||||||
let r = addr_port_pair
|
let r = addr_port_pair
|
||||||
.to_socket_addrs()
|
.to_socket_addrs()
|
||||||
.map_err(|e| ResolveAddrError::Resolution(e));
|
.map_err(ResolveAddrError::Resolution);
|
||||||
|
|
||||||
r.and_then(|mut iter| match iter.next() {
|
r.and_then(|mut iter| match iter.next() {
|
||||||
Some(a) => Ok(Async::Ready(a)),
|
Some(a) => Ok(Async::Ready(a)),
|
||||||
|
@ -71,11 +71,11 @@ impl Future for ResolveAddrFuture {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn split<'a>(address: &'a str) -> Option<(&'a str, u16)> {
|
fn split(address: &str) -> Option<(&str, u16)> {
|
||||||
address.rfind(":").and_then(|i| {
|
address.rfind(':').and_then(|i| {
|
||||||
let (a, p) = address.split_at(i);
|
let (a, p) = address.split_at(i);
|
||||||
// Default to localhost if given just the port. Example: ":80"
|
// Default to localhost if given just the port. Example: ":80"
|
||||||
let addr = if a.len() > 0 { a } else { "0.0.0.0" };
|
let addr = if !a.is_empty() { a } else { "0.0.0.0" };
|
||||||
// If this looks like an ipv6 IP address. Example: "[2001:db8::1]"
|
// If this looks like an ipv6 IP address. Example: "[2001:db8::1]"
|
||||||
// Then we remove the brackets.
|
// Then we remove the brackets.
|
||||||
let addr = if addr.starts_with('[') && addr.ends_with(']') {
|
let addr = if addr.starts_with('[') && addr.ends_with(']') {
|
||||||
|
|
|
@ -452,7 +452,7 @@ pub fn eager_read<T: AsMut<[u8]>>(
|
||||||
resource: Resource,
|
resource: Resource,
|
||||||
mut buf: T,
|
mut buf: T,
|
||||||
) -> EagerRead<Resource, T> {
|
) -> EagerRead<Resource, T> {
|
||||||
Either::A(tokio_io::io::read(resource, buf)).into()
|
Either::A(tokio_io::io::read(resource, buf))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(unix))]
|
#[cfg(not(unix))]
|
||||||
|
@ -460,12 +460,12 @@ pub fn eager_write<T: AsRef<[u8]>>(
|
||||||
resource: Resource,
|
resource: Resource,
|
||||||
buf: T,
|
buf: T,
|
||||||
) -> EagerWrite<Resource, T> {
|
) -> EagerWrite<Resource, T> {
|
||||||
Either::A(tokio_write::write(resource, buf)).into()
|
Either::A(tokio_write::write(resource, buf))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(unix))]
|
#[cfg(not(unix))]
|
||||||
pub fn eager_accept(resource: Resource) -> EagerAccept {
|
pub fn eager_accept(resource: Resource) -> EagerAccept {
|
||||||
Either::A(tokio_util::accept(resource)).into()
|
Either::A(tokio_util::accept(resource))
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is an optimization that Tokio should do.
|
// This is an optimization that Tokio should do.
|
||||||
|
|
|
@ -83,9 +83,7 @@ pub fn spawn(
|
||||||
resource.close();
|
resource.close();
|
||||||
}).unwrap();
|
}).unwrap();
|
||||||
|
|
||||||
let resource = c.wait().unwrap();
|
c.wait().unwrap()
|
||||||
|
|
||||||
resource
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
Loading…
Add table
Reference in a new issue