[CI] run clippy checks & fix clippy warnings (#840)

* Run clippy checks

* Fix clippy warnings

* Clippy checks for `sea-orm-*` crates

* Fix clippy warnings

* Fixup
This commit is contained in:
Billy Chan 2022-07-10 15:38:38 +08:00 committed by GitHub
parent a1bf662fc3
commit 1a3e8c456a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 74 additions and 30 deletions

View File

@ -87,8 +87,8 @@ jobs:
- id: git-log - id: git-log
run: echo "::set-output name=message::$(git log --no-merges -1 --oneline)" run: echo "::set-output name=message::$(git log --no-merges -1 --oneline)"
clippy-fmt: clippy:
name: Clippy + Fmt name: Clippy
runs-on: ubuntu-20.04 runs-on: ubuntu-20.04
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
@ -97,23 +97,44 @@ jobs:
with: with:
profile: minimal profile: minimal
toolchain: stable toolchain: stable
components: clippy, rustfmt components: clippy
override: true override: true
# Make sure files are formatted - name: Run clippy on `sea-orm` workspace
- uses: actions-rs/cargo@v1 uses: actions-rs/cargo@v1
with:
command: fmt
args: >
--all
# Run clippy
- uses: actions-rs/cargo@v1
with: with:
command: clippy command: clippy
args: > args: >
--all-targets
--all --all
--
-D warnings
- name: Run clippy on `sea-orm-cli`
uses: actions-rs/cargo@v1
with:
command: clippy
args: >
--manifest-path sea-orm-cli/Cargo.toml
--
-D warnings
- name: Run clippy on `sea-orm-migration`
uses: actions-rs/cargo@v1
with:
command: clippy
args: >
--manifest-path sea-orm-migration/Cargo.toml
--
-D warnings
- name: Run clippy on `sea-orm-rocket`
uses: actions-rs/cargo@v1
with:
command: clippy
args: >
--manifest-path sea-orm-rocket/Cargo.toml
--
-D warnings
compile-sqlite: compile-sqlite:
name: Compile SQLite name: Compile SQLite

View File

@ -25,6 +25,6 @@ pub trait MigrationTrait: MigrationName + Send + Sync {
/// Define actions to perform when rolling back the migration /// Define actions to perform when rolling back the migration
async fn down(&self, _manager: &SchemaManager) -> Result<(), DbErr> { async fn down(&self, _manager: &SchemaManager) -> Result<(), DbErr> {
Err(DbErr::Migration(format!("We Don't Do That Here"))) Err(DbErr::Migration("We Don't Do That Here".to_owned()))
} }
} }

View File

