Skip to content

Commit e90ffa6

Browse files
committed
Set stricter linter rules
1 parent 3ecb52b commit e90ffa6

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

crates/motus/Cargo.toml

+9
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,12 @@ clap = {version = "4.3.11", features = ["derive"]}
1515
itertools = "0.11.0"
1616
lazy_static = "1.4.0"
1717
rand = "0.8.5"
18+
19+
[lints.rust]
20+
unsafe_code = "forbid"
21+
22+
[lints.clippy]
23+
enum_glob_use = "deny"
24+
pedantic = "deny"
25+
nursery = "deny"
26+
unwrap_used = "deny"

crates/motus/src/lib.rs

+16-9
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ lazy_static! {
5151
/// println!("Generated password: {}", password);
5252
/// ```
5353
///
54+
/// # Panics
55+
///
56+
/// The function may panic in the event a word from the list the crate embeds were to contain
57+
/// non-UTF-8 characters.
58+
///
5459
/// # Returns
5560
///
5661
/// A `String` containing the generated memorable password
@@ -64,16 +69,15 @@ pub fn memorable_password<R: Rng>(
6469
) -> String {
6570
// Get the random words and format them
6671
let formatted_words: Vec<String> = get_random_words(rng, word_count)
67-
.iter()
72+
.into_iter()
6873
.map(|word| {
6974
let mut word = word.to_string();
7075

7176
// Scramble the word if requested
7277
if scramble {
7378
let mut bytes = word.to_string().into_bytes();
7479
bytes.shuffle(rng);
75-
word =
76-
String::from_utf8(bytes.to_vec()).expect("random words should be valid UTF-8");
80+
word = String::from_utf8(bytes).expect("random words should be valid UTF-8");
7781
}
7882

7983
// Capitalize the word if requested
@@ -95,18 +99,18 @@ pub fn memorable_password<R: Rng>(
9599
Separator::Underscore => formatted_words.join("_"),
96100
Separator::Numbers => formatted_words
97101
.iter()
98-
.map(|s| s.to_string())
102+
.map(String::to_string)
99103
.intersperse_with(|| rng.gen_range(0..10).to_string())
100104
.collect(),
101105
Separator::NumbersAndSymbols => {
102106
let numbers_and_symbols: Vec<char> = SYMBOL_CHARS
103107
.iter()
104108
.chain(NUMBER_CHARS.iter())
105-
.cloned()
109+
.copied()
106110
.collect();
107111
formatted_words
108112
.iter()
109-
.map(|s| s.to_string())
113+
.map(String::to_string)
110114
.intersperse_with(|| {
111115
numbers_and_symbols
112116
.choose(rng)
@@ -156,6 +160,10 @@ pub enum Separator {
156160
/// * `numbers: bool` - A flag indicating whether numbers should be included in the password
157161
/// * `symbols: bool` - A flag indicating whether symbols should be included in the password
158162
///
163+
/// # Panics
164+
///
165+
/// The function may panic in the event that the provided `characters` argument is 0.
166+
///
159167
/// # Returns
160168
///
161169
/// * `String` - The generated random password
@@ -193,8 +201,7 @@ pub fn random_password<R: Rng>(
193201

194202
// If either numbers or symbols is true, but not the other, we want
195203
// to make sure that we apply the following distribution: 80% letters, 20% numbers.
196-
(true, false) => vec![8, 2],
197-
(false, true) => vec![8, 2],
204+
(true, false) | (false, true) => vec![8, 2],
198205

199206
// Otherwise we want to make sure that we apply the following distribution: 100% letters.
200207
(false, false) => vec![10],
@@ -260,7 +267,7 @@ const SYMBOL_CHARS: &[char] = &['!', '@', '#', '$', '%', '^', '&', '*', '(', ')'
260267

261268
// get_random_words returns a vector of n random words from the word list
262269
fn get_random_words<R: Rng>(rng: &mut R, n: usize) -> Vec<&'static str> {
263-
WORDS_LIST.choose_multiple(rng, n).cloned().collect()
270+
WORDS_LIST.choose_multiple(rng, n).copied().collect()
264271
}
265272

266273
#[cfg(test)]

0 commit comments

Comments
 (0)