Skip to content

Commit b5533d2

Browse files
committed
Add lint
1 parent 3f6437c commit b5533d2

8 files changed

Lines changed: 95 additions & 67 deletions

File tree

.github/workflows/build.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ jobs:
1616
uses: actions/checkout@v4
1717
- name: Set up Rust
1818
uses: dtolnay/rust-toolchain@stable
19+
- name: run linters
20+
run: make lint-check
1921
- name: Build rops binary
2022
run: cargo build --release
2123
- name: Upload artifact (binary)

Cargo.lock

Lines changed: 12 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Makefile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.PHONY: help
2+
help:
3+
@echo ======================================================================================
4+
@echo rOps
5+
@echo ======================================================================================
6+
@fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//'
7+
@echo ======================================================================================
8+
9+
10+
.PHONY: lint
11+
lint: ## Run linters and fix issues
12+
@./dev/lint-rs fix
13+
14+
15+
.PHONY: lint
16+
lint-check: ## Run linters
17+
@./dev/lint-rs

dev/lint-rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env bash
2+
3+
FMT_ARG="--check"
4+
CLIPPY_ARG="-- -Dwarnings"
5+
6+
if [ "$1" = "fix" ] ; then
7+
FMT_ARG=""
8+
fi
9+
10+
11+
cargo fmt ${FMT_ARG}
12+
cargo clippy ${CLIPPY_ARG}

src/docker.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -146,17 +146,9 @@ impl DockerCommand {
146146
let manifest_tag = self.get_push_tag(name, false, settings);
147147
let amd64_tag = format!("{}-amd64", manifest_tag);
148148
let arm64_tag = format!("{}-arm64", manifest_tag);
149-
self.push_manifest(
150-
&manifest_tag,
151-
&amd64_tag,
152-
&arm64_tag,
153-
)?;
149+
self.push_manifest(&manifest_tag, &amd64_tag, &arm64_tag)?;
154150
if let Some(latest_tag) = self.get_latest_tag(name, settings) {
155-
self.push_manifest(
156-
&latest_tag,
157-
&amd64_tag,
158-
&arm64_tag,
159-
)?;
151+
self.push_manifest(&latest_tag, &amd64_tag, &arm64_tag)?;
160152
}
161153
Ok(())
162154
}

src/git.rs

Lines changed: 44 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,12 @@ impl GitSettings {
8585
.arg("--short")
8686
.output();
8787

88-
if let Ok(output) = output {
89-
if output.status.success() {
90-
let branch = String::from_utf8_lossy(&output.stdout).trim().to_string();
91-
if !branch.is_empty() {
92-
return branch;
93-
}
88+
if let Ok(output) = output
89+
&& output.status.success()
90+
{
91+
let branch = String::from_utf8_lossy(&output.stdout).trim().to_string();
92+
if !branch.is_empty() {
93+
return branch;
9494
}
9595
}
9696

@@ -102,17 +102,17 @@ impl GitSettings {
102102
.arg("HEAD")
103103
.output();
104104

105-
if let Ok(output) = output {
106-
if output.status.success() {
107-
let branch_output = String::from_utf8_lossy(&output.stdout);
108-
if let Some(branch_line) = branch_output.lines().nth(1) {
109-
let branch = branch_line
110-
.split_whitespace()
111-
.next()
112-
.unwrap_or("")
113-
.to_string();
114-
return branch.trim_start_matches("remotes/origin/").to_string();
115-
}
105+
if let Ok(output) = output
106+
&& output.status.success()
107+
{
108+
let branch_output = String::from_utf8_lossy(&output.stdout);
109+
if let Some(branch_line) = branch_output.lines().nth(1) {
110+
let branch = branch_line
111+
.split_whitespace()
112+
.next()
113+
.unwrap_or("")
114+
.to_string();
115+
return branch.trim_start_matches("remotes/origin/").to_string();
116116
}
117117
}
118118

@@ -201,29 +201,30 @@ impl GithubDownloadRelease {
201201
for arch in [
202202
Some(&settings.system.arch),
203203
settings.system.arch_variant.as_ref(),
204-
] {
205-
if let Some(arch) = arch {
206-
let file_name = self.get_file_name(settings, &release, arch);
207-
file_names.push(file_name.clone());
208-
if let Some(download_url) = &self.download_url {
204+
]
205+
.into_iter()
206+
.flatten()
207+
{
208+
let file_name = self.get_file_name(settings, &release, arch);
209+
file_names.push(file_name.clone());
210+
if let Some(download_url) = &self.download_url {
211+
return Ok(Asset {
212+
url: format!("{download_url}/{file_name}"),
213+
name: file_name,
214+
version: release.tag_name.clone(),
215+
});
216+
} else {
217+
// Find the asset matching the current architecture
218+
if let Some(asset) = release
219+
.assets
220+
.iter()
221+
.find(|a| a.name.to_lowercase() == file_name)
222+
{
209223
return Ok(Asset {
210-
url: format!("{download_url}/{file_name}"),
211-
name: file_name,
224+
url: asset.url.clone(),
225+
name: asset.name.clone(),
212226
version: release.tag_name.clone(),
213227
});
214-
} else {
215-
// Find the asset matching the current architecture
216-
if let Some(asset) = release
217-
.assets
218-
.iter()
219-
.find(|a| a.name.to_lowercase() == file_name)
220-
{
221-
return Ok(Asset {
222-
url: asset.url.clone(),
223-
name: asset.name.clone(),
224-
version: release.tag_name.clone(),
225-
});
226-
}
227228
}
228229
}
229230
}
@@ -243,7 +244,12 @@ impl GithubDownloadRelease {
243244
pub fn download(&self, settings: &Settings) -> RopsResult<Asset> {
244245
let asset = self.get_asset(settings)?;
245246

246-
log::info!("Download version {} - {} from {}", asset.version, asset.name, asset.url);
247+
log::info!(
248+
"Download version {} - {} from {}",
249+
asset.version,
250+
asset.name,
251+
asset.url
252+
);
247253

248254
// Download the binary using the asset's API URL
249255
let mut response = self

src/system.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use serde::{Deserialize, Serialize};
2-
use std::{process::Command};
2+
use std::process::Command;
33

44
#[derive(Debug, Clone, Deserialize, Serialize)]
55
pub struct CurrentSystem {

src/utils.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,11 @@ impl StreamCommand {
115115
let stderr_thread = std::thread::spawn(move || {
116116
let mut error_lines = 0;
117117
for line in stderr.lines().map_while(Result::ok) {
118-
if let Some(ref skip_error) = maybe_skip_error {
119-
if line.contains(skip_error) {
120-
log::debug!("skipping error: {}", line);
121-
continue;
122-
}
118+
if let Some(ref skip_error) = maybe_skip_error
119+
&& line.contains(skip_error)
120+
{
121+
log::debug!("skipping error: {}", line);
122+
continue;
123123
}
124124
log::warn!("{}", line);
125125
error_lines += 1;

0 commit comments

Comments
 (0)