Skip to content

Commit

Permalink
ci: run cargo clippy in ci
Browse files Browse the repository at this point in the history
  • Loading branch information
hugocaillard committed Oct 23, 2024
1 parent 11e9f66 commit f633077
Show file tree
Hide file tree
Showing 12 changed files with 224 additions and 299 deletions.
19 changes: 12 additions & 7 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,25 @@ concurrency:
group: ${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}
cancel-in-progress: true

# Make sure CI fails on all warnings, including Clippy lints
env:
RUSTFLAGS: "-Dwarnings"

jobs:
format:
name: Format check
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install Rust toolchain
run: rustup toolchain install stable --profile minimal --component rustfmt

- uses: actions/checkout@v4
- name: Run rustfmt
run: cargo fmt --all -- --check

clippy_check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run Clippy
run: cargo clippy --all-targets --all-features

build:
runs-on: ubuntu-latest
outputs:
Expand Down
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"rust-analyzer.check.command": "clippy"
}
2 changes: 1 addition & 1 deletion src/api_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl ApiConfig {
let config_file: ApiConfig = match toml::from_slice(&file_buffer) {
Ok(s) => s,
Err(e) => {
panic!("Config file malformatted {}", e.to_string());
panic!("Config file malformatted {}", e);
}
};
config_file
Expand Down
28 changes: 11 additions & 17 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,26 +45,23 @@ impl StacksDevnetConfig {
);

if user_id != self.namespace {
let msg =
let message =
format!("{context}, ERROR: devnet namespace must match authenticated user id");
ctx.try_log(|logger| slog::warn!(logger, "{}", msg));
return Err(DevNetError {
message: msg.into(),
code: 400,
});
ctx.try_log(|logger| slog::warn!(logger, "{}", message));
return Err(DevNetError { message, code: 400 });
}

let project_manifest_yaml_string = self
.get_project_manifest_yaml_string()
.map_err(|e| log_and_return_err(e, &context, &ctx))?;
.map_err(|e| log_and_return_err(e, &context, ctx))?;

let (network_manifest_yaml_string, devnet_config) = self
.get_network_manifest_string_and_devnet_config()
.map_err(|e| log_and_return_err(e, &context, &ctx))?;
.map_err(|e| log_and_return_err(e, &context, ctx))?;

let deployment_plan_yaml_string = self
.get_deployment_plan_yaml_string()
.map_err(|e| log_and_return_err(e, &context, &ctx))?;
.map_err(|e| log_and_return_err(e, &context, ctx))?;

let mut contracts: Vec<(String, String)> = vec![];
for (contract_identifier, (src, _)) in self.deployment_plan.contracts {
Expand Down Expand Up @@ -170,7 +167,7 @@ impl StacksDevnetConfig {
spec.location = contracts_loc.clone();
},
TransactionSpecification::EmulatedContractCall(_) | TransactionSpecification::EmulatedContractPublish(_) => {
return Err(format!("devnet deployment plans do not support emulated-contract-calls or emulated-contract-publish types"))
return Err("devnet deployment plans do not support emulated-contract-calls or emulated-contract-publish types".to_string())
}
TransactionSpecification::ContractCall(_) => {},
TransactionSpecification::BtcTransfer(_) => {},
Expand All @@ -184,12 +181,9 @@ impl StacksDevnetConfig {
}

fn log_and_return_err(e: String, context: &str, ctx: &Context) -> DevNetError {
let msg = format!("{context}, ERROR: {e}");
ctx.try_log(|logger: &hiro_system_kit::Logger| slog::warn!(logger, "{}", msg));
DevNetError {
message: msg.into(),
code: 400,
}
let message = format!("{context}, ERROR: {e}");
ctx.try_log(|logger: &hiro_system_kit::Logger| slog::warn!(logger, "{}", message));
DevNetError { message, code: 400 }
}
#[cfg(test)]
mod tests {
Expand Down Expand Up @@ -221,7 +215,7 @@ mod tests {
let config_file: StacksDevnetConfig = match serde_json::from_slice(&file_buffer) {
Ok(s) => s,
Err(e) => {
panic!("Config file malformatted {}", e.to_string());
panic!("Config file malformatted {}", e);
}
};
config_file
Expand Down
Loading

0 comments on commit f633077

Please sign in to comment.