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(ci): enforce clippy and cargo fmt in CI #2628

Merged
merged 4 commits into from
Sep 11, 2023
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
64 changes: 64 additions & 0 deletions .github/workflows/formatting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Clippy

on:
pull_request:
merge_group:
push:
branches:
- master

# This will cancel previous runs when a branch or PR is updated
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref || github.run_id }}
cancel-in-progress: true

jobs:
clippy:
name: cargo clippy
runs-on: ${{ matrix.runner }}
timeout-minutes: 30
env:
CACHED_PATHS: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/

strategy:
fail-fast: false
matrix:
include:
- runner: ubuntu-latest
target: x86_64-unknown-linux-gnu

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Restore cargo cache
uses: actions/cache/restore@v3
id: cache
with:
path: ${{ env.CACHED_PATHS }}
key: ${{ matrix.target }}-cargo-test-${{ hashFiles('**/Cargo.lock') }}

- name: Setup toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: stable # We do not use MSRV so we can benefit from newer lints
targets: ${{ matrix.target }}
components: clippy, rustfmt

- name: Run `cargo clippy`
run: cargo clippy --workspace --locked --release

- name: Run `cargo fmt`
run: cargo fmt --all --check

- uses: actions/cache/save@v3
# Write a cache entry even if the tests fail but don't create any for the merge queue.
if: ${{ always() && steps.cache.outputs.cache-hit != 'true' && github.event_name != 'merge_group' }}
with:
path: ${{ env.CACHED_PATHS }}
key: ${{ steps.cache.outputs.cache-primary-key }}
2 changes: 1 addition & 1 deletion crates/noirc_evaluator/src/ssa/ir/map.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use fxhash::FxHashMap as HashMap;

Check warning on line 1 in crates/noirc_evaluator/src/ssa/ir/map.rs

View workflow job for this annotation

GitHub Actions / Spellcheck / Spellcheck

Unknown word (fxhash)
use std::{
hash::Hash,
sync::atomic::{AtomicUsize, Ordering},
Expand Down Expand Up @@ -74,7 +74,7 @@

impl<T> Clone for Id<T> {
fn clone(&self) -> Self {
Self { index: self.index, _marker: self._marker }
*self
}
}

Expand Down Expand Up @@ -237,7 +237,7 @@
}

/// A TwoWayMap is a map from both key to value and value to key.
/// This is accomplished by keeping the map bijective - for every

Check warning on line 240 in crates/noirc_evaluator/src/ssa/ir/map.rs

View workflow job for this annotation

GitHub Actions / Spellcheck / Spellcheck

Unknown word (bijective)
/// value there is exactly one key and vice-versa. Any duplicate values
/// are prevented in the call to insert.
#[derive(Debug)]
Expand Down
4 changes: 2 additions & 2 deletions crates/noirc_frontend/src/hir/def_collector/dc_mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use crate::{
hir::def_collector::dc_crate::{UnresolvedStruct, UnresolvedTrait},
node_interner::TraitId,
parser::SubModule,
FunctionDefinition, Ident, LetStatement, NoirFunction, NoirStruct,
NoirTrait, NoirTypeAlias, ParsedModule, TraitImpl, TraitImplItem, TraitItem, TypeImpl,
FunctionDefinition, Ident, LetStatement, NoirFunction, NoirStruct, NoirTrait, NoirTypeAlias,
ParsedModule, TraitImpl, TraitImplItem, TraitItem, TypeImpl,
};

use super::{
Expand Down
4 changes: 2 additions & 2 deletions crates/noirc_frontend/src/hir/def_map/namespace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ impl PerNs {
}

pub fn iter_defs(self) -> impl Iterator<Item = ModuleDefId> {
self.types.map(|it| it.0).into_iter().chain(self.values.map(|it| it.0).into_iter())
self.types.map(|it| it.0).into_iter().chain(self.values.map(|it| it.0))
}

pub fn iter_items(self) -> impl Iterator<Item = (ModuleDefId, Visibility)> {
self.types.into_iter().chain(self.values.into_iter())
self.types.into_iter().chain(self.values)
}

pub fn is_none(&self) -> bool {
Expand Down