Skip to content

Commit

Permalink
Add clippy to CI and fix several clippy warnings (#625)
Browse files Browse the repository at this point in the history
* Remove ambiguity when using deps
* Fix doc and some linting hints
* Make tests more readable
* Run clippy during the CI checks
* Fix formatting
* A few more linting fixes
* Remove old comment
  • Loading branch information
chevdor committed Jul 8, 2021
1 parent ac72c85 commit 68511bc
Show file tree
Hide file tree
Showing 26 changed files with 193 additions and 214 deletions.
3 changes: 2 additions & 1 deletion .gitlab-ci.yml
Expand Up @@ -45,8 +45,9 @@ checkstyle-linux-stable:
<<: *only
<<: *docker-env
script:
- rustup component add rustfmt
- rustup component add rustfmt clippy
- cargo fmt --all -- --check
- cargo clippy
allow_failure: true

# test rust stable
Expand Down
2 changes: 1 addition & 1 deletion core-client/transports/src/lib.rs
Expand Up @@ -178,7 +178,7 @@ impl<T: DeserializeOwned + Unpin + 'static> Stream for TypedSubscriptionStream<T
.map_err(|error| RpcError::ParseError(self.returns.into(), Box::new(error))),
),
None => None,
Some(Err(err)) => Some(Err(err.into())),
Some(Err(err)) => Some(Err(err)),
}
.into()
}
Expand Down
2 changes: 1 addition & 1 deletion core-client/transports/src/transports/duplex.rs
Expand Up @@ -281,7 +281,7 @@ where
}
match self.outgoing.pop_front() {
Some(request) => {
if let Err(_) = self.sink.as_mut().start_send(request) {
if self.sink.as_mut().start_send(request).is_err() {
// the channel is disconnected.
return err().into();
}
Expand Down
2 changes: 1 addition & 1 deletion core-client/transports/src/transports/mod.rs
Expand Up @@ -151,7 +151,7 @@ impl From<ClientResponse> for Result<Value, Error> {
(Some(_), _, Some(error)) => {
let error = serde_json::from_value::<Error>(error.to_owned())
.ok()
.unwrap_or_else(|| Error::parse_error());
.unwrap_or_else(Error::parse_error);
Err(error)
}
_ => Ok(n.params.into()),
Expand Down
16 changes: 6 additions & 10 deletions core/src/io.rs
Expand Up @@ -8,7 +8,6 @@ use std::pin::Pin;
use std::sync::Arc;

use futures_util::{self, future, FutureExt};
use serde_json;

use crate::calls::{
Metadata, RemoteProcedure, RpcMethod, RpcMethodSimple, RpcMethodSync, RpcNotification, RpcNotificationSimple,
Expand Down Expand Up @@ -60,10 +59,10 @@ impl Default for Compatibility {

impl Compatibility {
fn is_version_valid(self, version: Option<Version>) -> bool {
match (self, version) {
(Compatibility::V1, None) | (Compatibility::V2, Some(Version::V2)) | (Compatibility::Both, _) => true,
_ => false,
}
matches!(
(self, version),
(Compatibility::V1, None) | (Compatibility::V2, Some(Version::V2)) | (Compatibility::Both, _)
)
}

fn default_version(self) -> Option<Version> {
Expand Down Expand Up @@ -208,10 +207,7 @@ impl<T: Metadata, S: Middleware<T>> MetaIoHandler<T, S> {
use self::future::Either::{Left, Right};
fn as_string(response: Option<Response>) -> Option<String> {
let res = response.map(write_response);
debug!(target: "rpc", "Response: {}.", match res {
Some(ref res) => res,
None => "None",
});
debug!(target: "rpc", "Response: {}.", res.as_ref().unwrap_or(&"None".to_string()));
res
}

Expand All @@ -237,7 +233,7 @@ impl<T: Metadata, S: Middleware<T>> MetaIoHandler<T, S> {
}

fn outputs_as_batch(outs: Vec<Option<Output>>) -> Option<Response> {
let outs: Vec<_> = outs.into_iter().filter_map(|v| v).collect();
let outs: Vec<_> = outs.into_iter().flatten().collect();
if outs.is_empty() {
None
} else {
Expand Down
20 changes: 9 additions & 11 deletions core/src/lib.rs
Expand Up @@ -3,19 +3,17 @@
//! Right now it supports only server side handling requests.
//!
//! ```rust
//! use jsonrpc_core::*;
//! use jsonrpc_core::IoHandler;
//! use jsonrpc_core::Value;
//! let mut io = IoHandler::new();
//! io.add_sync_method("say_hello", |_| {
//! Ok(Value::String("Hello World!".into()))
//! });
//!
//! fn main() {
//! let mut io = IoHandler::new();
//! io.add_sync_method("say_hello", |_| {
//! Ok(Value::String("Hello World!".into()))
//! });
//! let request = r#"{"jsonrpc": "2.0", "method": "say_hello", "params": [42, 23], "id": 1}"#;
//! let response = r#"{"jsonrpc":"2.0","result":"Hello World!","id":1}"#;
//!
//! let request = r#"{"jsonrpc": "2.0", "method": "say_hello", "params": [42, 23], "id": 1}"#;
//! let response = r#"{"jsonrpc":"2.0","result":"Hello World!","id":1}"#;
//!
//! assert_eq!(io.handle_request_sync(request), Some(response.to_string()));
//! }
//! assert_eq!(io.handle_request_sync(request), Some(response.to_string()));
//! ```

#![deny(missing_docs)]
Expand Down
1 change: 0 additions & 1 deletion core/src/types/params.rs
@@ -1,7 +1,6 @@
//! jsonrpc params field

use serde::de::DeserializeOwned;
use serde_json;
use serde_json::value::from_value;

use super::{Error, Value};
Expand Down
4 changes: 2 additions & 2 deletions core/src/types/response.rs
Expand Up @@ -43,8 +43,8 @@ impl Output {
/// Creates new output given `Result`, `Id` and `Version`.
pub fn from(result: CoreResult<Value>, id: Id, jsonrpc: Option<Version>) -> Self {
match result {
Ok(result) => Output::Success(Success { id, jsonrpc, result }),
Err(error) => Output::Failure(Failure { id, jsonrpc, error }),
Ok(result) => Output::Success(Success { jsonrpc, result, id }),
Err(error) => Output::Failure(Failure { jsonrpc, error, id }),
}
}

Expand Down

0 comments on commit 68511bc

Please sign in to comment.