Skip to content

Commit 7a17f11

Browse files
authored
Merge pull request #153 from tgross35/clippy-ci
Run clippy checks in CI
2 parents d6cac97 + 56619ab commit 7a17f11

File tree

2 files changed

+67
-40
lines changed

2 files changed

+67
-40
lines changed

.github/workflows/rust.yml

+23
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
name: CI
22

3+
env:
4+
CARGO_TERM_VERBOSE: true
5+
RUSTDOCFLAGS: -Dwarnings
6+
RUSTFLAGS: -Dwarnings
7+
38
on:
49
pull_request:
510
push:
@@ -36,6 +41,23 @@ jobs:
3641
3742
- run: cargo test --all
3843

44+
clippy:
45+
name: Clippy
46+
runs-on: ubuntu-24.04
47+
steps:
48+
- name: Checkout repository
49+
uses: actions/checkout@v4
50+
51+
- name: Update rust
52+
run: |
53+
# use beta since it gives us near-latest fixes but isn't as volatile as nightly
54+
rustup default beta
55+
rustup component add clippy
56+
rustup update --no-self-update
57+
58+
# FIXME(msrv): suggestions do not work in 1.23, nor dows `#![allow(clippy::...)]`
59+
- run: cargo clippy --all -- -Aclippy::while_let_loop
60+
3961
msrv:
4062
name: Check building with the MSRV
4163
runs-on: ubuntu-24.04
@@ -65,6 +87,7 @@ jobs:
6587
success:
6688
needs:
6789
- test
90+
- clippy
6891
- msrv
6992
- rustfmt
7093
runs-on: ubuntu-latest

src/lib.rs

+44-40
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ extern crate doc_comment;
7070
doctest!("../README.md");
7171

7272
use std::cmp;
73+
use std::cmp::Ordering;
7374
use std::error::Error;
7475
use std::fmt;
7576
use std::fs;
@@ -620,52 +621,56 @@ impl Pattern {
620621

621622
let count = i - old;
622623

623-
if count > 2 {
624-
return Err(PatternError {
625-
pos: old + 2,
626-
msg: ERROR_WILDCARDS,
627-
});
628-
} else if count == 2 {
629-
// ** can only be an entire path component
630-
// i.e. a/**/b is valid, but a**/b or a/**b is not
631-
// invalid matches are treated literally
632-
let is_valid = if i == 2 || path::is_separator(chars[i - count - 1]) {
633-
// it ends in a '/'
634-
if i < chars.len() && path::is_separator(chars[i]) {
635-
i += 1;
636-
true
637-
// or the pattern ends here
638-
// this enables the existing globbing mechanism
639-
} else if i == chars.len() {
640-
true
641-
// `**` ends in non-separator
624+
match count.cmp(&2) {
625+
Ordering::Greater => {
626+
return Err(PatternError {
627+
pos: old + 2,
628+
msg: ERROR_WILDCARDS,
629+
})
630+
}
631+
Ordering::Equal => {
632+
// ** can only be an entire path component
633+
// i.e. a/**/b is valid, but a**/b or a/**b is not
634+
// invalid matches are treated literally
635+
let is_valid = if i == 2 || path::is_separator(chars[i - count - 1]) {
636+
// it ends in a '/'
637+
if i < chars.len() && path::is_separator(chars[i]) {
638+
i += 1;
639+
true
640+
// or the pattern ends here
641+
// this enables the existing globbing mechanism
642+
} else if i == chars.len() {
643+
true
644+
// `**` ends in non-separator
645+
} else {
646+
return Err(PatternError {
647+
pos: i,
648+
msg: ERROR_RECURSIVE_WILDCARDS,
649+
});
650+
}
651+
// `**` begins with non-separator
642652
} else {
643653
return Err(PatternError {
644-
pos: i,
654+
pos: old - 1,
645655
msg: ERROR_RECURSIVE_WILDCARDS,
646656
});
647-
}
648-
// `**` begins with non-separator
649-
} else {
650-
return Err(PatternError {
651-
pos: old - 1,
652-
msg: ERROR_RECURSIVE_WILDCARDS,
653-
});
654-
};
657+
};
655658

656-
if is_valid {
657-
// collapse consecutive AnyRecursiveSequence to a
658-
// single one
659+
if is_valid {
660+
// collapse consecutive AnyRecursiveSequence to a
661+
// single one
659662

660-
let tokens_len = tokens.len();
663+
let tokens_len = tokens.len();
661664

662-
if !(tokens_len > 1 && tokens[tokens_len - 1] == AnyRecursiveSequence) {
663-
is_recursive = true;
664-
tokens.push(AnyRecursiveSequence);
665+
if !(tokens_len > 1
666+
&& tokens[tokens_len - 1] == AnyRecursiveSequence)
667+
{
668+
is_recursive = true;
669+
tokens.push(AnyRecursiveSequence);
670+
}
665671
}
666672
}
667-
} else {
668-
tokens.push(AnySequence);
673+
Ordering::Less => tokens.push(AnySequence),
669674
}
670675
}
671676
'[' => {
@@ -1029,7 +1034,7 @@ fn chars_eq(a: char, b: char, case_sensitive: bool) -> bool {
10291034
true
10301035
} else if !case_sensitive && a.is_ascii() && b.is_ascii() {
10311036
// FIXME: work with non-ascii chars properly (issue #9084)
1032-
a.to_ascii_lowercase() == b.to_ascii_lowercase()
1037+
a.eq_ignore_ascii_case(&b)
10331038
} else {
10341039
a == b
10351040
}
@@ -1166,8 +1171,7 @@ mod test {
11661171
.ok()
11671172
.and_then(|p| match p.components().next().unwrap() {
11681173
Component::Prefix(prefix_component) => {
1169-
let path = Path::new(prefix_component.as_os_str());
1170-
path.join("*");
1174+
let path = Path::new(prefix_component.as_os_str()).join("*");
11711175
Some(path.to_path_buf())
11721176
}
11731177
_ => panic!("no prefix in this path"),

0 commit comments

Comments
 (0)