Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: clippy fixes #167

Merged
merged 10 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 27 additions & 16 deletions .github/workflows/rust-clippy.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# rust-clippy is a tool that runs a bunch of lints to catch common
# mistakes in your Rust code and help improve your Rust code.
# More details at https://github.com/rust-lang/rust-clippy
Expand All @@ -18,6 +14,13 @@ on:
schedule:
- cron: '29 19 * * 2'

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

env:
CARGO_TERM_COLOR: always

jobs:
rust-clippy-analyze:
name: Run rust-clippy analyzing
Expand All @@ -30,23 +33,31 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4

- name: Install Rust toolchain
uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af #@v1
- uses: actions/cache@v3
id: cache-cargo
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: ${{ runner.os }}-cargo-

- name: Install Protoc
uses: arduino/setup-protoc@v3
with:
profile: minimal
toolchain: stable
components: clippy
override: true
version: "25.1"
repo-token: ${{ secrets.GITHUB_TOKEN }}

- name: Run rust-clippy
run: cargo clippy --all-targets --all-features -- -D warnings

- name: Install required cargo
run: cargo install clippy-sarif sarif-fmt

- name: Run rust-clippy
run:
cargo clippy
--all-features
--message-format=json | clippy-sarif | tee rust-clippy-results.sarif | sarif-fmt
continue-on-error: true
- name: Run rust-sarif
run: cargo clippy --all-features --message-format=json |
clippy-sarif | tee rust-clippy-results.sarif | sarif-fmt

- name: Upload analysis results to GitHub
uses: github/codeql-action/upload-sarif@v3
Expand Down
39 changes: 39 additions & 0 deletions .github/workflows/rust-fmt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: rust-fmt analyze

on:
push:
branches: [ "master" ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ "master" ]
schedule:
- cron: '29 19 * * 2'

concurrency:
# One build per PR, branch or tag
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

env:
CARGO_TERM_COLOR: always

jobs:
rust-fmt-analyze:
name: Run rust-fmt analyzing
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}

- name: cargo fmt
run: cargo fmt --all -- --check
69 changes: 62 additions & 7 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,85 @@ name: Rust

on:
push:
branches: [ "master" ]
branches: ["master"]
paths-ignore:
- "docs/**"

pull_request:
branches: [ "master" ]
branches: ["master"]
paths-ignore:
- "docs/**"

env:
CARGO_TERM_COLOR: always

jobs:
build:

code-coverage:
runs-on: ubuntu-latest
env:
CARGO_TERM_COLOR: always
steps:
- uses: actions/checkout@v4
- name: Install Rust
run: rustup update stable
- name: Install deps
run: |
sudo apt-get update
sudo apt install -y libsoxr-dev libopus-dev libssl-dev libfdk-aac-dev

- uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}

- name: Install Protoc
uses: arduino/setup-protoc@v3
with:
version: "25.1"
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Install cargo-llvm-cov
uses: taiki-e/install-action@cargo-llvm-cov
- name: Running cargo test
run: cargo test --all-features --workspace
- name: Generate code coverage
run: cargo llvm-cov --all-features --workspace --lcov --output-path lcov.info
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos
files: lcov.info
fail_ci_if_error: false
fail_ci_if_error: false
cargo-deny:
name: cargo-deny

# TODO: remove this matrix when https://github.com/EmbarkStudios/cargo-deny/issues/324 is resolved
strategy:
fail-fast: false
matrix:
platform:
- x86_64-unknown-linux-gnu
# - x86_64-unknown-linux-musl
- aarch64-unknown-linux-gnu
# - arm-unknown-linux-gnueabihf
# - armv7-unknown-linux-gnueabihf
# - mips-unknown-linux-gnu
# - mips64-unknown-linux-gnuabi64
# - mips64el-unknown-linux-gnuabi64
# - mipsel-unknown-linux-gnu
# - aarch64-unknown-linux-musl
- x86_64-apple-darwin
- aarch64-apple-darwin
# - x86_64-pc-windows-gnu
# - x86_64-pc-windows-msvc

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: EmbarkStudios/cargo-deny-action@v1
with:
command: check
log-level: error
arguments: --all-features --target ${{ matrix.platform }}
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ clap = { version = "4.4", features = ["derive", "env"] }
mockall = "0.12.1"
num_enum = "0.7.2"
convert-enum = "0.1.0"
sans-io-runtime = "0.1.0"
sans-io-runtime = { version = "0.1.0", default-features = false }
2 changes: 2 additions & 0 deletions bin/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::bool_assert_comparison)]

