Skip to content

Commit 7041726

Browse files
committed
fix: resolve all compiler warnings and format code
- Add #[allow(dead_code)] attributes for ABI spec fields that are parsed but not displayed - Fix code formatting with cargo fmt - Maintain full ABI spec compatibility while suppressing unused field warnings
1 parent a3d97bb commit 7041726

File tree

6 files changed

+197
-152
lines changed

6 files changed

+197
-152
lines changed

src/abi.rs

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,19 @@ pub struct AbiInput {
55
pub name: Option<String>,
66
pub r#type: String,
77
pub indexed: Option<bool>,
8+
#[allow(dead_code)]
89
pub internal_type: Option<String>,
10+
#[allow(dead_code)]
911
pub components: Option<Vec<AbiInput>>,
1012
}
1113

1214
#[derive(Debug, Clone)]
1315
pub struct AbiOutput {
1416
pub name: Option<String>,
1517
pub r#type: String,
18+
#[allow(dead_code)]
1619
pub internal_type: Option<String>,
20+
#[allow(dead_code)]
1721
pub components: Option<Vec<AbiOutput>>,
1822
}
1923

@@ -24,8 +28,11 @@ pub struct AbiItem {
2428
pub inputs: Option<Vec<AbiInput>>,
2529
pub outputs: Option<Vec<AbiOutput>>,
2630
pub state_mutability: Option<String>,
31+
#[allow(dead_code)]
2732
pub anonymous: Option<bool>,
33+
#[allow(dead_code)]
2834
pub payable: Option<bool>,
35+
#[allow(dead_code)]
2936
pub constant: Option<bool>,
3037
}
3138

