Skip to content

Commit

Permalink
Lint rust projects in CI (#60)
Browse files Browse the repository at this point in the history
* add lint-rust

* fix 1: run cargo fmt

* fix 2: run regen-lang before clippy

* fix 3: fix some clippy issues

* fix 4: clippy issues in compiler-core

* fix 5: lint issues in wasm
  • Loading branch information
Pistonight authored Sep 27, 2023
1 parent 1be178a commit 1393b2c
Show file tree
Hide file tree
Showing 49 changed files with 413 additions and 541 deletions.
17 changes: 16 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
- main

jobs:
check:
lint-typescript:
name: Lint TypeScript Packages
runs-on: ubuntu-latest
steps:
Expand All @@ -27,3 +27,18 @@ jobs:
features: cli
- run: task themes:ci client:ci docs:ci --output group
- run: task themes:check client:check docs:check --output group

lint-rust:
name: Lint Rust Packages
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: arduino/setup-task@v1
with:
version: 3.x
repo-token: ${{ secrets.GITHUB_TOKEN }}
- uses: dtolnay/rust-toolchain@stable
- uses: baptiste0928/cargo-install@v2
with:
crate: regen-lang
- run: task check:rs
36 changes: 18 additions & 18 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,26 @@ includes:
dir: ./web-themes

tasks:
check:
desc: Check issues in all packages
deps: [check:ts, check:rs]

check:ts:
cmds:
- task: docs:check
- task: client:check
- task: themes:check

check:rs:
deps: [core:grammar]
cmds:
- cargo fmt --check
- cargo clippy --all-features --all-targets -- -D warnings -D clippy::todo

fix:rs:
cmds:
- cargo fmt

docker:
deps: [build]
desc: Build docker container
Expand Down
48 changes: 27 additions & 21 deletions compiler-core/src/api.rs
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
use std::collections::HashMap;
use log::{error, info};
use std::collections::HashMap;

use celerctypes::ExecDoc;
use derivative::Derivative;

use crate::comp::{Compiler, CompilerError, CompDoc};
use crate::comp::{CompDoc, Compiler, CompilerError};
use crate::lang::Preset;
use crate::metrics::CompilerMetrics;
use crate::pack::{
self, PackedProject, Resource, ValidUse, PackerError, PackerResult,
};
use crate::pack::{self, PackedProject, PackerError, PackerResult, Resource, ValidUse};
use crate::plug::run_plugins;

/// Output of the compiler API
#[derive(Debug, Clone)]
pub enum CompilerOutput {
Ok {
/// The final document to be rendered
exec_doc: ExecDoc,
/// The metadata of the compiler
metadata: CompilerMetadata,
/// Metrics collected during compilation
metrics: CompilerMetrics,
},
Ok(Box<OkOutput>),
Cancelled,
}

#[derive(Debug, Clone)]
pub struct OkOutput {
/// The final document to be rendered
pub exec_doc: ExecDoc,
/// The metadata of the compiler
pub metadata: CompilerMetadata,
/// Metrics collected during compilation
pub metrics: CompilerMetrics,
}

/// Metadata of the compiler
///
/// This is information needed during compilation,
Expand Down Expand Up @@ -73,7 +74,9 @@ pub async fn compile(root_resource: &Resource, setting: &Setting) -> CompilerOut
return CompilerOutput::Cancelled;
}
error!("pack phase failed.");
Compiler::default().create_empty_doc_for_packer_error(e).await
Compiler::default()
.create_empty_doc_for_packer_error(e)
.await
}
Ok(packed_project) => {
let ms = metrics.pack_done();
Expand All @@ -86,9 +89,9 @@ pub async fn compile(root_resource: &Resource, setting: &Setting) -> CompilerOut
}
return CompilerOutput::Cancelled;
}
Ok(x) => x
Ok(x) => x,
}
},
}
};
let ms = metrics.comp_done();
info!("comp phase done in {ms}ms");
Expand All @@ -104,16 +107,16 @@ pub async fn compile(root_resource: &Resource, setting: &Setting) -> CompilerOut
}
return CompilerOutput::Cancelled;
}
Ok(x) => x
Ok(x) => x,
};
let ms = metrics.exec_done();
info!("exec phase done in {ms}ms");

CompilerOutput::Ok {
CompilerOutput::Ok(Box::new(OkOutput {
exec_doc,
metadata: comp_meta,
metrics,
}
}))
}

