[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:
parent
a1bf662fc3
commit
1a3e8c456a
47
.github/workflows/rust.yml
vendored
47
.github/workflows/rust.yml
vendored
@ -87,8 +87,8 @@ jobs:
|
||||
- id: git-log
|
||||
run: echo "::set-output name=message::$(git log --no-merges -1 --oneline)"
|
||||
|
||||
clippy-fmt:
|
||||
name: Clippy + Fmt
|
||||
clippy:
|
||||
name: Clippy
|
||||
runs-on: ubuntu-20.04
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
@ -97,23 +97,44 @@ jobs:
|
||||
with:
|
||||
profile: minimal
|
||||
toolchain: stable
|
||||
components: clippy, rustfmt
|
||||
components: clippy
|
||||
override: true
|
||||
|
||||
# Make sure files are formatted
|
||||
- uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: fmt
|
||||
args: >
|
||||
--all
|
||||
|
||||
# Run clippy
|
||||
- uses: actions-rs/cargo@v1
|
||||
- name: Run clippy on `sea-orm` workspace
|
||||
uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: clippy
|
||||
args: >
|
||||
--all-targets
|
||||
--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:
|
||||
name: Compile SQLite
|
||||
|
@ -25,6 +25,6 @@ pub trait MigrationTrait: MigrationName + Send + Sync {
|
||||
|
||||
/// Define actions to perform when rolling back the migration
|
||||
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()))
|
||||
}
|
||||
}
|
||||
|
@ -176,6 +176,7 @@ impl<D: Database> Initializer<D> {
|
||||
///
|
||||
/// This method should never need to be called manually. See the [crate
|
||||
/// docs](crate) for usage information.
|
||||
#[allow(clippy::new_without_default)]
|
||||
pub fn new() -> Self {
|
||||
Self(None, std::marker::PhantomData)
|
||||
}
|
||||
|
@ -105,6 +105,7 @@ impl ConnectionTrait for DatabaseConnection {
|
||||
}
|
||||
|
||||
#[instrument(level = "trace")]
|
||||
#[allow(unused_variables)]
|
||||
async fn execute(&self, stmt: Statement) -> Result<ExecResult, DbErr> {
|
||||
match self {
|
||||
#[cfg(feature = "sqlx-mysql")]
|
||||
@ -120,6 +121,7 @@ impl ConnectionTrait for DatabaseConnection {
|
||||
}
|
||||
|
||||
#[instrument(level = "trace")]
|
||||
#[allow(unused_variables)]
|
||||
async fn query_one(&self, stmt: Statement) -> Result<Option<QueryResult>, DbErr> {
|
||||
match self {
|
||||
#[cfg(feature = "sqlx-mysql")]
|
||||
@ -135,6 +137,7 @@ impl ConnectionTrait for DatabaseConnection {
|
||||
}
|
||||
|
||||
#[instrument(level = "trace")]
|
||||
#[allow(unused_variables)]
|
||||
async fn query_all(&self, stmt: Statement) -> Result<Vec<QueryResult>, DbErr> {
|
||||
match self {
|
||||
#[cfg(feature = "sqlx-mysql")]
|
||||
@ -160,6 +163,7 @@ impl<'a> StreamTrait<'a> for DatabaseConnection {
|
||||
type Stream = crate::QueryStream;
|
||||
|
||||
#[instrument(level = "trace")]
|
||||
#[allow(unused_variables, unreachable_code)]
|
||||
fn stream(
|
||||
&'a self,
|
||||
stmt: Statement,
|
||||
|
@ -12,6 +12,7 @@ pub(crate) struct MetricStream<'a> {
|
||||
}
|
||||
|
||||
impl<'a> MetricStream<'a> {
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn new<S>(
|
||||
metric_callback: &'a Option<crate::metric::Callback>,
|
||||
stmt: &'a Statement,
|
||||
|
@ -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")]
|
||||
use std::sync::Arc;
|
||||
@ -126,7 +126,7 @@ impl QueryStream {
|
||||
#[cfg(feature = "sqlx-mysql")]
|
||||
InnerConnection::MySql(c) => {
|
||||
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
|
||||
.fetch(query)
|
||||
.map_ok(Into::into)
|
||||
@ -137,7 +137,7 @@ impl QueryStream {
|
||||
#[cfg(feature = "sqlx-postgres")]
|
||||
InnerConnection::Postgres(c) => {
|
||||
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
|
||||
.fetch(query)
|
||||
.map_ok(Into::into)
|
||||
@ -148,7 +148,7 @@ impl QueryStream {
|
||||
#[cfg(feature = "sqlx-sqlite")]
|
||||
InnerConnection::Sqlite(c) => {
|
||||
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
|
||||
.fetch(query)
|
||||
.map_ok(Into::into)
|
||||
@ -158,7 +158,7 @@ impl QueryStream {
|
||||
}
|
||||
#[cfg(feature = "mock")]
|
||||
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 elapsed = _start.map(|s| s.elapsed().unwrap_or_default());
|
||||
MetricStream::new(_metric_callback, stmt, elapsed, stream)
|
||||
|
@ -1,6 +1,6 @@
|
||||
#![allow(missing_docs)]
|
||||
|
||||
use std::{ops::DerefMut, pin::Pin, task::Poll, time::SystemTime};
|
||||
use std::{ops::DerefMut, pin::Pin, task::Poll};
|
||||
|
||||
use futures::Stream;
|
||||
#[cfg(feature = "sqlx-dep")]
|
||||
@ -37,6 +37,7 @@ impl<'a> std::fmt::Debug for TransactionStream<'a> {
|
||||
|
||||
impl<'a> TransactionStream<'a> {
|
||||
#[instrument(level = "trace", skip(metric_callback))]
|
||||
#[allow(unused_variables)]
|
||||
pub(crate) fn build(
|
||||
conn: MutexGuard<'a, InnerConnection>,
|
||||
stmt: Statement,
|
||||
@ -50,7 +51,7 @@ impl<'a> TransactionStream<'a> {
|
||||
#[cfg(feature = "sqlx-mysql")]
|
||||
InnerConnection::MySql(c) => {
|
||||
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
|
||||
.fetch(query)
|
||||
.map_ok(Into::into)
|
||||
@ -61,7 +62,7 @@ impl<'a> TransactionStream<'a> {
|
||||
#[cfg(feature = "sqlx-postgres")]
|
||||
InnerConnection::Postgres(c) => {
|
||||
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
|
||||
.fetch(query)
|
||||
.map_ok(Into::into)
|
||||
@ -72,7 +73,7 @@ impl<'a> TransactionStream<'a> {
|
||||
#[cfg(feature = "sqlx-sqlite")]
|
||||
InnerConnection::Sqlite(c) => {
|
||||
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
|
||||
.fetch(query)
|
||||
.map_ok(Into::into)
|
||||
@ -82,7 +83,7 @@ impl<'a> TransactionStream<'a> {
|
||||
}
|
||||
#[cfg(feature = "mock")]
|
||||
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 elapsed = _start.map(|s| s.elapsed().unwrap_or_default());
|
||||
MetricStream::new(_metric_callback, stmt, elapsed, stream)
|
||||
|
@ -81,6 +81,7 @@ impl DatabaseTransaction {
|
||||
}
|
||||
|
||||
#[instrument(level = "trace", skip(metric_callback))]
|
||||
#[allow(unreachable_code)]
|
||||
async fn begin(
|
||||
conn: Arc<Mutex<InnerConnection>>,
|
||||
backend: DbBackend,
|
||||
@ -144,6 +145,7 @@ impl DatabaseTransaction {
|
||||
|
||||
/// Commit a transaction atomically
|
||||
#[instrument(level = "trace")]
|
||||
#[allow(unreachable_code)]
|
||||
pub async fn commit(mut self) -> Result<(), DbErr> {
|
||||
self.open = false;
|
||||
match *self.conn.lock().await {
|
||||
@ -175,6 +177,7 @@ impl DatabaseTransaction {
|
||||
|
||||
/// rolls back a transaction in case error are encountered during the operation
|
||||
#[instrument(level = "trace")]
|
||||
#[allow(unreachable_code)]
|
||||
pub async fn rollback(mut self) -> Result<(), DbErr> {
|
||||
self.open = false;
|
||||
match *self.conn.lock().await {
|
||||
@ -251,6 +254,7 @@ impl ConnectionTrait for DatabaseTransaction {
|
||||
}
|
||||
|
||||
#[instrument(level = "trace")]
|
||||
#[allow(unused_variables)]
|
||||
async fn execute(&self, stmt: Statement) -> Result<ExecResult, DbErr> {
|
||||
debug_print!("{}", stmt);
|
||||
|
||||
@ -286,6 +290,7 @@ impl ConnectionTrait for DatabaseTransaction {
|
||||
}
|
||||
|
||||
#[instrument(level = "trace")]
|
||||
#[allow(unused_variables)]
|
||||
async fn query_one(&self, stmt: Statement) -> Result<Option<QueryResult>, DbErr> {
|
||||
debug_print!("{}", stmt);
|
||||
|
||||
@ -319,6 +324,7 @@ impl ConnectionTrait for DatabaseTransaction {
|
||||
}
|
||||
|
||||
#[instrument(level = "trace")]
|
||||
#[allow(unused_variables)]
|
||||
async fn query_all(&self, stmt: Statement) -> Result<Vec<QueryResult>, DbErr> {
|
||||
debug_print!("{}", stmt);
|
||||
|
||||
@ -358,6 +364,7 @@ impl ConnectionTrait for DatabaseTransaction {
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
#[allow(unused_variables)]
|
||||
impl<'a> StreamTrait<'a> for DatabaseTransaction {
|
||||
type Stream = TransactionStream<'a>;
|
||||
|
||||
|
@ -101,6 +101,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(unused_variables, unreachable_code)]
|
||||
async fn exec_insert<A, C>(
|
||||
primary_key: Option<ValueTuple>,
|
||||
statement: Statement,
|
||||
|
@ -65,6 +65,7 @@ impl QueryResult {
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
impl fmt::Debug for QueryResultRow {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
@ -96,6 +97,7 @@ impl<T: TryGetable> TryGetable for Option<T> {
|
||||
|
||||
macro_rules! try_getable_all {
|
||||
( $type: ty ) => {
|
||||
#[allow(unused_variables)]
|
||||
impl TryGetable for $type {
|
||||
fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result<Self, TryGetError> {
|
||||
let column = format!("{}{}", pre, col);
|
||||
@ -208,6 +210,7 @@ macro_rules! try_getable_mysql {
|
||||
};
|
||||
}
|
||||
|
||||
#[allow(unused_macros)]
|
||||
macro_rules! try_getable_date_time {
|
||||
( $type: ty ) => {
|
||||
impl TryGetable for $type {
|
||||
@ -253,8 +256,10 @@ macro_rules! try_getable_date_time {
|
||||
};
|
||||
}
|
||||
|
||||
#[allow(unused_macros)]
|
||||
macro_rules! try_getable_time {
|
||||
( $type: ty ) => {
|
||||
#[allow(unused_variables)]
|
||||
impl TryGetable for $type {
|
||||
fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result<Self, TryGetError> {
|
||||
let column = format!("{}{}", pre, col);
|
||||
@ -342,6 +347,7 @@ use rust_decimal::Decimal;
|
||||
|
||||
#[cfg(feature = "with-rust_decimal")]
|
||||
impl TryGetable for Decimal {
|
||||
#[allow(unused_variables)]
|
||||
fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result<Self, TryGetError> {
|
||||
let column = format!("{}{}", pre, col);
|
||||
match &res.row {
|
||||
@ -633,6 +639,7 @@ where
|
||||
for<'de> Self: serde::Deserialize<'de>,
|
||||
{
|
||||
/// 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> {
|
||||
let column = format!("{}{}", pre, col);
|
||||
let res: Result<_, _> = match &res.row {
|
||||
|
@ -1,8 +1,9 @@
|
||||
use crate::{DbErr, FromQueryResult, QueryResult, QueryResultRow};
|
||||
use crate::{DbErr, FromQueryResult, QueryResult};
|
||||
use serde_json::Map;
|
||||
pub use serde_json::Value as JsonValue;
|
||||
|
||||
impl FromQueryResult for JsonValue {
|
||||
#[allow(unused_variables, unused_mut)]
|
||||
fn from_query_result(res: &QueryResult, pre: &str) -> Result<Self, DbErr> {
|
||||
let mut map = Map::new();
|
||||
#[allow(unused_macros)]
|
||||
@ -16,7 +17,7 @@ impl FromQueryResult for JsonValue {
|
||||
}
|
||||
match &res.row {
|
||||
#[cfg(feature = "sqlx-mysql")]
|
||||
QueryResultRow::SqlxMySql(row) => {
|
||||
crate::QueryResultRow::SqlxMySql(row) => {
|
||||
use serde_json::json;
|
||||
use sqlx::{Column, MySql, Row, Type};
|
||||
for column in row.columns() {
|
||||
@ -65,7 +66,7 @@ impl FromQueryResult for JsonValue {
|
||||
Ok(JsonValue::Object(map))
|
||||
}
|
||||
#[cfg(feature = "sqlx-postgres")]
|
||||
QueryResultRow::SqlxPostgres(row) => {
|
||||
crate::QueryResultRow::SqlxPostgres(row) => {
|
||||
use serde_json::json;
|
||||
use sqlx::{postgres::types::Oid, Column, Postgres, Row, Type};
|
||||
for column in row.columns() {
|
||||
@ -117,7 +118,7 @@ impl FromQueryResult for JsonValue {
|
||||
Ok(JsonValue::Object(map))
|
||||
}
|
||||
#[cfg(feature = "sqlx-sqlite")]
|
||||
QueryResultRow::SqlxSqlite(row) => {
|
||||
crate::QueryResultRow::SqlxSqlite(row) => {
|
||||
use serde_json::json;
|
||||
use sqlx::{Column, Row, Sqlite, Type};
|
||||
for column in row.columns() {
|
||||
@ -159,7 +160,7 @@ impl FromQueryResult for JsonValue {
|
||||
Ok(JsonValue::Object(map))
|
||||
}
|
||||
#[cfg(feature = "mock")]
|
||||
QueryResultRow::Mock(row) => {
|
||||
crate::QueryResultRow::Mock(row) => {
|
||||
for (column, value) in row.clone().into_column_value_tuples() {
|
||||
let col = if !column.starts_with(pre) {
|
||||
continue;
|
||||
|
Loading…
x
Reference in New Issue
Block a user