Skip to content

Commit 069e75b

Browse files
Alex HolmbergAlex Holmberg
authored andcommitted
feat: rant fmt and lint check
1 parent 1ad5282 commit 069e75b

21 files changed

Lines changed: 141 additions & 209 deletions

.DS_Store

0 Bytes
Binary file not shown.

src/agent/persistence.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,11 +251,10 @@ impl SessionSelector {
251251
let sessions = self.list_sessions();
252252

253253
// Try to parse as numeric index first
254-
if let Ok(index) = identifier.parse::<usize>() {
255-
if index > 0 && index <= sessions.len() {
254+
if let Ok(index) = identifier.parse::<usize>()
255+
&& index > 0 && index <= sessions.len() {
256256
return sessions.into_iter().nth(index - 1);
257257
}
258-
}
259258

260259
// Try to find by UUID or partial UUID
261260
sessions

src/agent/tools/fetch.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ impl WebFetchTool {
6969
let robots_url = format!("{}://{}/robots.txt", url.scheme(), url.authority());
7070

7171
// Try to fetch robots.txt (ignore errors - many sites don't have one)
72-
if let Ok(response) = self.client().get(&robots_url).send().await {
73-
if response.status().is_success() {
74-
if let Ok(robots_content) = response.text().await {
72+
if let Ok(response) = self.client().get(&robots_url).send().await
73+
&& response.status().is_success()
74+
&& let Ok(robots_content) = response.text().await {
7575
let path = url.path();
7676
for line in robots_content.lines() {
7777
if let Some(disallowed) = line.strip_prefix("Disallow: ") {
@@ -97,8 +97,6 @@ impl WebFetchTool {
9797
}
9898
}
9999
}
100-
}
101-
}
102100
Ok(())
103101
}
104102

src/agent/ui/hooks.rs

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,8 +1193,8 @@ fn format_kubelint_result(
11931193
let mut lines = Vec::new();
11941194

11951195
// Check for parse errors first
1196-
if let Some(errors) = parse_errors {
1197-
if !errors.is_empty() {
1196+
if let Some(errors) = parse_errors
1197+
&& !errors.is_empty() {
11981198
lines.push(format!(
11991199
"{}☸ {} parse error{} (files could not be fully analyzed){}",
12001200
ansi::HIGH,
@@ -1235,7 +1235,6 @@ fn format_kubelint_result(
12351235
return (false, lines);
12361236
}
12371237
}
1238-
}
12391238

12401239
if total == 0 && parse_errors.map(|e| e.is_empty()).unwrap_or(true) {
12411240
lines.push(format!(
@@ -1326,8 +1325,8 @@ fn format_kubelint_result(
13261325
}
13271326

13281327
// Then high priority
1329-
if shown < MAX_PREVIEW {
1330-
if let Some(high_issues) = action_plan
1328+
if shown < MAX_PREVIEW
1329+
&& let Some(high_issues) = action_plan
13311330
.and_then(|a| a.get("high"))
13321331
.and_then(|h| h.as_array())
13331332
{
@@ -1336,11 +1335,10 @@ fn format_kubelint_result(
13361335
shown += 1;
13371336
}
13381337
}
1339-
}
13401338

13411339
// Show quick fix hint
1342-
if let Some(quick_fixes) = v.get("quick_fixes").and_then(|q| q.as_array()) {
1343-
if let Some(first_fix) = quick_fixes.first().and_then(|f| f.as_str()) {
1340+
if let Some(quick_fixes) = v.get("quick_fixes").and_then(|q| q.as_array())
1341+
&& let Some(first_fix) = quick_fixes.first().and_then(|f| f.as_str()) {
13441342
let truncated = if first_fix.len() > 70 {
13451343
format!("{}...", &first_fix[..67])
13461344
} else {
@@ -1353,7 +1351,6 @@ fn format_kubelint_result(
13531351
ansi::RESET
13541352
));
13551353
}
1356-
}
13571354

13581355
// Note about remaining issues
13591356
let remaining = total as usize - shown;
@@ -1429,8 +1426,8 @@ fn format_helmlint_result(
14291426
let mut lines = Vec::new();
14301427

14311428
// Check for parse errors first
1432-
if let Some(errors) = parse_errors {
1433-
if !errors.is_empty() {
1429+
if let Some(errors) = parse_errors
1430+
&& !errors.is_empty() {
14341431
lines.push(format!(
14351432
"{}⎈ {} parse error{} (chart could not be fully analyzed){}",
14361433
ansi::HIGH,
@@ -1471,7 +1468,6 @@ fn format_helmlint_result(
14711468
return (false, lines);
14721469
}
14731470
}
1474-
}
14751471

14761472
if total == 0 && parse_errors.map(|e| e.is_empty()).unwrap_or(true) {
14771473
lines.push(format!(
@@ -1562,8 +1558,8 @@ fn format_helmlint_result(
15621558
}
15631559

15641560
// Then high priority
1565-
if shown < MAX_PREVIEW {
1566-
if let Some(high_issues) = action_plan
1561+
if shown < MAX_PREVIEW
1562+
&& let Some(high_issues) = action_plan
15671563
.and_then(|a| a.get("high"))
15681564
.and_then(|h| h.as_array())
15691565
{
@@ -1572,11 +1568,10 @@ fn format_helmlint_result(
15721568
shown += 1;
15731569
}
15741570
}
1575-
}
15761571

15771572
// Show quick fix hint
1578-
if let Some(quick_fixes) = v.get("quick_fixes").and_then(|q| q.as_array()) {
1579-
if let Some(first_fix) = quick_fixes.first().and_then(|f| f.as_str()) {
1573+
if let Some(quick_fixes) = v.get("quick_fixes").and_then(|q| q.as_array())
1574+
&& let Some(first_fix) = quick_fixes.first().and_then(|f| f.as_str()) {
15801575
let truncated = if first_fix.len() > 70 {
15811576
format!("{}...", &first_fix[..67])
15821577
} else {
@@ -1589,7 +1584,6 @@ fn format_helmlint_result(
15891584
ansi::RESET
15901585
));
15911586
}
1592-
}
15931587

15941588
// Note about remaining issues
15951589
let remaining = total as usize - shown;

src/analyzer/helmlint/lint.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,11 +315,10 @@ fn collect_chart_files(path: &Path) -> HashSet<String> {
315315
.into_iter()
316316
.filter_map(|e| e.ok())
317317
{
318-
if entry.path().is_file() {
319-
if let Ok(relative) = entry.path().strip_prefix(path) {
318+
if entry.path().is_file()
319+
&& let Ok(relative) = entry.path().strip_prefix(path) {
320320
files.insert(relative.display().to_string());
321321
}
322-
}
323322
}
324323

325324
files

src/analyzer/helmlint/pragma.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,17 @@ impl PragmaState {
3838
}
3939

4040
// Check if the rule is ignored for this specific line
41-
if let Some(ignores) = self.line_ignores.get(&line) {
42-
if ignores.contains(code.as_str()) {
41+
if let Some(ignores) = self.line_ignores.get(&line)
42+
&& ignores.contains(code.as_str()) {
4343
return true;
4444
}
45-
}
4645

4746
// Check if previous line has an ignore pragma for this line
48-
if line > 1 {
49-
if let Some(ignores) = self.line_ignores.get(&(line - 1)) {
50-
if ignores.contains(code.as_str()) {
47+
if line > 1
48+
&& let Some(ignores) = self.line_ignores.get(&(line - 1))
49+
&& ignores.contains(code.as_str()) {
5150
return true;
5251
}
53-
}
54-
}
5552

5653
false
5754
}

src/analyzer/helmlint/rules/hl1xxx.rs

Lines changed: 25 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ impl Rule for HL1002 {
8686
}
8787

8888
fn check(&self, ctx: &LintContext) -> Vec<CheckFailure> {
89-
if let Some(chart) = ctx.chart_metadata {
90-
if !chart.has_valid_api_version() {
89+
if let Some(chart) = ctx.chart_metadata
90+
&& !chart.has_valid_api_version() {
9191
let version = match &chart.api_version {
9292
ApiVersion::Unknown(v) => v.clone(),
9393
_ => "unknown".to_string(),
@@ -101,7 +101,6 @@ impl Rule for HL1002 {
101101
RuleCategory::Structure,
102102
)];
103103
}
104-
}
105104
vec![]
106105
}
107106
}
@@ -127,8 +126,8 @@ impl Rule for HL1003 {
127126
}
128127

129128
fn check(&self, ctx: &LintContext) -> Vec<CheckFailure> {
130-
if let Some(chart) = ctx.chart_metadata {
131-
if chart.name.is_empty() {
129+
if let Some(chart) = ctx.chart_metadata
130+
&& chart.name.is_empty() {
132131
return vec![CheckFailure::new(
133132
"HL1003",
134133
Severity::Error,
@@ -138,7 +137,6 @@ impl Rule for HL1003 {
138137
RuleCategory::Structure,
139138
)];
140139
}
141-
}
142140
vec![]
143141
}
144142
}
@@ -164,8 +162,8 @@ impl Rule for HL1004 {
164162
}
165163

166164
fn check(&self, ctx: &LintContext) -> Vec<CheckFailure> {
167-
if let Some(chart) = ctx.chart_metadata {
168-
if chart.version.is_empty() {
165+
if let Some(chart) = ctx.chart_metadata
166+
&& chart.version.is_empty() {
169167
return vec![CheckFailure::new(
170168
"HL1004",
171169
Severity::Error,
@@ -175,7 +173,6 @@ impl Rule for HL1004 {
175173
RuleCategory::Structure,
176174
)];
177175
}
178-
}
179176
vec![]
180177
}
181178
}
@@ -201,8 +198,8 @@ impl Rule for HL1005 {
201198
}
202199

203200
fn check(&self, ctx: &LintContext) -> Vec<CheckFailure> {
204-
if let Some(chart) = ctx.chart_metadata {
205-
if !chart.version.is_empty() && !is_valid_semver(&chart.version) {
201+
if let Some(chart) = ctx.chart_metadata
202+
&& !chart.version.is_empty() && !is_valid_semver(&chart.version) {
206203
return vec![CheckFailure::new(
207204
"HL1005",
208205
Severity::Warning,
@@ -215,7 +212,6 @@ impl Rule for HL1005 {
215212
RuleCategory::Structure,
216213
)];
217214
}
218-
}
219215
vec![]
220216
}
221217
}
@@ -241,13 +237,13 @@ impl Rule for HL1006 {
241237
}
242238

243239
fn check(&self, ctx: &LintContext) -> Vec<CheckFailure> {
244-
if let Some(chart) = ctx.chart_metadata {
245-
if chart.description.is_none()
240+
if let Some(chart) = ctx.chart_metadata
241+
&& (chart.description.is_none()
246242
|| chart
247243
.description
248244
.as_ref()
249245
.map(|d| d.is_empty())
250-
.unwrap_or(true)
246+
.unwrap_or(true))
251247
{
252248
return vec![CheckFailure::new(
253249
"HL1006",
@@ -258,7 +254,6 @@ impl Rule for HL1006 {
258254
RuleCategory::Structure,
259255
)];
260256
}
261-
}
262257
vec![]
263258
}
264259
}
@@ -284,8 +279,8 @@ impl Rule for HL1007 {
284279
}
285280

286281
fn check(&self, ctx: &LintContext) -> Vec<CheckFailure> {
287-
if let Some(chart) = ctx.chart_metadata {
288-
if chart.maintainers.is_empty() {
282+
if let Some(chart) = ctx.chart_metadata
283+
&& chart.maintainers.is_empty() {
289284
return vec![CheckFailure::new(
290285
"HL1007",
291286
Severity::Info,
@@ -295,7 +290,6 @@ impl Rule for HL1007 {
295290
RuleCategory::Structure,
296291
)];
297292
}
298-
}
299293
vec![]
300294
}
301295
}
@@ -321,8 +315,8 @@ impl Rule for HL1008 {
321315
}
322316

323317
fn check(&self, ctx: &LintContext) -> Vec<CheckFailure> {
324-
if let Some(chart) = ctx.chart_metadata {
325-
if chart.is_deprecated() {
318+
if let Some(chart) = ctx.chart_metadata
319+
&& chart.is_deprecated() {
326320
return vec![CheckFailure::new(
327321
"HL1008",
328322
Severity::Warning,
@@ -332,7 +326,6 @@ impl Rule for HL1008 {
332326
RuleCategory::Structure,
333327
)];
334328
}
335-
}
336329
vec![]
337330
}
338331
}
@@ -359,11 +352,10 @@ impl Rule for HL1009 {
359352

360353
fn check(&self, ctx: &LintContext) -> Vec<CheckFailure> {
361354
// Skip for library charts
362-
if let Some(chart) = ctx.chart_metadata {
363-
if chart.is_library() {
355+
if let Some(chart) = ctx.chart_metadata
356+
&& chart.is_library() {
364357
return vec![];
365358
}
366-
}
367359

368360
let has_templates = ctx
369361
.files
@@ -466,8 +458,8 @@ impl Rule for HL1012 {
466458
}
467459

468460
fn check(&self, ctx: &LintContext) -> Vec<CheckFailure> {
469-
if let Some(chart) = ctx.chart_metadata {
470-
if !is_valid_chart_name(&chart.name) {
461+
if let Some(chart) = ctx.chart_metadata
462+
&& !is_valid_chart_name(&chart.name) {
471463
return vec![CheckFailure::new(
472464
"HL1012",
473465
Severity::Error,
@@ -480,7 +472,6 @@ impl Rule for HL1012 {
480472
RuleCategory::Structure,
481473
)];
482474
}
483-
}
484475
vec![]
485476
}
486477
}
@@ -506,9 +497,9 @@ impl Rule for HL1013 {
506497
}
507498

508499
fn check(&self, ctx: &LintContext) -> Vec<CheckFailure> {
509-
if let Some(chart) = ctx.chart_metadata {
510-
if let Some(icon) = &chart.icon {
511-
if icon.starts_with("http://") {
500+
if let Some(chart) = ctx.chart_metadata
501+
&& let Some(icon) = &chart.icon
502+
&& icon.starts_with("http://") {
512503
return vec![CheckFailure::new(
513504
"HL1013",
514505
Severity::Warning,
@@ -518,8 +509,6 @@ impl Rule for HL1013 {
518509
RuleCategory::Structure,
519510
)];
520511
}
521-
}
522-
}
523512
vec![]
524513
}
525514
}
@@ -545,9 +534,9 @@ impl Rule for HL1014 {
545534
}
546535

547536
fn check(&self, ctx: &LintContext) -> Vec<CheckFailure> {
548-
if let Some(chart) = ctx.chart_metadata {
549-
if let Some(home) = &chart.home {
550-
if home.starts_with("http://") {
537+
if let Some(chart) = ctx.chart_metadata
538+
&& let Some(home) = &chart.home
539+
&& home.starts_with("http://") {
551540
return vec![CheckFailure::new(
552541
"HL1014",
553542
Severity::Warning,
@@ -557,8 +546,6 @@ impl Rule for HL1014 {
557546
RuleCategory::Structure,
558547
)];
559548
}
560-
}
561-
}
562549
vec![]
563550
}
564551
}

0 commit comments

Comments
 (0)