Skip to content

Commit 5460458

Browse files
committed
refactor: cargo fmt
1 parent f91622e commit 5460458

File tree

15 files changed

+96
-117
lines changed

15 files changed

+96
-117
lines changed

ci/tests/test_cli.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
// CLI tests placeholder - currently no tests implemented
1+
// CLI tests placeholder - currently no tests implemented

codeinput/src/benches/owner_resolver_bench.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use codeinput::core::owner_resolver::{find_files_for_owner, find_owners_for_file};
22
use codeinput::core::types::{CodeownersEntry, FileEntry, Owner, OwnerType, Tag};
3-
use criterion::{Criterion, criterion_group, criterion_main};
3+
use criterion::{criterion_group, criterion_main, Criterion};
44
use std::hint::black_box;
55
use std::path::{Path, PathBuf};
66

codeinput/src/benches/parser_bench.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use codeinput::core::parser::{parse_codeowners, parse_line, parse_owner};
2-
use criterion::{Criterion, criterion_group, criterion_main};
2+
use criterion::{criterion_group, criterion_main, Criterion};
33
use std::hint::black_box;
44
use std::io::Write;
55
use std::path::Path;
@@ -337,4 +337,3 @@ criterion_group!(
337337
bench_parse_owner_unknown
338338
);
339339
criterion_main!(benches);
340-

codeinput/src/benches/resolver_bench.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use codeinput::core::resolver::find_owners_and_tags_for_file;
22
use codeinput::core::types::{
3-
CodeownersEntry, CodeownersEntryMatcher, Owner, OwnerType, Tag, codeowners_entry_to_matcher,
3+
codeowners_entry_to_matcher, CodeownersEntry, CodeownersEntryMatcher, Owner, OwnerType, Tag,
44
};
5-
use criterion::{Criterion, criterion_group, criterion_main};
5+
use criterion::{criterion_group, criterion_main, Criterion};
66
use std::hint::black_box;
77
use std::path::{Path, PathBuf};
88

codeinput/src/benches/tag_resolver_bench.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use codeinput::core::tag_resolver::{find_files_for_tag, find_tags_for_file};
22
use codeinput::core::types::{CodeownersEntry, FileEntry, Owner, OwnerType, Tag};
3-
use criterion::{Criterion, criterion_group, criterion_main};
3+
use criterion::{criterion_group, criterion_main, Criterion};
44
use std::hint::black_box;
55
use std::path::{Path, PathBuf};
66

codeinput/src/core/cache.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use crate::{
44
parse::parse_repo,
55
resolver::find_owners_and_tags_for_file,
66
types::{
7-
CacheEncoding, CodeownersCache, CodeownersEntry, CodeownersEntryMatcher, FileEntry,
8-
codeowners_entry_to_matcher,
7+
codeowners_entry_to_matcher, CacheEncoding, CodeownersCache, CodeownersEntry,
8+
CodeownersEntryMatcher, FileEntry,
99
},
1010
},
1111
utils::error::{Error, Result},

codeinput/src/core/commands/list_tags.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,3 @@ pub fn run(
112112

113113
Ok(())
114114
}
115-

codeinput/src/core/common.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -143,16 +143,12 @@ mod tests {
143143

144144
// Verify results
145145
assert_eq!(found_files.len(), 2);
146-
assert!(
147-
found_files
148-
.iter()
149-
.any(|p| p == &base_path.join("CODEOWNERS"))
150-
);
151-
assert!(
152-
found_files
153-
.iter()
154-
.any(|p| p == &nested_dir.join("CODEOWNERS"))
155-
);
146+
assert!(found_files
147+
.iter()
148+
.any(|p| p == &base_path.join("CODEOWNERS")));
149+
assert!(found_files
150+
.iter()
151+
.any(|p| p == &nested_dir.join("CODEOWNERS")));
156152

157153
Ok(())
158154
}

codeinput/src/core/inline_parser.rs

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use crate::utils::error::Result;
2-
use std::path::Path;
3-
use std::io::{BufRead, BufReader};
42
use std::fs::File;
3+
use std::io::{BufRead, BufReader};
4+
use std::path::Path;
55

6-
use super::types::{InlineCodeownersEntry, Owner, Tag};
76
use super::parser::parse_owner;
7+
use super::types::{InlineCodeownersEntry, Owner, Tag};
88

