Skip to content

Commit 90ba580

Browse files
Improve code quality with linting fixes and cleanup (#4)
* Improve code quality with linting fixes and cleanup - Added rustfmt.toml and .clippy.toml configuration files - Fixed redundant closures by using direct function references - Marked unused variables with underscores - Added #[allow(dead_code)] attributes to public API functions - Simplified return statements and improved code patterns - Fixed error handling in async functions - All tests passing with no Clippy warnings in main code * Add GitHub Actions workflow with linting and testing steps - Added a CI workflow that runs on push to main and pull requests - Included separate jobs for build/test and linting - Added code formatting check with rustfmt - Added Clippy linting with warnings treated as errors - Configured caching to speed up CI runs --------- Co-authored-by: Don Johnson <[email protected]>
1 parent 334de8f commit 90ba580

19 files changed

+974
-739
lines changed

.clippy.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Allow code that would be automatically fixed by rustfmt
2+
cognitive-complexity-threshold = 25
3+
too-many-arguments-threshold = 7
4+
disallowed-methods = []

.github/workflows/rust-ci.yml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: Rust CI
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
env:
10+
CARGO_TERM_COLOR: always
11+
12+
jobs:
13+
build_and_test:
14+
name: Build and Test
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v3
18+
19+
- name: Install Rust
20+
uses: actions-rs/toolchain@v1
21+
with:
22+
profile: minimal
23+
toolchain: stable
24+
override: true
25+
components: rustfmt, clippy
26+
27+
- name: Cache dependencies
28+
uses: actions/cache@v3
29+
with:
30+
path: |
31+
~/.cargo/registry
32+
~/.cargo/git
33+
target
34+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
35+
36+
- name: Build
37+
uses: actions-rs/cargo@v1
38+
with:
39+
command: build
40+
41+
- name: Run tests
42+
uses: actions-rs/cargo@v1
43+
with:
44+
command: test
45+
46+
linting:
47+
name: Lint Code
48+
runs-on: ubuntu-latest
49+
steps:
50+
- uses: actions/checkout@v3
51+
52+
- name: Install Rust
53+
uses: actions-rs/toolchain@v1
54+
with:
55+
profile: minimal
56+
toolchain: stable
57+
override: true
58+
components: rustfmt, clippy
59+
60+
- name: Cache dependencies
61+
uses: actions/cache@v3
62+
with:
63+
path: |
64+
~/.cargo/registry
65+
~/.cargo/git
66+
target
67+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
68+
69+
- name: Check code formatting
70+
uses: actions-rs/cargo@v1
71+
with:
72+
command: fmt
73+
args: --all -- --check
74+
75+
- name: Clippy
76+
uses: actions-rs/cargo@v1
77+
with:
78+
command: clippy
79+
args: -- -D warnings

rustfmt.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
max_width = 100
2+
hard_tabs = false
3+
tab_spaces = 4
4+
newline_style = "Auto"
5+
use_small_heuristics = "Default"
6+
reorder_imports = true
7+
reorder_modules = true
8+
remove_nested_parens = true
9+
edition = "2021"
10+
merge_derives = true
11+
use_field_init_shorthand = true
12+
use_try_shorthand = true
13+
format_strings = true

src/config.rs

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11
use anyhow::Result;
22
use std::path::Path;
3-
use tracing;
43

54
/// Configuration for scanning
65
#[derive(Debug, Clone)]
76
pub struct ScanConfig {
87
/// Path to input file with domains, one per line
98
pub input_file: String,
10-
9+
1110
/// Path to rules file
1211
pub rules_file: String,
13-
12+
1413
/// Number of concurrent scanners
1514
pub concurrency: usize,
16-
15+
1716
/// Verbosity level: 0=error, 1=warn, 2=info, 3=debug, 4=trace
1817
pub verbosity: u8,
19-
18+
2019
/// Whether to use distributed mode
2120
pub distributed: bool,
22-
21+
2322
/// Path to output file
2423
pub output_file: Option<String>,
2524

@@ -71,6 +70,7 @@ impl Default for ScanConfig {
7170

7271
impl ScanConfig {
7372
/// Create a new scan configuration with default values
73+
#[allow(dead_code)]
7474
pub fn new(input_file: String, rules_file: String) -> Self {
7575
Self {
7676
input_file,
@@ -89,35 +89,32 @@ impl ScanConfig {
8989
verbose: false,
9090
}
9191
}
92-
92+
9393
/// Validate the configuration
9494
pub fn validate(&self) -> Result<()> {
9595
// Check if input file exists
9696
if !Path::new(&self.input_file).exists() {
9797
anyhow::bail!("input file does not exist: {}", self.input_file);
9898
}
99-
99+
100100
// Check if rules file exists
101101
if !Path::new(&self.rules_file).exists() {
102102
anyhow::bail!("Rules file does not exist: {}", self.rules_file);
103103
}
104-
104+
105105
// Check concurrency value
106106
if self.concurrency == 0 {
107107
anyhow::bail!("Invalid concurrency value: must be greater than 0");
108108
}
109-
109+
110110
Ok(())
111111
}
112-
112+
113113
/// Log the configuration
114114
pub fn log_config(&self) {
115115
// Use event-based tracing which is more reliably captured by test infrastructure
116-
tracing::event!(
117-
tracing::Level::INFO,
118-
message = "Configuration:"
119-
);
120-
116+
tracing::event!(tracing::Level::INFO, message = "Configuration:");
117+
121118
// Log each configuration value as a separate event for better test capturing
122119
tracing::event!(
123120
tracing::Level::INFO,
@@ -189,7 +186,7 @@ impl ScanConfig {
189186
verbose = self.verbose,
190187
message = format!(" verbose: {}", self.verbose)
191188
);
192-
189+
193190
tracing::event!(
194191
tracing::Level::DEBUG,
195192
message = "Configuration validated successfully"

0 commit comments

Comments
 (0)