Skip to content

Commit

Permalink
chore(ci): add rustfmt checks and fix format issues (#40)
Browse files Browse the repository at this point in the history
Signed-off-by: Lorenzo Delgado <[email protected]>
  • Loading branch information
LNSD authored Jun 4, 2024
1 parent e7a2721 commit 72eb0a2
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 18 deletions.
35 changes: 24 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ name: ci
on:
pull_request:
push:
branches:
- "main"
branches: [ main ]

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
Expand All @@ -26,16 +25,30 @@ jobs:
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
components: rustfmt, clippy
profile: minimal
override: true
components: clippy

- name: Cache Cargo build files
- name: Cache rust build files
uses: Leafwing-Studios/cargo-cache@c7e8aa40ae2c975774d3bd766beb92927cfd7771 # v1

- run: cargo check
- run: cargo fmt --all -- --check
- run: cargo clippy -- -D warnings
- name: check (release)
run: cargo check --workspace --all-targets --all-features --release

- name: Unit tests
run: cargo test --lib
- name: clippy
run: cargo clippy --workspace --all-targets --all-features -- -D warnings --force-warn deprecated --force-warn dead-code

- name: unit-tests
run: cargo test --all-features --lib

format:
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4

- name: Setup Rust toolchain
uses: dtolnay/rust-toolchain@nightly
with:
toolchain: nightly
components: rustfmt

- run: cargo +nightly fmt --all -- --check
3 changes: 2 additions & 1 deletion candidate-selection/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ pub mod num;
#[cfg(test)]
mod test;

pub use crate::num::Normalized;
pub use arrayvec::ArrayVec;
use ordered_float::NotNan;

pub use crate::num::Normalized;

pub trait Candidate {
type Id: Eq + Ord;
fn id(&self) -> Self::Id;
Expand Down
3 changes: 2 additions & 1 deletion candidate-selection/src/test.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::{select, ArrayVec, Candidate, Normalized};
use proptest::{prelude::prop, prop_assert_eq, prop_compose, proptest};

use crate::{select, ArrayVec, Candidate, Normalized};

#[derive(Debug)]
struct TestCandidate {
id: u8,
Expand Down
7 changes: 4 additions & 3 deletions indexer-selection/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ mod performance;
#[cfg(test)]
mod test;

pub use candidate_selection::{ArrayVec, Normalized};
use custom_debug::CustomDebug;
pub use performance::*;
use std::{
collections::hash_map::DefaultHasher,
f64::consts::E,
fmt::Display,
hash::{Hash as _, Hasher as _},
};

pub use candidate_selection::{ArrayVec, Normalized};
use custom_debug::CustomDebug;
pub use performance::*;
use thegraph_core::types::{alloy_primitives::Address, DeploymentId};
use url::Url;

Expand Down
6 changes: 4 additions & 2 deletions indexer-selection/src/test.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use crate::*;
use std::ops::RangeInclusive;

use candidate_selection::{num::assert_within, Candidate as _};
use proptest::{prop_assert, prop_compose, proptest};
use std::ops::RangeInclusive;
use thegraph_core::types::alloy_primitives::{hex, FixedBytes};

use crate::*;

#[test]
fn candidate_should_use_url_display_for_debug() {
let expected_url = "https://example.com/candidate/test/url";
Expand Down
3 changes: 3 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[toolchain]
channel = "stable"
profile = "default"
4 changes: 4 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
unstable_features = true
imports_granularity = "Crate"
group_imports = "StdExternalCrate"
reorder_modules = true

0 comments on commit 72eb0a2

Please sign in to comment.