99
/// Detects inline CODEOWNERS declaration in the first 50 lines of a file
1010
pub fn detect_inline_codeowners(file_path: &Path) -> Result<Option<InlineCodeownersEntry>> {
@@ -32,18 +32,16 @@ pub fn detect_inline_codeowners(file_path: &Path) -> Result<Option<InlineCodeown
3232

3333
/// Parse a single line for inline CODEOWNERS declaration
3434
fn parse_inline_codeowners_line(
35-
line: &str,
36-
line_number: usize,
37-
file_path: &Path,
35+
line: &str, line_number: usize, file_path: &Path,
3836
) -> Result<Option<InlineCodeownersEntry>> {
3937
// Look for !!!CODEOWNERS marker
4038
if let Some(marker_pos) = line.find("!!!CODEOWNERS") {
4139
// Extract everything after the marker
4240
let after_marker = &line[marker_pos + "!!!CODEOWNERS".len()..];
43-
41+
4442
// Split by whitespace to get tokens
4543
let tokens: Vec<&str> = after_marker.split_whitespace().collect();
46-
44+
4745
if tokens.is_empty() {
4846
return Ok(None);
4947
}
@@ -68,16 +66,20 @@ fn parse_inline_codeowners_line(
6866
} else {
6967
// Extract tag name, but check if this might be a comment
7068
let tag_part = &token[1..];
71-
69+
7270
// If the tag part is empty, it's probably a comment marker
7371
if tag_part.is_empty() {
7472
break;
7573
}
76-
74+
7775
// Special handling for common comment patterns
7876
// If the next token looks like end of comment (like "-->"), still treat as tag
79-
let next_token = if i + 1 < tokens.len() { Some(tokens[i + 1]) } else { None };
80-
77+
let next_token = if i + 1 < tokens.len() {
78+
Some(tokens[i + 1])
79+
} else {
80+
None
81+
};
82+
8183
match next_token {
8284
Some("-->") | Some("*/") => {
8385
// This is likely the end of a comment block, so the tag is valid
@@ -97,7 +99,10 @@ fn parse_inline_codeowners_line(
9799
// Next token doesn't start with # and isn't a comment ender
98100
// This could be a comment, but we'll be conservative and treat as tag
99101
// if it looks like a valid tag name (alphanumeric + common chars)
100-
if tag_part.chars().all(|c| c.is_alphanumeric() || c == '-' || c == '_') {
102+
if tag_part
103+
.chars()
104+
.all(|c| c.is_alphanumeric() || c == '-' || c == '_')
105+
{
101106
tags.push(Tag(tag_part.to_string()));
102107
#[allow(unused_assignments)]
103108
{
@@ -145,7 +150,7 @@ mod tests {
145150
fn test_detect_inline_codeowners_rust_comment() -> Result<()> {
146151
let temp_dir = TempDir::new().unwrap();
147152
let file_path = temp_dir.path().join("test.rs");
148-
153+
149154
let content = r#"// This is a Rust file
150155
// !!!CODEOWNERS @user1 @org/team2 #tag1 #tag2
151156
fn main() {
@@ -156,7 +161,7 @@ fn main() {
156161

157162
let result = detect_inline_codeowners(&file_path)?;
158163
assert!(result.is_some());
159-
164+
160165
let entry = result.unwrap();
161166
assert_eq!(entry.file_path, file_path);
162167
assert_eq!(entry.line_number, 2);
@@ -174,7 +179,7 @@ fn main() {
174179
fn test_detect_inline_codeowners_javascript_comment() -> Result<()> {
175180
let temp_dir = TempDir::new().unwrap();
176181
let file_path = temp_dir.path().join("test.js");
177-
182+
178183
let content = r#"/*
179184
* !!!CODEOWNERS @frontend-team #javascript
180185
*/
@@ -186,7 +191,7 @@ function hello() {
186191

187192
let result = detect_inline_codeowners(&file_path)?;
188193
assert!(result.is_some());
189-
194+
190195
let entry = result.unwrap();
191196
assert_eq!(entry.owners.len(), 1);
192197
assert_eq!(entry.owners[0].identifier, "@frontend-team");
@@ -200,7 +205,7 @@ function hello() {
200205
fn test_detect_inline_codeowners_python_comment() -> Result<()> {
201206
let temp_dir = TempDir::new().unwrap();
202207
let file_path = temp_dir.path().join("test.py");
203-
208+
204209
let content = r#"#!/usr/bin/env python3
205210
# !!!CODEOWNERS @python-team @user1 #backend #critical
206211
"""
@@ -214,7 +219,7 @@ def main():
214219

215220
let result = detect_inline_codeowners(&file_path)?;
216221
assert!(result.is_some());
217-
222+
218223
let entry = result.unwrap();
219224
assert_eq!(entry.line_number, 2);
220225
assert_eq!(entry.owners.len(), 2);
@@ -231,7 +236,7 @@ def main():
231236
fn test_detect_inline_codeowners_html_comment() -> Result<()> {
232237
let temp_dir = TempDir::new().unwrap();
233238
let file_path = temp_dir.path().join("test.html");
234-
239+
235240
let content = r#"<!DOCTYPE html>
236241
<html>
237242
<!-- !!!CODEOWNERS @web-team #frontend -->
@@ -244,7 +249,7 @@ def main():
244249

245250
let result = detect_inline_codeowners(&file_path)?;
246251
assert!(result.is_some());
247-
252+
248253
let entry = result.unwrap();
249254
assert_eq!(entry.owners.len(), 1);
250255
assert_eq!(entry.owners[0].identifier, "@web-team");
@@ -258,7 +263,7 @@ def main():
258263
fn test_detect_inline_codeowners_no_marker() -> Result<()> {
259264
let temp_dir = TempDir::new().unwrap();
260265
let file_path = temp_dir.path().join("test.rs");
261-
266+
262267
let content = r#"// This is a regular file
263268
fn main() {
264269
println!("No CODEOWNERS marker here");
@@ -276,7 +281,7 @@ fn main() {
276281
fn test_detect_inline_codeowners_no_owners() -> Result<()> {
277282
let temp_dir = TempDir::new().unwrap();
278283
let file_path = temp_dir.path().join("test.rs");
279-
284+
280285
let content = r#"// !!!CODEOWNERS #just-tags
281286
fn main() {
282287
println!("Only tags, no owners");
@@ -294,7 +299,7 @@ fn main() {
294299
fn test_detect_inline_codeowners_first_occurrence_only() -> Result<()> {
295300
let temp_dir = TempDir::new().unwrap();
296301
let file_path = temp_dir.path().join("test.rs");
297-
302+
298303
let content = r#"// !!!CODEOWNERS @first-owner #first-tag
299304
fn main() {
300305
// !!!CODEOWNERS @second-owner #second-tag
@@ -305,7 +310,7 @@ fn main() {
305310

306311
let result = detect_inline_codeowners(&file_path)?;
307312
assert!(result.is_some());
308-
313+
309314
let entry = result.unwrap();
310315
assert_eq!(entry.line_number, 1);
311316
assert_eq!(entry.owners[0].identifier, "@first-owner");
@@ -318,15 +323,15 @@ fn main() {
318323
fn test_detect_inline_codeowners_beyond_50_lines() -> Result<()> {
319324
let temp_dir = TempDir::new().unwrap();
320325
let file_path = temp_dir.path().join("test.rs");
321-
326+
322327
let mut content = String::new();
323328
// Add 51 lines, with the marker on line 51
324329
for i in 1..=50 {
325330
content.push_str(&format!("// Line {}\n", i));
326331
}
327332
content.push_str("// !!!CODEOWNERS @should-not-be-found #beyond-limit\n");
328333
content.push_str("fn main() {}\n");
329-
334+
330335
fs::write(&file_path, content).unwrap();
331336

332337
let result = detect_inline_codeowners(&file_path)?;
@@ -339,15 +344,15 @@ fn main() {
339344
fn test_detect_inline_codeowners_with_comment_after() -> Result<()> {
340345
let temp_dir = TempDir::new().unwrap();
341346
let file_path = temp_dir.path().join("test.rs");
342-
347+
343348
let content = r#"// !!!CODEOWNERS @user1 #tag1 # this is a comment after
344349
fn main() {}
345350
"#;
346351
fs::write(&file_path, content).unwrap();
347352

348353
let result = detect_inline_codeowners(&file_path)?;
349354
assert!(result.is_some());
350-
355+
351356
let entry = result.unwrap();
352357
assert_eq!(entry.owners.len(), 1);
353358
assert_eq!(entry.owners[0].identifier, "@user1");
@@ -367,5 +372,4 @@ fn main() {}
367372

368373
Ok(())
369374
}
370-
371-
}
375+
}

codeinput/src/core/owner_resolver.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,11 @@ pub fn find_owners_for_file<'a>(
8282
over.matched(file_path, false).is_whitelist()
8383
};
8484

85-
if matches { Some((entry, depth)) } else { None }
85+
if matches {
86+
Some((entry, depth))
87+
} else {
88+
None
89+
}
8690
})
8791
.collect();
8892

0 commit comments

Comments
 (0)