Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

style: run clippy fix and fmt (#9965)

Brooooooklyn58aa18afa62e
diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml
index 4ee194c913..dde70e06e9 100644
--- a/.github/workflows/build-test.yml
+++ b/.github/workflows/build-test.yml
@@ -118,6 +118,26 @@ jobs:
- name: Run Type Check
run: yarn typecheck
+ lint-rust:
+ name: Lint Rust
+ runs-on: ubuntu-latest
+ needs: optimize_ci
+ if: needs.optimize_ci.outputs.skip == 'false'
+ steps:
+ - uses: actions/checkout@v4
+ - uses: ./.github/actions/build-rust
+ with:
+ no-build: 'true'
+ - name: fmt check
+ run: |
+ rustup toolchain add nightly
+ rustup component add --toolchain nightly-x86_64-unknown-linux-gnu rustfmt
+ cargo +nightly fmt --all -- --check
+ - name: Clippy
+ run: |
+ rustup component add clippy
+ cargo clippy --all-targets --all-features -- -D warnings
+
check-yarn-binary:
name: Check yarn binary
runs-on: ubuntu-latest
@@ -855,6 +875,7 @@ jobs:
needs:
- analyze
- lint
+ - lint-rust
- check-yarn-binary
- e2e-test
- e2e-legacy-blocksuite-test
diff --git a/packages/common/native/benches/hashcash.rs b/packages/common/native/benches/hashcash.rs
index 974cf4f829..7978c905cb 100644
--- a/packages/common/native/benches/hashcash.rs
+++ b/packages/common/native/benches/hashcash.rs
@@ -1,8 +1,7 @@
use std::hint::black_box;
-use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
-
use affine_common::hashcash::Stamp;
+use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
fn bench_hashcash(c: &mut Criterion) {
let mut group = c.benchmark_group("hashcash");
diff --git a/packages/common/native/src/hashcash.rs b/packages/common/native/src/hashcash.rs
index d5cee2890e..34370b764c 100644
--- a/packages/common/native/src/hashcash.rs
+++ b/packages/common/native/src/hashcash.rs
@@ -129,10 +129,11 @@ impl TryFrom<&str> for Stamp {
#[cfg(test)]
mod tests {
- use super::Stamp;
use rand::{distributions::Alphanumeric, Rng};
use rayon::prelude::*;
+ use super::Stamp;
+
#[test]
fn test_mint() {
{
diff --git a/packages/frontend/native/nbstore/build.rs b/packages/frontend/native/nbstore/build.rs
index f6fa8cd5e0..67c9899e27 100644
--- a/packages/frontend/native/nbstore/build.rs
+++ b/packages/frontend/native/nbstore/build.rs
@@ -1,6 +1,7 @@
+use std::fs;
+
use affine_schema::get_migrator;
use sqlx::sqlite::SqliteConnectOptions;
-use std::fs;
#[tokio::main]
async fn main() -> Result<(), std::io::Error> {
diff --git a/packages/frontend/native/nbstore/src/blob.rs b/packages/frontend/native/nbstore/src/blob.rs
index 095d2ada38..2f4dc6f8d3 100644
--- a/packages/frontend/native/nbstore/src/blob.rs
+++ b/packages/frontend/native/nbstore/src/blob.rs
@@ -60,7 +60,8 @@ impl SqliteDocStorage {
pub async fn list_blobs(&self) -> Result<Vec<ListedBlob>> {
let result = sqlx::query_as!(
ListedBlob,
- "SELECT key, size, mime, created_at FROM blobs WHERE deleted_at IS NULL ORDER BY created_at DESC;"
+ "SELECT key, size, mime, created_at FROM blobs WHERE deleted_at IS NULL ORDER BY created_at \
+ DESC;"
)
.fetch_all(&self.pool)
.await?;
@@ -90,7 +91,7 @@ mod tests {
storage
.set_blob(SetBlob {
key: format!("test_{}", i),
- data: vec![0, 0].into(),
+ data: vec![0, 0],
mime: "text/plain".to_string(),
})
.await
@@ -130,7 +131,7 @@ mod tests {
storage
.set_blob(SetBlob {
key: format!("test_{}", i),
- data: vec![0, 0].into(),
+ data: vec![0, 0],
mime: "text/plain".to_string(),
})
.await
@@ -178,7 +179,7 @@ mod tests {
storage
.set_blob(SetBlob {
key: format!("test_{}", i),
- data: vec![0, 0].into(),
+ data: vec![0, 0],
mime: "text/plain".to_string(),
})
.await
diff --git a/packages/frontend/native/nbstore/src/doc.rs b/packages/frontend/native/nbstore/src/doc.rs
index 0eeead284e..326e81fc45 100644
--- a/packages/frontend/native/nbstore/src/doc.rs
+++ b/packages/frontend/native/nbstore/src/doc.rs
@@ -84,7 +84,7 @@ impl SqliteDocStorage {
}
// Increment timestamp by 1ms and retry
- timestamp = timestamp + chrono::Duration::milliseconds(1);
+ timestamp += chrono::Duration::milliseconds(1);
tried += 1;
}
}
@@ -102,7 +102,7 @@ impl SqliteDocStorage {
let mut tx = self.pool.begin().await?;
sqlx::query(r#"INSERT INTO updates (doc_id, data, created_at) VALUES ($1, $2, $3);"#)
- .bind(&doc_id)
+ .bind(doc_id)
.bind(update.as_ref())
.bind(timestamp)
.execute(&mut *tx)
@@ -114,7 +114,7 @@ impl SqliteDocStorage {
ON CONFLICT(doc_id)
DO UPDATE SET timestamp=$2;"#,
)
- .bind(&doc_id)
+ .bind(doc_id)
.bind(timestamp)
.execute(&mut *tx)
.await?;
@@ -293,7 +293,7 @@ mod tests {
storage
.set_doc_snapshot(DocRecord {
doc_id: "test".to_string(),
- bin: vec![0, 0].into(),
+ bin: vec![0, 0],
timestamp: Utc::now().naive_utc(),
})
.await
@@ -373,7 +373,7 @@ mod tests {
let snapshot = DocRecord {
doc_id: "test".to_string(),
- bin: vec![0, 0].into(),
+ bin: vec![0, 0],
timestamp: Utc::now().naive_utc(),
};
@@ -391,7 +391,7 @@ mod tests {
let snapshot = DocRecord {
doc_id: "test".to_string(),
- bin: vec![0, 0].into(),
+ bin: vec![0, 0],
timestamp: Utc::now().naive_utc(),
};
@@ -404,7 +404,7 @@ mod tests {
let snapshot = DocRecord {
doc_id: "test".to_string(),
- bin: vec![0, 1].into(),
+ bin: vec![0, 1],
timestamp: DateTime::from_timestamp_millis(Utc::now().timestamp_millis() - 1000)
.unwrap()
.naive_utc(),
diff --git a/packages/frontend/native/nbstore/src/lib.rs b/packages/frontend/native/nbstore/src/lib.rs
index cf7c4955f2..f75eed86ca 100644
--- a/packages/frontend/native/nbstore/src/lib.rs
+++ b/packages/frontend/native/nbstore/src/lib.rs
@@ -93,7 +93,7 @@ impl DocStoragePool {
})
}
- async fn get<'a>(&'a self, universal_id: String) -> Result<Ref<'a, SqliteDocStorage>> {
+ async fn get(&self, universal_id: String) -> Result<Ref<SqliteDocStorage>> {
Ok(self.pool.get(universal_id).await?)
}
diff --git a/packages/frontend/native/nbstore/src/pool.rs b/packages/frontend/native/nbstore/src/pool.rs
index 49f9527cfd..03fa59c1a6 100644
--- a/packages/frontend/native/nbstore/src/pool.rs
+++ b/packages/frontend/native/nbstore/src/pool.rs
@@ -12,7 +12,7 @@ pub struct Ref<'a, V> {
_guard: RwLockReadGuard<'a, V>,
}
-impl<'a, V> Deref for Ref<'a, V> {
+impl<V> Deref for Ref<'_, V> {
type Target = V;
fn deref(&self) -> &Self::Target {
@@ -24,17 +24,17 @@ pub struct RefMut<'a, V> {
_guard: RwLockMappedWriteGuard<'a, V>,
}
-impl<'a, V> Deref for RefMut<'a, V> {
+impl<V> Deref for RefMut<'_, V> {
type Target = V;
fn deref(&self) -> &Self::Target {
- &*self._guard
+ &self._guard
}
}
-impl<'a, V> DerefMut for RefMut<'a, V> {
+impl<V> DerefMut for RefMut<'_, V> {
fn deref_mut(&mut self) -> &mut Self::Target {
- &mut *self._guard
+ &mut self._guard
}
}
@@ -62,7 +62,7 @@ impl SqliteDocStoragePool {
RefMut { _guard: lock }
}
- pub async fn get<'a>(&'a self, universal_id: String) -> Result<Ref<'a, SqliteDocStorage>> {
+ pub async fn get(&self, universal_id: String) -> Result<Ref<SqliteDocStorage>> {
let lock = RwLockReadGuard::try_map(self.inner.read().await, |lock| {
if let Some(storage) = lock.get(&universal_id) {
Some(storage)
diff --git a/packages/frontend/native/nbstore/src/storage.rs b/packages/frontend/native/nbstore/src/storage.rs
index 269d59369c..7c72cada4d 100644
--- a/packages/frontend/native/nbstore/src/storage.rs
+++ b/packages/frontend/native/nbstore/src/storage.rs
@@ -51,7 +51,7 @@ impl SqliteDocStorage {
let name: &str = row.try_get("description")?;
Ok(name == "init_v2")
}
- _ => return Ok(false),
+ _ => Ok(false),
}
}
diff --git a/packages/frontend/native/sqlite_v1/build.rs b/packages/frontend/native/sqlite_v1/build.rs
index fb2ed2b8ce..67a6d3da8c 100644
--- a/packages/frontend/native/sqlite_v1/build.rs
+++ b/packages/frontend/native/sqlite_v1/build.rs
@@ -1,6 +1,7 @@
-use sqlx::sqlite::SqliteConnectOptions;
use std::fs;
+use sqlx::sqlite::SqliteConnectOptions;
+
#[tokio::main]
async fn main() -> Result<(), std::io::Error> {
napi_build::setup();
diff --git a/packages/frontend/native/sqlite_v1/src/lib.rs b/packages/frontend/native/sqlite_v1/src/lib.rs
index 02c0385517..4bab152271 100644
--- a/packages/frontend/native/sqlite_v1/src/lib.rs
+++ b/packages/frontend/native/sqlite_v1/src/lib.rs
@@ -89,7 +89,8 @@ impl SqliteConnection {
let blob = blob.as_ref();
sqlx::query_as!(
BlobRow,
- "INSERT INTO blobs (key, data) VALUES ($1, $2) ON CONFLICT(key) DO UPDATE SET data = excluded.data",
+ "INSERT INTO blobs (key, data) VALUES ($1, $2) ON CONFLICT(key) DO UPDATE SET data = \
+ excluded.data",
key,
blob,
)
@@ -288,7 +289,8 @@ impl SqliteConnection {
pub async fn set_server_clock(&self, key: String, data: Uint8Array) -> napi::Result<()> {
let data = data.as_ref();
sqlx::query!(
- "INSERT INTO server_clock (key, data) VALUES ($1, $2) ON CONFLICT(key) DO UPDATE SET data = excluded.data",
+ "INSERT INTO server_clock (key, data) VALUES ($1, $2) ON CONFLICT(key) DO UPDATE SET data = \
+ excluded.data",
key,
data,
)
@@ -342,7 +344,8 @@ impl SqliteConnection {
pub async fn set_sync_metadata(&self, key: String, data: Uint8Array) -> napi::Result<()> {
let data = data.as_ref();
sqlx::query!(
- "INSERT INTO sync_metadata (key, data) VALUES ($1, $2) ON CONFLICT(key) DO UPDATE SET data = excluded.data",
+ "INSERT INTO sync_metadata (key, data) VALUES ($1, $2) ON CONFLICT(key) DO UPDATE SET data \
+ = excluded.data",
key,
data,
)