diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml new file mode 100644 index 0000000..45c99b4 --- /dev/null +++ b/.github/workflows/checks.yml @@ -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/cargo@v1.0.3 + 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/cargo@v1.0.3 + with: + command: fmt + args: --all -- --check diff --git a/src/lib.rs b/src/lib.rs index c2c6c3b..395f5f8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,5 @@ +#![allow(clippy::new_without_default)] + use pyo3::prelude::*; pub mod replica; use replica::*; diff --git a/src/replica.rs b/src/replica.rs index bd047d1..59c5fa8 100644 --- a/src/replica.rs +++ b/src/replica.rs @@ -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())) } @@ -77,7 +77,7 @@ impl Replica { } pub fn working_set(&mut self) -> anyhow::Result { - 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 { @@ -89,7 +89,7 @@ impl Replica { // TODO: better error handling here Rc::into_inner(rc).unwrap() }) - .map(|dm| DependencyMap(dm))?; + .map(DependencyMap)?; Ok(s) } @@ -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> { 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) { diff --git a/src/task/data.rs b/src/task/data.rs index 5ea401e..b8e2381 100644 --- a/src/task/data.rs +++ b/src/task/data.rs @@ -14,7 +14,7 @@ impl TaskData { let mut ops: Vec = 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 { @@ -34,13 +34,13 @@ impl TaskData { let mut ops: Vec = 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 = Vec::new(); self.0.delete(&mut ops); - ops.get(0).map(|op| Operation(op.clone())).expect("") + ops.first().map(|op| Operation(op.clone())).expect("") } } diff --git a/src/task/mod.rs b/src/task/mod.rs index f28e9ec..b677279 100644 --- a/src/task/mod.rs +++ b/src/task/mod.rs @@ -1,3 +1,4 @@ +#![allow(clippy::module_inception)] mod annotation; mod data; mod status; diff --git a/src/task/status.rs b/src/task/status.rs index 77dae47..cec2479 100644 --- a/src/task/status.rs +++ b/src/task/status.rs @@ -14,24 +14,24 @@ pub enum Status { impl From 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 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()), - }; + } } } diff --git a/src/task/task.rs b/src/task/task.rs index 5ecb83e..2865ff3 100644 --- a/src/task/task.rs +++ b/src/task/task.rs @@ -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()) } @@ -103,18 +104,14 @@ impl Task { /// Returns: /// list[str]: list of tags pub fn get_tags(&self) -> Vec { - 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 { - self.0 - .get_annotations() - .into_iter() - .map(|annotation| Annotation(annotation)) - .collect() + self.0.get_annotations().map(Annotation).collect() } /// Get a task UDA @@ -163,7 +160,6 @@ impl Task { pub fn get_dependencies(&self) -> Vec { self.0 .get_dependencies() - .into_iter() .map(|uuid| uuid.to_string()) .collect() }