apply clippy lints - wasm, nodejs

This commit is contained in:
freestrings 2019-06-25 23:31:52 +09:00
parent 319186b1d9
commit 9a28faf058
5 changed files with 22 additions and 16 deletions

View File

@ -29,6 +29,8 @@ matrix:
- cargo build --verbose --all - cargo build --verbose --all
- cargo clippy --all-targets --all-features -- -D warnings -A clippy::cognitive_complexity - cargo clippy --all-targets --all-features -- -D warnings -A clippy::cognitive_complexity
- cargo test --verbose --all - cargo test --verbose --all
- cd wasm && cargo clippy -- -D warnings -A clippy::suspicious_else_formatting
- cd ../nodejs/native && cargo clippy -- -D warnings
after_success: | after_success: |
cargo tarpaulin --exclude-files nodejs wasm parser/mod.rs --out Xml cargo tarpaulin --exclude-files nodejs wasm parser/mod.rs --out Xml
bash <(curl -s https://codecov.io/bash) bash <(curl -s https://codecov.io/bash)

View File

@ -2,9 +2,6 @@
set -e set -e
cargo clippy -- -D warnings && \
cargo clippy --all-targets --all-features -- -D warnings -A clippy::cognitive_complexity
# project_root # project_root
DIR="$(pwd)" DIR="$(pwd)"
WASM="${DIR}"/wasm WASM="${DIR}"/wasm
@ -31,6 +28,16 @@ __cargo_clean () {
cd "${DIR}" && cargo clean cd "${DIR}" && cargo clean
} }
if [ "$1" = "clippy" ]
then
echo
__msg "clippy"
cargo clippy -- -D warnings && \
cargo clippy --all-targets --all-features -- -D warnings -A clippy::cognitive_complexity && \
cd "${WASM}" && cargo clippy -- -A clippy::suspicious_else_formatting && \
cd "${NODEJS}" && cargo clippy
fi
echo echo
__msg "clean" __msg "clean"
rm -rf \ rm -rf \

View File

@ -206,7 +206,7 @@ declare_types! {
{ {
let guard = ctx.lock(); let guard = ctx.lock();
let mut this = this.borrow_mut(&guard); let mut this = this.borrow_mut(&guard);
let _ = this.path(&path); this.path(&path);
} }
Ok(JsUndefined::new().upcast()) Ok(JsUndefined::new().upcast())
@ -219,7 +219,7 @@ declare_types! {
{ {
let guard = ctx.lock(); let guard = ctx.lock();
let mut this = this.borrow_mut(&guard); let mut this = this.borrow_mut(&guard);
let _ = this.value(&json_str); this.value(&json_str);
} }
Ok(JsUndefined::new().upcast()) Ok(JsUndefined::new().upcast())

View File

@ -132,6 +132,7 @@ extern crate serde_json;
use serde_json::Value; use serde_json::Value;
pub use parser::Parser;
pub use select::JsonPathError; pub use select::JsonPathError;
pub use select::{Selector, SelectorMut}; pub use select::{Selector, SelectorMut};

View File

@ -102,7 +102,7 @@ pub fn compile(path: &str) -> JsValue {
}, },
Err(e) => JsValue::from_str(&format!("{:?}", e)), Err(e) => JsValue::from_str(&format!("{:?}", e)),
} }
}) as Box<Fn(JsValue) -> JsValue>); }) as Box<dyn Fn(JsValue) -> JsValue>);
let ret = cb.as_ref().clone(); let ret = cb.as_ref().clone();
cb.forget(); cb.forget();
@ -131,8 +131,8 @@ pub fn selector(js_value: JsValue) -> JsValue {
Err(e) => JsValue::from_str(&format!("{:?}", e)), Err(e) => JsValue::from_str(&format!("{:?}", e)),
} }
} }
Err(e) => return JsValue::from_str(&format!("{:?}", JsonPathError::Path(e))), Err(e) => JsValue::from_str(&format!("{:?}", JsonPathError::Path(e))),
}) as Box<Fn(String) -> JsValue>, }) as Box<dyn Fn(String) -> JsValue>,
); );
let ret = cb.as_ref().clone(); let ret = cb.as_ref().clone();
@ -193,6 +193,7 @@ pub fn replace_with(js_value: JsValue, path: &str, fun: js_sys::Function) -> JsV
/// lifetime 제약으로 Selector를 사용 할 수 없다. /// lifetime 제약으로 Selector를 사용 할 수 없다.
/// ///
#[wasm_bindgen] #[wasm_bindgen]
#[derive(Default)]
pub struct Selector { pub struct Selector {
path: Option<String>, path: Option<String>,
value: Option<Value>, value: Option<Value>,
@ -202,10 +203,7 @@ pub struct Selector {
impl Selector { impl Selector {
#[wasm_bindgen(constructor)] #[wasm_bindgen(constructor)]
pub fn new() -> Self { pub fn new() -> Self {
Selector { Selector::default()
path: None,
value: None,
}
} }
#[wasm_bindgen(catch)] #[wasm_bindgen(catch)]
@ -263,6 +261,7 @@ impl Selector {
/// `wasm_bindgen` 제약으로 builder-pattern을 구사 할 수 없다. /// `wasm_bindgen` 제약으로 builder-pattern을 구사 할 수 없다.
/// ///
#[wasm_bindgen] #[wasm_bindgen]
#[derive(Default)]
pub struct SelectorMut { pub struct SelectorMut {
path: Option<String>, path: Option<String>,
value: Option<Value>, value: Option<Value>,
@ -272,10 +271,7 @@ pub struct SelectorMut {
impl SelectorMut { impl SelectorMut {
#[wasm_bindgen(constructor)] #[wasm_bindgen(constructor)]
pub fn new() -> Self { pub fn new() -> Self {
SelectorMut { SelectorMut::default()
path: None,
value: None,
}
} }
#[wasm_bindgen(catch)] #[wasm_bindgen(catch)]