use atm0s_sdn::secure::StaticKeyAuthorization;
use atm0s_sdn::services::visualization;
use atm0s_sdn::{
Expand Down
61 changes: 61 additions & 0 deletions deny.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
[graph]

targets = [
]
all-features = false
no-default-features = false
[output]
feature-depth = 1

[advisories]
ignore = [
]

[licenses]
unlicensed = "allow"
allow = [
"Apache-2.0",
"BSD-2-Clause",
"BSD-3-Clause",
"ISC",
"MIT",
"Unicode-DFS-2016",
"WTFPL",

]
confidence-threshold = 0.8
exceptions = [
]


[licenses.private]
ignore = false
registries = [
#"https://sekretz.com/registry
]

[bans]
multiple-versions = "warn"
wildcards = "allow"
highlight = "all"
workspace-default-features = "allow"
external-default-features = "allow"
allow = [
]
deny = [
]

skip = [
]
skip-tree = [
]
[sources]
unknown-registry = "warn"
unknown-git = "warn"
allow-registry = ["https://github.com/rust-lang/crates.io-index"]
allow-git = []

[sources.allow-org]
github = [""]
gitlab = [""]
bitbucket = [""]
6 changes: 1 addition & 5 deletions packages/core/identity/src/conn_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,7 @@
impl PartialOrd<Self> for ConnId {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
//compare both session and direction
if self.session == other.session {
self.direction.partial_cmp(&other.direction)
} else {
self.session.partial_cmp(&other.session)
}
Some(self.cmp(other))

Check warning on line 124 in packages/core/identity/src/conn_id.rs

View check run for this annotation

Codecov / codecov/patch

packages/core/identity/src/conn_id.rs#L124

Added line #L124 was not covered by tests
}
}

Expand Down
2 changes: 2 additions & 0 deletions packages/core/identity/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::bool_assert_comparison)]

mod conn_id;
mod node_addr;
mod node_id;
Expand Down
8 changes: 4 additions & 4 deletions packages/core/identity/src/node_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,23 +77,23 @@
fn layer(&self, index: u8) -> u8 {
assert!(index <= 3);

(*self >> 8 * index) as u8
(*self >> (8 * index)) as u8
}

fn build(geo1: u8, geo2: u8, group: u8, index: u8) -> Self {
((geo1 as u32) << 8 * 3) | ((geo2 as u32) << 8 * 2) | ((group as u32) << 8) | (index as u32)
((geo1 as u32) << (8 * 3)) | ((geo2 as u32) << (8 * 2)) | ((group as u32) << 8) | (index as u32)
}

fn build2(zone_id: u16, group: u8, index: u8) -> Self {
((zone_id as u32) << 16) | ((group as u32) << 8) | (index as u32)
}

fn geo1(&self) -> u8 {
(*self >> 8 * 3) as u8
(*self >> (8 * 3)) as u8

Check warning on line 92 in packages/core/identity/src/node_id.rs

View check run for this annotation

Codecov / codecov/patch

packages/core/identity/src/node_id.rs#L92

Added line #L92 was not covered by tests
}

fn geo2(&self) -> u8 {
(*self >> 8 * 2) as u8
(*self >> (8 * 2)) as u8

Check warning on line 96 in packages/core/identity/src/node_id.rs

View check run for this annotation

Codecov / codecov/patch

packages/core/identity/src/node_id.rs#L96

Added line #L96 was not covered by tests
}

fn group(&self) -> u8 {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/router/src/core/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,8 +455,8 @@ mod tests {

for i in 0..100 {
let key: u32 = rand::random();
let next_a = router_a.closest_node(key, &vec![]);
let next_b = router_b.closest_node(key, &vec![]);
let next_a = router_a.closest_node(key, &[]);
let next_b = router_b.closest_node(key, &[]);
match (next_a, next_b) {
(Some(a), Some(b)) => {
panic!("Step {}, Wrong with key {} => {:?} {:?}", i, key, a, b);
Expand Down
4 changes: 2 additions & 2 deletions packages/core/router/src/core/table/metric.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ impl Metric {
pub fn score(&self) -> u32 {
let based_score = self.latency as u32 + (self.hops.len() as u32 * HOP_PLUS_RTT as u32);
if self.bandwidth >= BANDWIDTH_LIMIT {
return based_score;
based_score
} else {
return based_score + BANDWIDTH_SCORE_PENALTY;
based_score + BANDWIDTH_SCORE_PENALTY
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/core/router/src/core/table/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub struct Path(pub ConnId, pub Metric);

impl PartialOrd for Path {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
self.1.partial_cmp(&other.1)
Some(self.cmp(other))
}
}

Expand Down
8 changes: 5 additions & 3 deletions packages/core/router/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::bool_assert_comparison)]

use atm0s_sdn_identity::{NodeId, NodeIdType};
pub mod core;
pub mod shadow;
Expand All @@ -21,9 +23,9 @@ impl ServiceBroadcastLevel {
}
}

impl Into<u8> for ServiceBroadcastLevel {
fn into(self) -> u8 {
match self {
impl From<ServiceBroadcastLevel> for u8 {
fn from(val: ServiceBroadcastLevel) -> Self {
match val {
ServiceBroadcastLevel::Global => 0,
ServiceBroadcastLevel::Geo1 => 1,
ServiceBroadcastLevel::Geo2 => 2,
Expand Down
2 changes: 2 additions & 0 deletions packages/core/utils/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::bool_assert_comparison)]

pub mod error_handle;
pub mod hash;
pub mod init_array;
Expand Down
1 change: 1 addition & 0 deletions packages/network/src/base/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub struct NeighboursControl {
}

impl NeighboursControl {
#[allow(clippy::result_unit_err)]
pub fn validate(&self, now: u64, auth: &dyn Authorization) -> Result<NeighboursControlCmds, ()> {
auth.validate(self.from, &self.cmd, &self.signature).ok_or(())?;
let (ts, cmd) = bincode::DefaultOptions::new().with_limit(1499).deserialize::<(u64, NeighboursControlCmds)>(&self.cmd).map_err(|_| ())?;
Expand Down
Loading
Loading