@@ -36,9 +43,12 @@ impl fmt::Display for AbiItem {
3643

3744
match type_str.as_str() {
3845
"constructor" => {
39-
let params = self.inputs.as_ref()
46+
let params = self
47+
.inputs
48+
.as_ref()
4049
.map(|inputs| {
41-
inputs.iter()
50+
inputs
51+
.iter()
4252
.map(|p| {
4353
if let Some(name) = &p.name {
4454
format!("{} {}", p.r#type, name)
@@ -53,9 +63,12 @@ impl fmt::Display for AbiItem {
5363
write!(f, "constructor({})", params)
5464
}
5565
"event" => {
56-
let params = self.inputs.as_ref()
66+
let params = self
67+
.inputs
68+
.as_ref()
5769
.map(|inputs| {
58-
inputs.iter()
70+
inputs
71+
.iter()
5972
.map(|p| {
6073
let indexed = if p.indexed.unwrap_or(false) {
6174
" indexed"
@@ -72,12 +85,20 @@ impl fmt::Display for AbiItem {
7285
.join(", ")
7386
})
7487
.unwrap_or_default();
75-
write!(f, "event {}({})", self.name.as_ref().unwrap_or(&String::new()), params)
88+
write!(
89+
f,
90+
"event {}({})",
91+
self.name.as_ref().unwrap_or(&String::new()),
92+
params
93+
)
7694
}
7795
"function" => {
78-
let params = self.inputs.as_ref()
96+
let params = self
97+
.inputs
98+
.as_ref()
7999
.map(|inputs| {
80-
inputs.iter()
100+
inputs
101+
.iter()
81102
.map(|p| {
82103
if let Some(name) = &p.name {
83104
format!("{} {}", p.r#type, name)
@@ -89,10 +110,11 @@ impl fmt::Display for AbiItem {
89110
.join(", ")
90111
})
91112
.unwrap_or_default();
92-
113+
93114
let returns = if let Some(outputs) = &self.outputs {
94115
if !outputs.is_empty() {
95-
let output_params = outputs.iter()
116+
let output_params = outputs
117+
.iter()
96118
.map(|o| {
97119
let has_name = o.name.as_ref().map_or(false, |n| !n.is_empty());
98120
if has_name {
@@ -117,11 +139,14 @@ impl fmt::Display for AbiItem {
117139
String::new()
118140
};
119141

120-
write!(f, "function {}({}){}{}",
121-
self.name.as_ref().unwrap_or(&String::new()),
122-
params,
123-
vis,
124-
returns)
142+
write!(
143+
f,
144+
"function {}({}){}{}",
145+
self.name.as_ref().unwrap_or(&String::new()),
146+
params,
147+
vis,
148+
returns
149+
)
125150
}
126151
"fallback" => {
127152
let payable = if visibility == "payable" {
@@ -139,4 +164,4 @@ impl fmt::Display for AbiItem {
139164
}
140165
}
141166
}
142-
}
167+
}

src/converter.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ impl Converter {
1111

1212
pub fn convert_to_human_readable(abi: &[AbiItem]) -> Vec<String> {
1313
abi.iter()
14-
.filter(|item| {
15-
!item.r#type.is_empty() && item.r#type != "unknown"
16-
})
14+
.filter(|item| !item.r#type.is_empty() && item.r#type != "unknown")
1715
.map(|item| item.to_string())
1816
.filter(|formatted| !formatted.is_empty() && !formatted.starts_with("{}"))
1917
.collect()
@@ -48,7 +46,8 @@ fn format_json_pretty(strings: &[String]) -> String {
4846
}
4947

5048
fn format_json_compact(strings: &[String]) -> String {
51-
let escaped: Vec<String> = strings.iter()
49+
let escaped: Vec<String> = strings
50+
.iter()
5251
.map(|s| format!("\"{}\"", escape_json_string(s)))
5352
.collect();
5453
format!("[{}]", escaped.join(","))
@@ -70,4 +69,4 @@ fn escape_json_string(s: &str) -> String {
7069
}
7170
}
7271
result
73-
}
72+
}

src/file_ops.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
use crate::converter::Converter;
12
use std::fs;
2-
use std::path::{Path, PathBuf};
33
use std::io::{self, Read, Write};
4-
use crate::converter::Converter;
4+
use std::path::{Path, PathBuf};
55

66
pub struct ConvertOptions {
77
pub suffix: String,
@@ -75,7 +75,8 @@ pub fn convert_file(
7575
path.to_path_buf()
7676
} else {
7777
let mut path = input_path.to_path_buf();
78-
let stem = path.file_stem()
78+
let stem = path
79+
.file_stem()
7980
.and_then(|s| s.to_str())
8081
.unwrap_or("output");
8182
let new_name = format!("{}{}.json", stem, options.suffix);
@@ -138,7 +139,7 @@ pub fn convert_directory(
138139

139140
for entry in entries.filter_map(Result::ok) {
140141
let path = entry.path();
141-
142+
142143
if path.is_file() {
143144
if let Some(ext) = path.extension() {
144145
if ext == "json" {
@@ -152,10 +153,9 @@ pub fn convert_directory(
152153
}
153154
}
154155

155-
let relative = path.strip_prefix(input_dir)
156-
.unwrap_or(&path);
156+
let relative = path.strip_prefix(input_dir).unwrap_or(&path);
157157
let output_path = output_dir.join(relative);
158-
158+
159159
results.push(convert_file(&path, Some(&output_path), options));
160160
}
161161
}
@@ -190,20 +190,20 @@ pub fn convert_stdin_to_stdout(options: &ConvertOptions) -> io::Result<()> {
190190

191191
fn matches_pattern(filename: &str, pattern: &str) -> bool {
192192
let pattern_parts: Vec<&str> = pattern.split('*').collect();
193-
193+
194194
if pattern_parts.is_empty() {
195195
return true;
196196
}
197197

198198
let mut filename_pos = 0;
199-
199+
200200
for (i, part) in pattern_parts.iter().enumerate() {
201201
if part.is_empty() {
202202
if i == 0 || i == pattern_parts.len() - 1 {
203203
continue;
204204
}
205205
}
206-
206+
207207
if let Some(pos) = filename[filename_pos..].find(part) {
208208
filename_pos += pos + part.len();
209209
} else {
@@ -216,4 +216,4 @@ fn matches_pattern(filename: &str, pattern: &str) -> bool {
216216
}
217217

218218
true
219-
}
219+
}

0 commit comments

Comments
 (0)