async fn pack_phase(root_resource: &Resource, setting: &Setting) -> PackerResult<PackedProject> {
Expand All @@ -122,14 +125,17 @@ async fn pack_phase(root_resource: &Resource, setting: &Setting) -> PackerResult
Ok(resource) => resource,
Err(_) => {
error!("fail to resolve project.yaml");
return Err(PackerError::InvalidProject.into());
return Err(PackerError::InvalidProject);
}
};

pack::pack_project(&project_resource, setting).await
}

async fn comp_phase(packed_project: PackedProject, setting: &Setting) -> Result<(CompDoc, CompilerMetadata), CompilerError> {
async fn comp_phase(
packed_project: PackedProject,
setting: &Setting,
) -> Result<(CompDoc, CompilerMetadata), CompilerError> {
let PackedProject {
route_metadata,
compiler_metadata,
Expand Down
10 changes: 7 additions & 3 deletions compiler-core/src/comp/comp_doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ pub struct CompDoc {
}

impl Compiler {
pub async fn comp_doc(mut self, route: PackerValue) -> Result<(CompDoc, CompilerMetadata), CompilerError> {
pub async fn comp_doc(
mut self,
route: PackerValue,
) -> Result<(CompDoc, CompilerMetadata), CompilerError> {
let mut route_vec = vec![];
let mut preface = vec![];

Expand Down Expand Up @@ -100,9 +103,10 @@ impl Compiler {

pub async fn create_empty_doc_for_packer_error(
self,
error: PackerError
error: PackerError,
) -> (CompDoc, CompilerMetadata) {
self.create_empty_doc_for_error(&[CompilerError::PackerErrors(vec![error])]).await
self.create_empty_doc_for_error(&[CompilerError::PackerErrors(vec![error])])
.await
}

pub async fn create_empty_doc_for_error(
Expand Down
4 changes: 2 additions & 2 deletions compiler-core/src/comp/comp_line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ impl Compiler {
Value::Array(array) => {
// need to track the coordinate of the final position with a stack
let mut ref_stack = vec![];
async_for!((i, v) in array.into_iter().enumerate(), {
let _ = async_for!((i, v) in array.into_iter().enumerate(), {
if let Some(m) = self
.comp_movement(&format!("{p}[{i}]", p = prop::MOVEMENTS), v, errors)
.await
Expand Down Expand Up @@ -299,7 +299,7 @@ impl Compiler {
}
prop::MARKERS => match value {
Value::Array(array) => {
async_for!((i, v) in array.into_iter().enumerate(), {
let _ = async_for!((i, v) in array.into_iter().enumerate(), {
if let Some(m) = self
.comp_marker(&format!("{p}[{i}]", p = prop::MARKERS), v, errors)
.await
Expand Down
4 changes: 1 addition & 3 deletions compiler-core/src/comp/comp_section.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ impl Compiler {
};

let mut iter = section_obj.into_iter();
let (section_name, section_value) = iter
.next()
.ok_or_else(|| CompilerError::InvalidSectionType)?;
let (section_name, section_value) = iter.next().ok_or(CompilerError::InvalidSectionType)?;
if iter.next().is_some() {
return Err(CompilerError::InvalidSectionType);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,13 @@
//! Builder for making a compiler in tests
use std::collections::HashMap;

use celerctypes::{GameCoord, MapCoordMap, RouteMetadata};
use derivative::Derivative;
use celerctypes::{GameCoord, RouteMetadata};

use crate::api::CompilerMetadata;
use crate::lang::Preset;

#[derive(Derivative, Debug, Clone)]
#[derivative(Default)]
pub struct Compiler {
pub project: RouteMetadata,
pub meta: CompilerMetadata,
/// Current color of the map line
pub color: String,
/// Current position on the map
pub coord: GameCoord,
#[derivative(Default(value = "8"))]
pub max_preset_depth: usize,
}
use super::Compiler;

#[cfg(test)]
#[derive(Default, Debug, Clone)]
pub struct CompilerBuilder {
project: RouteMetadata,
Expand All @@ -29,7 +17,6 @@ pub struct CompilerBuilder {
default_icon_priority: i64,
}

#[cfg(test)]
impl CompilerBuilder {
pub fn new(project: RouteMetadata, color: String, coord: GameCoord) -> Self {
CompilerBuilder {
Expand Down
Loading

0 comments on commit 1393b2c

Please sign in to comment.