@ -176,6 +176,7 @@ impl<D: Database> Initializer<D> {
/// ///
/// This method should never need to be called manually. See the [crate /// This method should never need to be called manually. See the [crate
/// docs](crate) for usage information. /// docs](crate) for usage information.
#[allow(clippy::new_without_default)]
pub fn new() -> Self { pub fn new() -> Self {
Self(None, std::marker::PhantomData) Self(None, std::marker::PhantomData)
} }

View File

@ -105,6 +105,7 @@ impl ConnectionTrait for DatabaseConnection {
} }
#[instrument(level = "trace")] #[instrument(level = "trace")]
#[allow(unused_variables)]
async fn execute(&self, stmt: Statement) -> Result<ExecResult, DbErr> { async fn execute(&self, stmt: Statement) -> Result<ExecResult, DbErr> {
match self { match self {
#[cfg(feature = "sqlx-mysql")] #[cfg(feature = "sqlx-mysql")]
@ -120,6 +121,7 @@ impl ConnectionTrait for DatabaseConnection {
} }
#[instrument(level = "trace")] #[instrument(level = "trace")]
#[allow(unused_variables)]
async fn query_one(&self, stmt: Statement) -> Result<Option<QueryResult>, DbErr> { async fn query_one(&self, stmt: Statement) -> Result<Option<QueryResult>, DbErr> {
match self { match self {
#[cfg(feature = "sqlx-mysql")] #[cfg(feature = "sqlx-mysql")]
@ -135,6 +137,7 @@ impl ConnectionTrait for DatabaseConnection {
} }
#[instrument(level = "trace")] #[instrument(level = "trace")]
#[allow(unused_variables)]
async fn query_all(&self, stmt: Statement) -> Result<Vec<QueryResult>, DbErr> { async fn query_all(&self, stmt: Statement) -> Result<Vec<QueryResult>, DbErr> {
match self { match self {
#[cfg(feature = "sqlx-mysql")] #[cfg(feature = "sqlx-mysql")]
@ -160,6 +163,7 @@ impl<'a> StreamTrait<'a> for DatabaseConnection {
type Stream = crate::QueryStream; type Stream = crate::QueryStream;
#[instrument(level = "trace")] #[instrument(level = "trace")]
#[allow(unused_variables, unreachable_code)]
fn stream( fn stream(
&'a self, &'a self,
stmt: Statement, stmt: Statement,

View File

@ -12,6 +12,7 @@ pub(crate) struct MetricStream<'a> {
} }
impl<'a> MetricStream<'a> { impl<'a> MetricStream<'a> {
#[allow(dead_code)]
pub(crate) fn new<S>( pub(crate) fn new<S>(
metric_callback: &'a Option<crate::metric::Callback>, metric_callback: &'a Option<crate::metric::Callback>,
stmt: &'a Statement, stmt: &'a Statement,

View File

@ -1,6 +1,6 @@
#![allow(missing_docs)] #![allow(missing_docs, unreachable_code, unused_variables)]
use std::{pin::Pin, task::Poll, time::SystemTime}; use std::{pin::Pin, task::Poll};
#[cfg(feature = "mock")] #[cfg(feature = "mock")]
use std::sync::Arc; use std::sync::Arc;
@ -126,7 +126,7 @@ impl QueryStream {
#[cfg(feature = "sqlx-mysql")] #[cfg(feature = "sqlx-mysql")]
InnerConnection::MySql(c) => { InnerConnection::MySql(c) => {
let query = crate::driver::sqlx_mysql::sqlx_query(stmt); let query = crate::driver::sqlx_mysql::sqlx_query(stmt);
let _start = _metric_callback.is_some().then(SystemTime::now); let _start = _metric_callback.is_some().then(std::time::SystemTime::now);
let stream = c let stream = c
.fetch(query) .fetch(query)
.map_ok(Into::into) .map_ok(Into::into)
@ -137,7 +137,7 @@ impl QueryStream {
#[cfg(feature = "sqlx-postgres")] #[cfg(feature = "sqlx-postgres")]
InnerConnection::Postgres(c) => { InnerConnection::Postgres(c) => {
let query = crate::driver::sqlx_postgres::sqlx_query(stmt); let query = crate::driver::sqlx_postgres::sqlx_query(stmt);
let _start = _metric_callback.is_some().then(SystemTime::now); let _start = _metric_callback.is_some().then(std::time::SystemTime::now);
let stream = c let stream = c
.fetch(query) .fetch(query)
.map_ok(Into::into) .map_ok(Into::into)
@ -148,7 +148,7 @@ impl QueryStream {
#[cfg(feature = "sqlx-sqlite")] #[cfg(feature = "sqlx-sqlite")]
InnerConnection::Sqlite(c) => { InnerConnection::Sqlite(c) => {
let query = crate::driver::sqlx_sqlite::sqlx_query(stmt); let query = crate::driver::sqlx_sqlite::sqlx_query(stmt);
let _start = _metric_callback.is_some().then(SystemTime::now); let _start = _metric_callback.is_some().then(std::time::SystemTime::now);
let stream = c let stream = c
.fetch(query) .fetch(query)
.map_ok(Into::into) .map_ok(Into::into)
@ -158,7 +158,7 @@ impl QueryStream {
} }
#[cfg(feature = "mock")] #[cfg(feature = "mock")]
InnerConnection::Mock(c) => { InnerConnection::Mock(c) => {
let _start = _metric_callback.is_some().then(SystemTime::now); let _start = _metric_callback.is_some().then(std::time::SystemTime::now);
let stream = c.fetch(stmt); let stream = c.fetch(stmt);
let elapsed = _start.map(|s| s.elapsed().unwrap_or_default()); let elapsed = _start.map(|s| s.elapsed().unwrap_or_default());
MetricStream::new(_metric_callback, stmt, elapsed, stream) MetricStream::new(_metric_callback, stmt, elapsed, stream)

View File

@ -1,6 +1,6 @@
#![allow(missing_docs)] #![allow(missing_docs)]
use std::{ops::DerefMut, pin::Pin, task::Poll, time::SystemTime}; use std::{ops::DerefMut, pin::Pin, task::Poll};
use futures::Stream; use futures::Stream;
#[cfg(feature = "sqlx-dep")] #[cfg(feature = "sqlx-dep")]
@ -37,6 +37,7 @@ impl<'a> std::fmt::Debug for TransactionStream<'a> {
impl<'a> TransactionStream<'a> { impl<'a> TransactionStream<'a> {
#[instrument(level = "trace", skip(metric_callback))] #[instrument(level = "trace", skip(metric_callback))]
#[allow(unused_variables)]
pub(crate) fn build( pub(crate) fn build(
conn: MutexGuard<'a, InnerConnection>, conn: MutexGuard<'a, InnerConnection>,
stmt: Statement, stmt: Statement,
@ -50,7 +51,7 @@ impl<'a> TransactionStream<'a> {
#[cfg(feature = "sqlx-mysql")] #[cfg(feature = "sqlx-mysql")]
InnerConnection::MySql(c) => { InnerConnection::MySql(c) => {
let query = crate::driver::sqlx_mysql::sqlx_query(stmt); let query = crate::driver::sqlx_mysql::sqlx_query(stmt);
let _start = _metric_callback.is_some().then(SystemTime::now); let _start = _metric_callback.is_some().then(std::time::SystemTime::now);
let stream = c let stream = c
.fetch(query) .fetch(query)
.map_ok(Into::into) .map_ok(Into::into)
@ -61,7 +62,7 @@ impl<'a> TransactionStream<'a> {
#[cfg(feature = "sqlx-postgres")] #[cfg(feature = "sqlx-postgres")]
InnerConnection::Postgres(c) => { InnerConnection::Postgres(c) => {
let query = crate::driver::sqlx_postgres::sqlx_query(stmt); let query = crate::driver::sqlx_postgres::sqlx_query(stmt);
let _start = _metric_callback.is_some().then(SystemTime::now); let _start = _metric_callback.is_some().then(std::time::SystemTime::now);
let stream = c let stream = c
.fetch(query) .fetch(query)
.map_ok(Into::into) .map_ok(Into::into)
@ -72,7 +73,7 @@ impl<'a> TransactionStream<'a> {
#[cfg(feature = "sqlx-sqlite")] #[cfg(feature = "sqlx-sqlite")]
InnerConnection::Sqlite(c) => { InnerConnection::Sqlite(c) => {
let query = crate::driver::sqlx_sqlite::sqlx_query(stmt); let query = crate::driver::sqlx_sqlite::sqlx_query(stmt);
let _start = _metric_callback.is_some().then(SystemTime::now); let _start = _metric_callback.is_some().then(std::time::SystemTime::now);
let stream = c let stream = c
.fetch(query) .fetch(query)
.map_ok(Into::into) .map_ok(Into::into)
@ -82,7 +83,7 @@ impl<'a> TransactionStream<'a> {
} }
#[cfg(feature = "mock")] #[cfg(feature = "mock")]
InnerConnection::Mock(c) => { InnerConnection::Mock(c) => {
let _start = _metric_callback.is_some().then(SystemTime::now); let _start = _metric_callback.is_some().then(std::time::SystemTime::now);
let stream = c.fetch(stmt); let stream = c.fetch(stmt);
let elapsed = _start.map(|s| s.elapsed().unwrap_or_default()); let elapsed = _start.map(|s| s.elapsed().unwrap_or_default());
MetricStream::new(_metric_callback, stmt, elapsed, stream) MetricStream::new(_metric_callback, stmt, elapsed, stream)

View File

@ -81,6 +81,7 @@ impl DatabaseTransaction {
} }
#[instrument(level = "trace", skip(metric_callback))] #[instrument(level = "trace", skip(metric_callback))]
#[allow(unreachable_code)]
async fn begin( async fn begin(
conn: Arc<Mutex<InnerConnection>>, conn: Arc<Mutex<InnerConnection>>,
backend: DbBackend, backend: DbBackend,
@ -144,6 +145,7 @@ impl DatabaseTransaction {
/// Commit a transaction atomically /// Commit a transaction atomically
#[instrument(level = "trace")] #[instrument(level = "trace")]
#[allow(unreachable_code)]
pub async fn commit(mut self) -> Result<(), DbErr> { pub async fn commit(mut self) -> Result<(), DbErr> {
self.open = false; self.open = false;
match *self.conn.lock().await { match *self.conn.lock().await {
@ -175,6 +177,7 @@ impl DatabaseTransaction {
/// rolls back a transaction in case error are encountered during the operation /// rolls back a transaction in case error are encountered during the operation
#[instrument(level = "trace")] #[instrument(level = "trace")]
#[allow(unreachable_code)]
pub async fn rollback(mut self) -> Result<(), DbErr> { pub async fn rollback(mut self) -> Result<(), DbErr> {
self.open = false; self.open = false;
match *self.conn.lock().await { match *self.conn.lock().await {
@ -251,6 +254,7 @@ impl ConnectionTrait for DatabaseTransaction {
} }
#[instrument(level = "trace")] #[instrument(level = "trace")]
#[allow(unused_variables)]
async fn execute(&self, stmt: Statement) -> Result<ExecResult, DbErr> { async fn execute(&self, stmt: Statement) -> Result<ExecResult, DbErr> {
debug_print!("{}", stmt); debug_print!("{}", stmt);
@ -286,6 +290,7 @@ impl ConnectionTrait for DatabaseTransaction {
} }
#[instrument(level = "trace")] #[instrument(level = "trace")]
#[allow(unused_variables)]
async fn query_one(&self, stmt: Statement) -> Result<Option<QueryResult>, DbErr> { async fn query_one(&self, stmt: Statement) -> Result<Option<QueryResult>, DbErr> {
debug_print!("{}", stmt); debug_print!("{}", stmt);
@ -319,6 +324,7 @@ impl ConnectionTrait for DatabaseTransaction {
} }
#[instrument(level = "trace")] #[instrument(level = "trace")]
#[allow(unused_variables)]
async fn query_all(&self, stmt: Statement) -> Result<Vec<QueryResult>, DbErr> { async fn query_all(&self, stmt: Statement) -> Result<Vec<QueryResult>, DbErr> {
debug_print!("{}", stmt); debug_print!("{}", stmt);
@ -358,6 +364,7 @@ impl ConnectionTrait for DatabaseTransaction {
} }
#[async_trait::async_trait] #[async_trait::async_trait]
#[allow(unused_variables)]
impl<'a> StreamTrait<'a> for DatabaseTransaction { impl<'a> StreamTrait<'a> for DatabaseTransaction {
type Stream = TransactionStream<'a>; type Stream = TransactionStream<'a>;

View File

@ -101,6 +101,7 @@ where
} }
} }
#[allow(unused_variables, unreachable_code)]
async fn exec_insert<A, C>( async fn exec_insert<A, C>(
primary_key: Option<ValueTuple>, primary_key: Option<ValueTuple>,
statement: Statement, statement: Statement,

View File

@ -65,6 +65,7 @@ impl QueryResult {
} }
} }
#[allow(unused_variables)]
impl fmt::Debug for QueryResultRow { impl fmt::Debug for QueryResultRow {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self { match self {
@ -96,6 +97,7 @@ impl<T: TryGetable> TryGetable for Option<T> {
macro_rules! try_getable_all { macro_rules! try_getable_all {
( $type: ty ) => { ( $type: ty ) => {
#[allow(unused_variables)]
impl TryGetable for $type { impl TryGetable for $type {
fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result<Self, TryGetError> { fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result<Self, TryGetError> {
let column = format!("{}{}", pre, col); let column = format!("{}{}", pre, col);
@ -208,6 +210,7 @@ macro_rules! try_getable_mysql {
}; };
} }
#[allow(unused_macros)]
macro_rules! try_getable_date_time { macro_rules! try_getable_date_time {
( $type: ty ) => { ( $type: ty ) => {
impl TryGetable for $type { impl TryGetable for $type {
@ -253,8 +256,10 @@ macro_rules! try_getable_date_time {
}; };
} }
#[allow(unused_macros)]
macro_rules! try_getable_time { macro_rules! try_getable_time {
( $type: ty ) => { ( $type: ty ) => {
#[allow(unused_variables)]
impl TryGetable for $type { impl TryGetable for $type {
fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result<Self, TryGetError> { fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result<Self, TryGetError> {
let column = format!("{}{}", pre, col); let column = format!("{}{}", pre, col);
@ -342,6 +347,7 @@ use rust_decimal::Decimal;
#[cfg(feature = "with-rust_decimal")] #[cfg(feature = "with-rust_decimal")]
impl TryGetable for Decimal { impl TryGetable for Decimal {
#[allow(unused_variables)]
fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result<Self, TryGetError> { fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result<Self, TryGetError> {
let column = format!("{}{}", pre, col); let column = format!("{}{}", pre, col);
match &res.row { match &res.row {
@ -633,6 +639,7 @@ where
for<'de> Self: serde::Deserialize<'de>, for<'de> Self: serde::Deserialize<'de>,
{ {
/// Ensure the type implements this method /// Ensure the type implements this method
#[allow(unused_variables, unreachable_code)]
fn try_get_from_json(res: &QueryResult, pre: &str, col: &str) -> Result<Self, TryGetError> { fn try_get_from_json(res: &QueryResult, pre: &str, col: &str) -> Result<Self, TryGetError> {
let column = format!("{}{}", pre, col); let column = format!("{}{}", pre, col);
let res: Result<_, _> = match &res.row { let res: Result<_, _> = match &res.row {

View File

@ -1,8 +1,9 @@
use crate::{DbErr, FromQueryResult, QueryResult, QueryResultRow}; use crate::{DbErr, FromQueryResult, QueryResult};
use serde_json::Map; use serde_json::Map;
pub use serde_json::Value as JsonValue; pub use serde_json::Value as JsonValue;
impl FromQueryResult for JsonValue { impl FromQueryResult for JsonValue {
#[allow(unused_variables, unused_mut)]
fn from_query_result(res: &QueryResult, pre: &str) -> Result<Self, DbErr> { fn from_query_result(res: &QueryResult, pre: &str) -> Result<Self, DbErr> {
let mut map = Map::new(); let mut map = Map::new();
#[allow(unused_macros)] #[allow(unused_macros)]
@ -16,7 +17,7 @@ impl FromQueryResult for JsonValue {
} }
match &res.row { match &res.row {
#[cfg(feature = "sqlx-mysql")] #[cfg(feature = "sqlx-mysql")]
QueryResultRow::SqlxMySql(row) => { crate::QueryResultRow::SqlxMySql(row) => {
use serde_json::json; use serde_json::json;
use sqlx::{Column, MySql, Row, Type}; use sqlx::{Column, MySql, Row, Type};
for column in row.columns() { for column in row.columns() {
@ -65,7 +66,7 @@ impl FromQueryResult for JsonValue {
Ok(JsonValue::Object(map)) Ok(JsonValue::Object(map))
} }
#[cfg(feature = "sqlx-postgres")] #[cfg(feature = "sqlx-postgres")]
QueryResultRow::SqlxPostgres(row) => { crate::QueryResultRow::SqlxPostgres(row) => {
use serde_json::json; use serde_json::json;
use sqlx::{postgres::types::Oid, Column, Postgres, Row, Type}; use sqlx::{postgres::types::Oid, Column, Postgres, Row, Type};
for column in row.columns() { for column in row.columns() {
@ -117,7 +118,7 @@ impl FromQueryResult for JsonValue {
Ok(JsonValue::Object(map)) Ok(JsonValue::Object(map))
} }
#[cfg(feature = "sqlx-sqlite")] #[cfg(feature = "sqlx-sqlite")]
QueryResultRow::SqlxSqlite(row) => { crate::QueryResultRow::SqlxSqlite(row) => {
use serde_json::json; use serde_json::json;
use sqlx::{Column, Row, Sqlite, Type}; use sqlx::{Column, Row, Sqlite, Type};
for column in row.columns() { for column in row.columns() {
@ -159,7 +160,7 @@ impl FromQueryResult for JsonValue {
Ok(JsonValue::Object(map)) Ok(JsonValue::Object(map))
} }
#[cfg(feature = "mock")] #[cfg(feature = "mock")]
QueryResultRow::Mock(row) => { crate::QueryResultRow::Mock(row) => {
for (column, value) in row.clone().into_column_value_tuples() { for (column, value) in row.clone().into_column_value_tuples() {
let col = if !column.starts_with(pre) { let col = if !column.starts_with(pre) {
continue; continue;