Skip to content

Commit 1d03e95

Browse files
committed
Run clippy on CI
1 parent 144b8b1 commit 1d03e95

File tree

2 files changed

+29
-29
lines changed

2 files changed

+29
-29
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,8 @@ jobs:
3838
- name: Check formatting
3939
run: cargo fmt -- --check
4040

41+
- name: Run clippy
42+
run: cargo clippy
43+
4144
- name: Test
4245
run: cargo test

src/main.rs

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ impl Tree {
7878

7979
fn add_node_at_path(&mut self, node: Node, name: OsString, path: &mut Components<'_>) {
8080
match path.next() {
81-
Some(Component::Normal(ref dir)) => {
82-
dir.to_str().map(|dir| {
81+
Some(Component::Normal(dir)) => {
82+
if let Some(dir) = dir.to_str() {
8383
let new_node = self.children.entry(dir.into()).or_insert(Node::Tree(Tree {
8484
name: dir.into(),
8585
children: BTreeMap::new(),
@@ -88,7 +88,7 @@ impl Tree {
8888
if let &mut Node::Tree(ref mut new_node) = new_node {
8989
new_node.add_node_at_path(node, name, path)
9090
}
91-
});
91+
};
9292
}
9393

9494
Some(_) => unimplemented!(),
@@ -140,9 +140,9 @@ trait Lines {
140140
impl Lines for Node {
141141
fn lines(&self) -> Vec<OsString> {
142142
match self {
143-
&Node::Tree(ref node) => node.lines(),
144-
&Node::Summary(ref node) => node.lines(),
145-
&Node::Leaf(ref node) => node.lines(),
143+
Node::Tree(node) => node.lines(),
144+
Node::Summary(node) => node.lines(),
145+
Node::Leaf(node) => node.lines(),
146146
}
147147
}
148148
}
@@ -170,7 +170,7 @@ impl Lines for Tree {
170170
.collect::<Vec<_>>(),
171171
);
172172

173-
if let Some(&last) = last.get(0) {
173+
if let Some(&last) = last.first() {
174174
// The last child’s first line gets prepended by "└── ".
175175
// All following lines get prepended by " ".
176176
lines.extend(self.prepend_first_and_rest(last.lines(), "└── ".into(), " ".into()));
@@ -236,7 +236,7 @@ impl Lines for Leaf {
236236
impl fmt::Display for Node {
237237
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
238238
for l in self.lines() {
239-
write!(f, "{}\n", l.as_os_str().to_string_lossy())?;
239+
writeln!(f, "{}", l.as_os_str().to_string_lossy())?;
240240
}
241241

242242
Ok(())
@@ -245,9 +245,9 @@ impl fmt::Display for Node {
245245

246246
fn walk_repository(repo: &Repository, name: &OsStr, args: &Args) -> Result<Option<Node>> {
247247
if args.summary {
248-
walk_summary(&repo, name, &args)
248+
walk_summary(repo, name, args)
249249
} else {
250-
walk_entries(&repo, name, &args)
250+
walk_entries(repo, name, args)
251251
}
252252
}
253253

@@ -267,27 +267,24 @@ fn walk_entries(repo: &Repository, name: &OsStr, args: &Args) -> Result<Option<N
267267
.ok_or(anyhow!("{:?} cannot be resolved to a path", entry.path()))?,
268268
);
269269

270-
let file_name = file_name(&path);
270+
let file_name = file_name(path);
271271

272272
let leaf = Leaf {
273273
name: file_name.into(),
274274
status: entry.status(),
275275
};
276276

277-
entry
278-
.path()
279-
.and_then(|path| Path::new(path).parent())
280-
.map(|parent| {
281-
root.add_leaf_at_path(leaf, &mut parent.components());
282-
});
277+
if let Some(parent) = entry.path().and_then(|path| Path::new(path).parent()) {
278+
root.add_leaf_at_path(leaf, &mut parent.components());
279+
}
283280
}
284281
}
285282

286283
Ok(Some(Node::Tree(root)))
287284
}
288285

289286
fn file_name(path: &Path) -> &OsStr {
290-
path.file_name().unwrap_or_else(|| path.as_os_str())
287+
path.file_name().unwrap_or(path.as_os_str())
291288
}
292289

293290
fn walk_summary(repo: &Repository, name: &OsStr, args: &Args) -> Result<Option<Node>> {
@@ -299,10 +296,10 @@ fn walk_summary(repo: &Repository, name: &OsStr, args: &Args) -> Result<Option<N
299296

300297
let summary = Summary {
301298
name: name.into(),
302-
stats: stats,
299+
stats,
303300
};
304301

305-
return Ok(Some(Node::Summary(summary)));
302+
Ok(Some(Node::Summary(summary)))
306303
}
307304

308305
fn walk_directory(path: &Path, iter: ReadDir, depth: usize, args: &Args) -> Result<Node> {
@@ -315,8 +312,8 @@ fn walk_directory(path: &Path, iter: ReadDir, depth: usize, args: &Args) -> Resu
315312

316313
let new_entries = directories
317314
.iter()
318-
.filter_map(|ref entry| {
319-
walk_path(&entry.path(), depth - 1, &args)
315+
.filter_map(|entry| {
316+
walk_path(&entry.path(), depth - 1, args)
320317
.ok()
321318
.and_then(|child| child.map(|child| (child, entry.file_name())))
322319
})
@@ -331,16 +328,16 @@ fn walk_directory(path: &Path, iter: ReadDir, depth: usize, args: &Args) -> Resu
331328

332329
fn walk_path(path: &Path, depth: usize, args: &Args) -> Result<Option<Node>> {
333330
if path.is_dir() {
334-
match Repository::open(&path) {
331+
match Repository::open(path) {
335332
Ok(repo) => {
336-
let node = walk_repository(&repo, file_name(path), &args)?;
333+
let node = walk_repository(&repo, file_name(path), args)?;
337334

338335
Ok(node)
339336
}
340337

341338
_ => {
342339
if depth > 0 {
343-
let node = walk_directory(&path, path.read_dir()?, depth, &args)?;
340+
let node = walk_directory(path, path.read_dir()?, depth, args)?;
344341

345342
Ok(Some(node))
346343
} else {
@@ -354,7 +351,7 @@ fn walk_path(path: &Path, depth: usize, args: &Args) -> Result<Option<Node>> {
354351
}
355352

356353
fn fallback(path: &Path, args: &Args) -> Result<Option<Node>> {
357-
let repo = match Repository::discover(&path) {
354+
let repo = match Repository::discover(path) {
358355
Err(ref error)
359356
if (error.class() == git2::ErrorClass::Repository
360357
&& error.code() == git2::ErrorCode::NotFound) =>
@@ -369,7 +366,7 @@ fn fallback(path: &Path, args: &Args) -> Result<Option<Node>> {
369366
otherwise => otherwise?,
370367
};
371368

372-
walk_repository(&repo, file_name(path), &args)
369+
walk_repository(&repo, file_name(path), args)
373370
}
374371

375372
#[derive(Parser, Debug)]
@@ -409,9 +406,9 @@ fn run() -> Result<()> {
409406

410407
let path = Path::new(".");
411408

412-
let node = match walk_path(&path, args.depth, &args)? {
409+
let node = match walk_path(path, args.depth, &args)? {
413410
node @ Some(_) => node,
414-
None => fallback(&path, &args)?,
411+
None => fallback(path, &args)?,
415412
};
416413

417414
match node {

0 commit comments

Comments
 (0)