style: run clippy fix and fmt (#9965)

This commit is contained in:
Brooooooklyn
2025-02-05 13:48:17 +00:00
parent db1fcf42c9
commit 58aa18afa6
11 changed files with 54 additions and 27 deletions
+21
View File
@@ -118,6 +118,26 @@ jobs:
- name: Run Type Check - name: Run Type Check
run: yarn typecheck 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: check-yarn-binary:
name: Check yarn binary name: Check yarn binary
runs-on: ubuntu-latest runs-on: ubuntu-latest
@@ -855,6 +875,7 @@ jobs:
needs: needs:
- analyze - analyze
- lint - lint
- lint-rust
- check-yarn-binary - check-yarn-binary
- e2e-test - e2e-test
- e2e-legacy-blocksuite-test - e2e-legacy-blocksuite-test
+1 -2
View File
@@ -1,8 +1,7 @@
use std::hint::black_box; use std::hint::black_box;
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
use affine_common::hashcash::Stamp; use affine_common::hashcash::Stamp;
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
fn bench_hashcash(c: &mut Criterion) { fn bench_hashcash(c: &mut Criterion) {
let mut group = c.benchmark_group("hashcash"); let mut group = c.benchmark_group("hashcash");
+2 -1
View File
@@ -129,10 +129,11 @@ impl TryFrom<&str> for Stamp {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::Stamp;
use rand::{distributions::Alphanumeric, Rng}; use rand::{distributions::Alphanumeric, Rng};
use rayon::prelude::*; use rayon::prelude::*;
use super::Stamp;
#[test] #[test]
fn test_mint() { fn test_mint() {
{ {
+2 -1
View File
@@ -1,6 +1,7 @@
use std::fs;
use affine_schema::get_migrator; use affine_schema::get_migrator;
use sqlx::sqlite::SqliteConnectOptions; use sqlx::sqlite::SqliteConnectOptions;
use std::fs;
#[tokio::main] #[tokio::main]
async fn main() -> Result<(), std::io::Error> { async fn main() -> Result<(), std::io::Error> {
+5 -4
View File
@@ -60,7 +60,8 @@ impl SqliteDocStorage {
pub async fn list_blobs(&self) -> Result<Vec<ListedBlob>> { pub async fn list_blobs(&self) -> Result<Vec<ListedBlob>> {
let result = sqlx::query_as!( let result = sqlx::query_as!(
ListedBlob, 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) .fetch_all(&self.pool)
.await?; .await?;
@@ -90,7 +91,7 @@ mod tests {
storage storage
.set_blob(SetBlob { .set_blob(SetBlob {
key: format!("test_{}", i), key: format!("test_{}", i),
data: vec![0, 0].into(), data: vec![0, 0],
mime: "text/plain".to_string(), mime: "text/plain".to_string(),
}) })
.await .await
@@ -130,7 +131,7 @@ mod tests {
storage storage
.set_blob(SetBlob { .set_blob(SetBlob {
key: format!("test_{}", i), key: format!("test_{}", i),
data: vec![0, 0].into(), data: vec![0, 0],
mime: "text/plain".to_string(), mime: "text/plain".to_string(),
}) })
.await .await
@@ -178,7 +179,7 @@ mod tests {
storage storage
.set_blob(SetBlob { .set_blob(SetBlob {
key: format!("test_{}", i), key: format!("test_{}", i),
data: vec![0, 0].into(), data: vec![0, 0],
mime: "text/plain".to_string(), mime: "text/plain".to_string(),
}) })
.await .await
+7 -7
View File
@@ -84,7 +84,7 @@ impl SqliteDocStorage {
} }
// Increment timestamp by 1ms and retry // Increment timestamp by 1ms and retry
timestamp = timestamp + chrono::Duration::milliseconds(1); timestamp += chrono::Duration::milliseconds(1);
tried += 1; tried += 1;
} }
} }
@@ -102,7 +102,7 @@ impl SqliteDocStorage {
let mut tx = self.pool.begin().await?; let mut tx = self.pool.begin().await?;
sqlx::query(r#"INSERT INTO updates (doc_id, data, created_at) VALUES ($1, $2, $3);"#) 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(update.as_ref())
.bind(timestamp) .bind(timestamp)
.execute(&mut *tx) .execute(&mut *tx)
@@ -114,7 +114,7 @@ impl SqliteDocStorage {
ON CONFLICT(doc_id) ON CONFLICT(doc_id)
DO UPDATE SET timestamp=$2;"#, DO UPDATE SET timestamp=$2;"#,
) )
.bind(&doc_id) .bind(doc_id)
.bind(timestamp) .bind(timestamp)
.execute(&mut *tx) .execute(&mut *tx)
.await?; .await?;
@@ -293,7 +293,7 @@ mod tests {
storage storage
.set_doc_snapshot(DocRecord { .set_doc_snapshot(DocRecord {
doc_id: "test".to_string(), doc_id: "test".to_string(),
bin: vec![0, 0].into(), bin: vec![0, 0],
timestamp: Utc::now().naive_utc(), timestamp: Utc::now().naive_utc(),
}) })
.await .await
@@ -373,7 +373,7 @@ mod tests {
let snapshot = DocRecord { let snapshot = DocRecord {
doc_id: "test".to_string(), doc_id: "test".to_string(),
bin: vec![0, 0].into(), bin: vec![0, 0],
timestamp: Utc::now().naive_utc(), timestamp: Utc::now().naive_utc(),
}; };
@@ -391,7 +391,7 @@ mod tests {
let snapshot = DocRecord { let snapshot = DocRecord {
doc_id: "test".to_string(), doc_id: "test".to_string(),
bin: vec![0, 0].into(), bin: vec![0, 0],
timestamp: Utc::now().naive_utc(), timestamp: Utc::now().naive_utc(),
}; };
@@ -404,7 +404,7 @@ mod tests {
let snapshot = DocRecord { let snapshot = DocRecord {
doc_id: "test".to_string(), doc_id: "test".to_string(),
bin: vec![0, 1].into(), bin: vec![0, 1],
timestamp: DateTime::from_timestamp_millis(Utc::now().timestamp_millis() - 1000) timestamp: DateTime::from_timestamp_millis(Utc::now().timestamp_millis() - 1000)
.unwrap() .unwrap()
.naive_utc(), .naive_utc(),
+1 -1
View File
@@ -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?) Ok(self.pool.get(universal_id).await?)
} }
+6 -6
View File
@@ -12,7 +12,7 @@ pub struct Ref<'a, V> {
_guard: RwLockReadGuard<'a, V>, _guard: RwLockReadGuard<'a, V>,
} }
impl<'a, V> Deref for Ref<'a, V> { impl<V> Deref for Ref<'_, V> {
type Target = V; type Target = V;
fn deref(&self) -> &Self::Target { fn deref(&self) -> &Self::Target {
@@ -24,17 +24,17 @@ pub struct RefMut<'a, V> {
_guard: RwLockMappedWriteGuard<'a, V>, _guard: RwLockMappedWriteGuard<'a, V>,
} }
impl<'a, V> Deref for RefMut<'a, V> { impl<V> Deref for RefMut<'_, V> {
type Target = V; type Target = V;
fn deref(&self) -> &Self::Target { 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 { fn deref_mut(&mut self) -> &mut Self::Target {
&mut *self._guard &mut self._guard
} }
} }
@@ -62,7 +62,7 @@ impl SqliteDocStoragePool {
RefMut { _guard: lock } 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| { let lock = RwLockReadGuard::try_map(self.inner.read().await, |lock| {
if let Some(storage) = lock.get(&universal_id) { if let Some(storage) = lock.get(&universal_id) {
Some(storage) Some(storage)
@@ -51,7 +51,7 @@ impl SqliteDocStorage {
let name: &str = row.try_get("description")?; let name: &str = row.try_get("description")?;
Ok(name == "init_v2") Ok(name == "init_v2")
} }
_ => return Ok(false), _ => Ok(false),
} }
} }
+2 -1
View File
@@ -1,6 +1,7 @@
use sqlx::sqlite::SqliteConnectOptions;
use std::fs; use std::fs;
use sqlx::sqlite::SqliteConnectOptions;
#[tokio::main] #[tokio::main]
async fn main() -> Result<(), std::io::Error> { async fn main() -> Result<(), std::io::Error> {
napi_build::setup(); napi_build::setup();
@@ -89,7 +89,8 @@ impl SqliteConnection {
let blob = blob.as_ref(); let blob = blob.as_ref();
sqlx::query_as!( sqlx::query_as!(
BlobRow, 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, key,
blob, blob,
) )
@@ -288,7 +289,8 @@ impl SqliteConnection {
pub async fn set_server_clock(&self, key: String, data: Uint8Array) -> napi::Result<()> { pub async fn set_server_clock(&self, key: String, data: Uint8Array) -> napi::Result<()> {
let data = data.as_ref(); let data = data.as_ref();
sqlx::query!( 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, key,
data, data,
) )
@@ -342,7 +344,8 @@ impl SqliteConnection {
pub async fn set_sync_metadata(&self, key: String, data: Uint8Array) -> napi::Result<()> { pub async fn set_sync_metadata(&self, key: String, data: Uint8Array) -> napi::Result<()> {
let data = data.as_ref(); let data = data.as_ref();
sqlx::query!( 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, key,
data, data,
) )