Skip to content

Commit

Permalink
Add Rust checks, including clippy fixes (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
djmitche authored Dec 25, 2024
1 parent cb3ea2d commit 9b2ac43
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 19 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: checks

on:
push:
branches:
- main
pull_request:
types: [opened, reopened, synchronize]

jobs:
clippy:
runs-on: ubuntu-latest
name: "Check & Clippy"

steps:
- uses: actions/checkout@v4

- name: Cache cargo registry
uses: actions/cache@v4
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}

- name: Cache cargo build
uses: actions/cache@v4
with:
path: target
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}

- uses: actions-rs/toolchain@v1
with:
toolchain: "1.78.0" # MSRV
override: true
components: clippy

- uses: actions-rs/[email protected]
with:
command: check

- uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --all-features --no-deps -- -D warnings
name: "Clippy Results"

fmt:
runs-on: ubuntu-latest
name: "Formatting"
steps:
- uses: actions/checkout@v4

- uses: actions-rs/toolchain@v1
with:
profile: minimal
components: rustfmt
toolchain: stable
override: true

- uses: actions-rs/[email protected]
with:
command: fmt
args: --all -- --check
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::new_without_default)]

use pyo3::prelude::*;
pub mod replica;
use replica::*;
Expand Down
10 changes: 5 additions & 5 deletions src/replica.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl Replica {
let task = self
.0
.create_task(Uuid::parse_str(&uuid)?, &mut ops)
.map(|t| Task(t))?;
.map(Task)?;
Ok((task, ops.iter().map(|op| Operation(op.clone())).collect()))
}

Expand Down Expand Up @@ -77,7 +77,7 @@ impl Replica {
}

pub fn working_set(&mut self) -> anyhow::Result<WorkingSet> {
Ok(self.0.working_set().map(|ws| WorkingSet(ws))?)
Ok(self.0.working_set().map(WorkingSet)?)
}

pub fn dependency_map(&mut self, force: bool) -> anyhow::Result<DependencyMap> {
Expand All @@ -89,7 +89,7 @@ impl Replica {
// TODO: better error handling here
Rc::into_inner(rc).unwrap()
})
.map(|dm| DependencyMap(dm))?;
.map(DependencyMap)?;

Ok(s)
}
Expand All @@ -98,14 +98,14 @@ impl Replica {
Ok(self
.0
.get_task(Uuid::parse_str(&uuid).unwrap())
.map(|opt| opt.map(|t| Task(t)))?)
.map(|opt| opt.map(Task))?)
}

pub fn get_task_data(&mut self, uuid: String) -> anyhow::Result<Option<TaskData>> {
Ok(self
.0
.get_task_data(Uuid::parse_str(&uuid)?)
.map(|opt| opt.map(|td| TaskData(td)))?)
.map(|opt| opt.map(TaskData))?)
}

pub fn sync(&self, _avoid_snapshots: bool) {
Expand Down
6 changes: 3 additions & 3 deletions src/task/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ impl TaskData {
let mut ops: Vec<TCOperation> = vec![TCOperation::Create { uuid: u }];

let td = TaskData(TCTaskData::create(u, &mut ops));
(td, Operation(ops.get(0).expect("").clone()))
(td, Operation(ops.first().expect("").clone()))
}

pub fn get_uuid(&self) -> String {
Expand All @@ -34,13 +34,13 @@ impl TaskData {
let mut ops: Vec<TCOperation> = Vec::new();

self.0.update(property, value, &mut ops);
ops.get(0).map(|op| Operation(op.clone())).expect("")
ops.first().map(|op| Operation(op.clone())).expect("")
}

pub fn delete(&mut self) -> Operation {
let mut ops: Vec<TCOperation> = Vec::new();
self.0.delete(&mut ops);

ops.get(0).map(|op| Operation(op.clone())).expect("")
ops.first().map(|op| Operation(op.clone())).expect("")
}
}
1 change: 1 addition & 0 deletions src/task/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(clippy::module_inception)]
mod annotation;
mod data;
mod status;
Expand Down
8 changes: 4 additions & 4 deletions src/task/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@ pub enum Status {

impl From<TCStatus> for Status {
fn from(status: TCStatus) -> Self {
return match status {
match status {
TCStatus::Pending => Status::Pending,
TCStatus::Completed => Status::Completed,
TCStatus::Deleted => Status::Deleted,
TCStatus::Recurring => Status::Recurring,
_ => Status::Unknown,
};
}
}
}

impl From<Status> for TCStatus {
fn from(status: Status) -> Self {
return match status {
match status {
Status::Pending => TCStatus::Pending,
Status::Completed => TCStatus::Completed,
Status::Deleted => TCStatus::Deleted,
Status::Recurring => TCStatus::Recurring,
Status::Unknown => TCStatus::Unknown("unknown status".to_string()),
};
}
}
}
10 changes: 3 additions & 7 deletions src/task/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ unsafe impl Send for Task {}

#[pymethods]
impl Task {
#[allow(clippy::wrong_self_convention)]
pub fn into_task_data(&self) -> TaskData {
TaskData(self.0.clone().into_task_data())
}
Expand Down Expand Up @@ -103,18 +104,14 @@ impl Task {
/// Returns:
/// list[str]: list of tags
pub fn get_tags(&self) -> Vec<Tag> {
self.0.get_tags().into_iter().map(|v| Tag(v)).collect()
self.0.get_tags().map(Tag).collect()
}
/// Get task annotations
///
/// Returns:
/// list[Annotation]: list of task annotations
pub fn get_annotations(&self) -> Vec<Annotation> {
self.0
.get_annotations()
.into_iter()
.map(|annotation| Annotation(annotation))
.collect()
self.0.get_annotations().map(Annotation).collect()
}

/// Get a task UDA
Expand Down Expand Up @@ -163,7 +160,6 @@ impl Task {
pub fn get_dependencies(&self) -> Vec<String> {
self.0
.get_dependencies()
.into_iter()
.map(|uuid| uuid.to_string())
.collect()
}
Expand Down

0 comments on commit 9b2ac43

Please sign in to comment.