Skip to content

Commit

Permalink
chore: apply clippy suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
forehalo committed Dec 20, 2023
1 parent 48bdeb2 commit a58b922
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 56 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/y-octo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
- name: Setup Rust
uses: ./.github/actions/setup-rust
with:
toolchain: nightly-2023-08-19
toolchain: nightly
components: clippy, rustfmt

- name: Install Node.js
Expand All @@ -53,8 +53,7 @@ jobs:

- name: Build & Check
run: |
cargo vendor > .cargo/config.toml
cargo clippy --all-features --message-format=json -- -D warnings | clippy-sarif | tee rust-clippy-results.sarif | sarif-fmt
cargo +nightly clippy --all-features --message-format=json -- -D warnings | clippy-sarif | tee rust-clippy-results.sarif | sarif-fmt
RUSTDOCFLAGS="-D rustdoc::broken-intra-doc-links" cargo doc --workspace --all-features --no-deps
env:
CARGO_TERM_COLOR: always
Expand All @@ -63,7 +62,7 @@ jobs:
run: |
yarn prettier --check .
yarn taplo fmt --check .
cargo +nightly-2023-08-19 fmt --all --check
cargo +nightly fmt --all --check
- name: Upload analysis results to GitHub
uses: github/codeql-action/upload-sarif@v2
Expand Down
1 change: 1 addition & 0 deletions y-octo-node/src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub struct YArray {

#[napi]
impl YArray {
#[allow(clippy::new_without_default)]
#[napi(constructor)]
pub fn new() -> Self {
unimplemented!()
Expand Down
1 change: 1 addition & 0 deletions y-octo-node/src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub struct YMap {

#[napi]
impl YMap {
#[allow(clippy::new_without_default)]
#[napi(constructor)]
pub fn new() -> Self {
unimplemented!()
Expand Down
2 changes: 2 additions & 0 deletions y-octo-node/src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub struct YText {

#[napi]
impl YText {
#[allow(clippy::new_without_default)]
#[napi(constructor)]
pub fn new() -> Self {
unimplemented!()
Expand Down Expand Up @@ -43,6 +44,7 @@ impl YText {
self.text.len() as i64
}

#[allow(clippy::inherent_to_string)]
#[napi]
pub fn to_string(&self) -> String {
self.text.to_string()
Expand Down
25 changes: 0 additions & 25 deletions y-octo/src/doc/codec/id.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::{
cmp::Ordering,
fmt::Display,
hash::Hash,
ops::{Add, Sub},
Expand Down Expand Up @@ -44,22 +43,6 @@ impl Add<Clock> for Id {
}
}

#[allow(clippy::incorrect_partial_ord_impl_on_ord_type)]
impl PartialOrd for Id {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
match self.client.cmp(&other.client) {
Ordering::Equal => Some(self.clock.cmp(&other.clock)),
_ => None,
}
}
}

impl Ord for Id {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
self.clock.cmp(&other.clock)
}
}

impl Display for Id {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "({}, {})", self.client, self.clock)
Expand All @@ -72,16 +55,8 @@ mod tests {

#[test]
fn basic_id_operation() {
let id_with_same_client_1 = Id::new(1, 1);
let id_with_same_client_2 = Id::new(1, 2);
assert!(id_with_same_client_1 < id_with_same_client_2);

let id_with_different_client_1 = Id::new(1, 1);
let id_with_different_client_2 = Id::new(2, 1);
assert_eq!(
id_with_different_client_1.partial_cmp(&id_with_different_client_2),
None
);

assert_ne!(id_with_different_client_1, id_with_different_client_2);
assert_eq!(Id::new(1, 1), Id::new(1, 1));
Expand Down
21 changes: 9 additions & 12 deletions y-octo/src/doc/common/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,18 +383,15 @@ mod tests {

#[test]
fn test_range_covered() {
assert_eq!(OrderRange::check_range_covered(&[0..1], &[2..3]), false);
assert_eq!(OrderRange::check_range_covered(&[0..1], &[0..3]), true);
assert_eq!(OrderRange::check_range_covered(&[0..1], &[1..3]), false);
assert_eq!(OrderRange::check_range_covered(&[0..1], &[0..3]), true);
assert_eq!(OrderRange::check_range_covered(&[1..2], &[0..3]), true);
assert_eq!(OrderRange::check_range_covered(&[1..2, 2..3], &[0..3]), true);
assert_eq!(OrderRange::check_range_covered(&[1..2, 2..3, 3..4], &[0..3]), false);
assert_eq!(OrderRange::check_range_covered(&[0..1, 2..3], &[0..2, 2..4]), true);
assert_eq!(
OrderRange::check_range_covered(&[0..1, 2..3, 3..4], &[0..2, 2..4]),
true
);
assert!(!OrderRange::check_range_covered(&[0..1], &[2..3]));
assert!(OrderRange::check_range_covered(&[0..1], &[0..3]));
assert!(!OrderRange::check_range_covered(&[0..1], &[1..3]));
assert!(OrderRange::check_range_covered(&[0..1], &[0..3]));
assert!(OrderRange::check_range_covered(&[1..2], &[0..3]));
assert!(OrderRange::check_range_covered(&[1..2, 2..3], &[0..3]));
assert!(!OrderRange::check_range_covered(&[1..2, 2..3, 3..4], &[0..3]));
assert!(OrderRange::check_range_covered(&[0..1, 2..3], &[0..2, 2..4]));
assert!(OrderRange::check_range_covered(&[0..1, 2..3, 3..4], &[0..2, 2..4]),);
}

#[test]
Expand Down
7 changes: 1 addition & 6 deletions y-octo/src/doc/hasher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::{

use super::Client;

#[derive(Default)]
pub struct ClientHasher(Client);

impl Hasher for ClientHasher {
Expand All @@ -19,12 +20,6 @@ impl Hasher for ClientHasher {
}
}

impl Default for ClientHasher {
fn default() -> Self {
Self(0)
}
}

#[derive(Default, Clone)]
pub struct ClientHasherBuilder;

Expand Down
4 changes: 2 additions & 2 deletions y-octo/src/doc/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl StoreHistory {

// make items as reference
let mut store_items = store_items.iter().collect::<Vec<_>>();
store_items.sort_by(|a, b| a.id.cmp(&b.id));
store_items.sort_by(|a, b| a.id.clock.cmp(&b.id.clock));

self.parse_items(store_items)
}
Expand Down Expand Up @@ -130,7 +130,7 @@ impl StoreHistory {

// make items as reference
let mut store_items = store_items.iter().collect::<Vec<_>>();
store_items.sort_by(|a, b| a.id.cmp(&b.id));
store_items.sort_by(|a, b| a.id.clock.cmp(&b.id.clock));

self.parse_items(store_items)
}
Expand Down
2 changes: 1 addition & 1 deletion y-octo/src/doc/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@ impl DocStore {
clock..clock + n.len()
})
.collect::<Vec<_>>();
if ranges.len() > 0 {
if !ranges.is_empty() {
delete_set.batch_push(*client, ranges);
}
}
Expand Down
4 changes: 2 additions & 2 deletions y-octo/src/doc/types/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ impl Iterator for ArrayIter<'_> {
for item in self.0.by_ref() {
if let Some(item) = item.get() {
if item.countable() {
return Some(Value::try_from(&item.content).unwrap());
return Some(Value::from(&item.content));
}
}
}
Expand All @@ -40,7 +40,7 @@ impl Array {
// TODO: rewrite to content.read(&mut [Any])
return match &item.content {
Content::Any(any) => return any.get(offset as usize).map(|any| Value::Any(any.clone())),
_ => Value::try_from(&item.content).map_or_else(|_| None, Some),
_ => Some(Value::from(&item.content)),
};
}

Expand Down
8 changes: 4 additions & 4 deletions y-octo/src/doc/types/map.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::hash_map::Iter;
use std::{collections::hash_map::Iter, rc::Rc};

use super::*;
use crate::{
Expand Down Expand Up @@ -71,10 +71,10 @@ pub(crate) trait MapType: AsInner<Inner = YTypeRef> {
let ty = self.as_inner().ty();

if let Some(ty) = ty {
let ty = Arc::new(ty);
let ty = Rc::new(ty);

EntriesInnerIterator {
iter: Some(unsafe { &*Arc::as_ptr(&ty) }.map.iter()),
iter: Some(unsafe { &*Rc::as_ptr(&ty) }.map.iter()),
_lock: Some(ty),
}
} else {
Expand All @@ -99,7 +99,7 @@ pub(crate) trait MapType: AsInner<Inner = YTypeRef> {
}

pub(crate) struct EntriesInnerIterator<'a> {
_lock: Option<Arc<RwLockReadGuard<'a, YType>>>,
_lock: Option<Rc<RwLockReadGuard<'a, YType>>>,
iter: Option<Iter<'a, String, ItemRef>>,
}

Expand Down

0 comments on commit a58b922

Please sign in to comment.