Skip to content

Commit 58a06a4

Browse files
atezetspenserblack
authored andcommitted
Apply some (pedantic) clippy lints
1 parent e55e26c commit 58a06a4

File tree

5 files changed

+49
-60
lines changed

5 files changed

+49
-60
lines changed

examples/control.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use colored::*;
44

55
#[cfg(not(windows))]
66
fn main() {
7-
both()
7+
both();
88
}
99

1010
#[cfg(windows)]

src/color.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,11 @@ impl Color {
8585
}
8686

8787
/// Gets the closest plain color to the TrueColor
88-
fn closest_color_euclidean(&self) -> Self {
88+
fn closest_color_euclidean(self) -> Self {
8989
use std::cmp;
9090
use Color::*;
9191

92-
match *self {
92+
match self {
9393
TrueColor {
9494
r: r1,
9595
g: g1,
@@ -332,13 +332,13 @@ mod tests {
332332
#[test]
333333
fn parse() {
334334
let color: Result<Color, _> = "blue".parse();
335-
assert_eq!(Ok(Color::Blue), color)
335+
assert_eq!(Ok(Color::Blue), color);
336336
}
337337

338338
#[test]
339339
fn error() {
340340
let color: Result<Color, ()> = "bloublou".parse();
341-
assert_eq!(Err(()), color)
341+
assert_eq!(Err(()), color);
342342
}
343343
}
344344

src/control.rs

+16-27
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,13 @@ pub struct ShouldColorize {
6969
/// Use this to force colored to ignore the environment and always/never colorize
7070
/// See example/control.rs
7171
pub fn set_override(override_colorize: bool) {
72-
SHOULD_COLORIZE.set_override(override_colorize)
72+
SHOULD_COLORIZE.set_override(override_colorize);
7373
}
7474

7575
/// Remove the manual override and let the environment decide if it's ok to colorize
7676
/// See example/control.rs
7777
pub fn unset_override() {
78-
SHOULD_COLORIZE.unset_override()
78+
SHOULD_COLORIZE.unset_override();
7979
}
8080

8181
lazy_static! {
@@ -177,7 +177,7 @@ mod specs {
177177
assert_eq!(
178178
None,
179179
ShouldColorize::normalize_env(Err(env::VarError::NotUnicode("".into())))
180-
)
180+
);
181181
});
182182

183183
ctx.it("should return Some(true) if != 0", |_| {
@@ -281,19 +281,19 @@ mod specs {
281281
clicolor: false,
282282
..ShouldColorize::default()
283283
};
284-
false == colorize_control.should_colorize()
284+
!colorize_control.should_colorize()
285285
});
286286

287287
ctx.it("clicolor == true means colors !", |_| {
288288
let colorize_control = ShouldColorize {
289289
clicolor: true,
290290
..ShouldColorize::default()
291291
};
292-
true == colorize_control.should_colorize()
292+
colorize_control.should_colorize()
293293
});
294294

295295
ctx.it("unset clicolors implies true", |_| {
296-
true == ShouldColorize::default().should_colorize()
296+
ShouldColorize::default().should_colorize()
297297
});
298298
});
299299

@@ -307,7 +307,7 @@ mod specs {
307307
..ShouldColorize::default()
308308
};
309309

310-
true == colorize_control.should_colorize()
310+
colorize_control.should_colorize()
311311
},
312312
);
313313

@@ -320,7 +320,7 @@ mod specs {
320320
..ShouldColorize::default()
321321
};
322322

323-
false == colorize_control.should_colorize()
323+
!colorize_control.should_colorize()
324324
},
325325
);
326326
});
@@ -332,10 +332,9 @@ mod specs {
332332
clicolor_force: None,
333333
has_manual_override: AtomicBool::new(true),
334334
manual_override: AtomicBool::new(true),
335-
.. ShouldColorize::default()
336335
};
337336

338-
true == colorize_control.should_colorize()
337+
colorize_control.should_colorize();
339338
});
340339

341340
ctx.it("should not colorize if manual_override is false, but clicolor is true or clicolor_force is true", |_| {
@@ -344,11 +343,10 @@ mod specs {
344343
clicolor_force: Some(true),
345344
has_manual_override: AtomicBool::new(true),
346345
manual_override: AtomicBool::new(false),
347-
.. ShouldColorize::default()
348346
};
349347

350-
false == colorize_control.should_colorize()
351-
})
348+
!colorize_control.should_colorize()
349+
});
352350
});
353351

354352
ctx.specify("::set_override", |ctx| {
@@ -361,21 +359,15 @@ mod specs {
361359
let colorize_control = ShouldColorize::default();
362360
colorize_control.set_override(true);
363361
{
364-
assert_eq!(
365-
true,
366-
colorize_control.has_manual_override.load(Ordering::Relaxed)
367-
);
362+
assert!(colorize_control.has_manual_override.load(Ordering::Relaxed));
368363
let val = colorize_control.manual_override.load(Ordering::Relaxed);
369-
assert_eq!(true, val);
364+
assert!(val);
370365
}
371366
colorize_control.set_override(false);
372367
{
373-
assert_eq!(
374-
true,
375-
colorize_control.has_manual_override.load(Ordering::Relaxed)
376-
);
368+
assert!(colorize_control.has_manual_override.load(Ordering::Relaxed));
377369
let val = colorize_control.manual_override.load(Ordering::Relaxed);
378-
assert_eq!(false, val);
370+
assert!(!val);
379371
}
380372
});
381373
});
@@ -390,10 +382,7 @@ mod specs {
390382
let colorize_control = ShouldColorize::default();
391383
colorize_control.set_override(true);
392384
colorize_control.unset_override();
393-
assert_eq!(
394-
false,
395-
colorize_control.has_manual_override.load(Ordering::Relaxed)
396-
);
385+
assert!(!colorize_control.has_manual_override.load(Ordering::Relaxed));
397386
});
398387
});
399388
}));

src/lib.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -490,17 +490,17 @@ impl ColoredString {
490490
}
491491

492492
#[cfg(not(feature = "no-color"))]
493-
fn has_colors(&self) -> bool {
493+
fn has_colors() -> bool {
494494
control::SHOULD_COLORIZE.should_colorize()
495495
}
496496

497497
#[cfg(feature = "no-color")]
498-
fn has_colors(&self) -> bool {
498+
fn has_colors() -> bool {
499499
false
500500
}
501501

502502
fn compute_style(&self) -> String {
503-
if !self.has_colors() || self.is_plain() {
503+
if !ColoredString::has_colors() || self.is_plain() {
504504
return String::new();
505505
}
506506

@@ -534,7 +534,7 @@ impl ColoredString {
534534
}
535535

536536
fn escape_inner_reset_sequences(&self) -> Cow<str> {
537-
if !self.has_colors() || self.is_plain() {
537+
if !ColoredString::has_colors() || self.is_plain() {
538538
return self.input.as_str().into();
539539
}
540540

@@ -713,7 +713,7 @@ impl<'a> Colorize for &'a str {
713713

714714
impl fmt::Display for ColoredString {
715715
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
716-
if !self.has_colors() || self.is_plain() {
716+
if !ColoredString::has_colors() || self.is_plain() {
717717
return <String as fmt::Display>::fmt(&self.input, f);
718718
}
719719

@@ -944,22 +944,22 @@ mod tests {
944944

945945
#[test]
946946
fn color_fn() {
947-
assert_eq!("blue".blue(), "blue".color("blue"))
947+
assert_eq!("blue".blue(), "blue".color("blue"));
948948
}
949949

950950
#[test]
951951
fn on_color_fn() {
952-
assert_eq!("blue".on_blue(), "blue".on_color("blue"))
952+
assert_eq!("blue".on_blue(), "blue".on_color("blue"));
953953
}
954954

955955
#[test]
956956
fn bright_color_fn() {
957-
assert_eq!("blue".bright_blue(), "blue".color("bright blue"))
957+
assert_eq!("blue".bright_blue(), "blue".color("bright blue"));
958958
}
959959

960960
#[test]
961961
fn on_bright_color_fn() {
962-
assert_eq!("blue".on_bright_blue(), "blue".on_color("bright blue"))
962+
assert_eq!("blue".on_bright_blue(), "blue".on_color("bright blue"));
963963
}
964964

965965
#[test]
@@ -981,8 +981,8 @@ mod tests {
981981
let cstring = cstring.bold().italic();
982982
assert_eq!(cstring.fgcolor(), Some(Color::Blue));
983983
assert_eq!(cstring.bgcolor(), Some(Color::BrightYellow));
984-
assert_eq!(cstring.style().contains(Styles::Bold), true);
985-
assert_eq!(cstring.style().contains(Styles::Italic), true);
986-
assert_eq!(cstring.style().contains(Styles::Dimmed), false);
984+
assert!(cstring.style().contains(Styles::Bold));
985+
assert!(cstring.style().contains(Styles::Italic));
986+
assert!(!cstring.style().contains(Styles::Dimmed));
987987
}
988988
}

src/style.rs

+16-16
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ mod tests {
563563

564564
#[test]
565565
fn empty_is_none() {
566-
assert_eq!(None, Styles::from_u8(CLEARV))
566+
assert_eq!(None, Styles::from_u8(CLEARV));
567567
}
568568
}
569569

@@ -632,19 +632,19 @@ mod tests {
632632
#[test]
633633
fn aggreg1() {
634634
let styles: &[Styles] = &[Bold, Bold, Bold];
635-
test_aggreg!(styles, [Bold])
635+
test_aggreg!(styles, [Bold]);
636636
}
637637

638638
#[test]
639639
fn aggreg2() {
640640
let styles: &[Styles] = &[Italic, Italic, Bold, Bold];
641-
test_aggreg!(styles, [Bold, Italic])
641+
test_aggreg!(styles, [Bold, Italic]);
642642
}
643643

644644
#[test]
645645
fn aggreg3() {
646646
let styles: &[Styles] = &[Bold, Italic, Bold];
647-
test_aggreg!(styles, [Bold, Italic])
647+
test_aggreg!(styles, [Bold, Italic]);
648648
}
649649

650650
macro_rules! test_combine {
@@ -658,49 +658,49 @@ mod tests {
658658
#[test]
659659
fn two1() {
660660
let s: &[Styles] = &[Bold, Underline];
661-
test_combine!(s)
661+
test_combine!(s);
662662
}
663663

664664
#[test]
665665
fn two2() {
666666
let s: &[Styles] = &[Underline, Italic];
667-
test_combine!(s)
667+
test_combine!(s);
668668
}
669669

670670
#[test]
671671
fn two3() {
672672
let s: &[Styles] = &[Bold, Italic];
673-
test_combine!(s)
673+
test_combine!(s);
674674
}
675675

676676
#[test]
677677
fn three1() {
678678
let s: &[Styles] = &[Bold, Underline, Italic];
679-
test_combine!(s)
679+
test_combine!(s);
680680
}
681681

682682
#[test]
683683
fn three2() {
684684
let s: &[Styles] = &[Dimmed, Underline, Italic];
685-
test_combine!(s)
685+
test_combine!(s);
686686
}
687687

688688
#[test]
689689
fn four() {
690690
let s: &[Styles] = &[Dimmed, Underline, Italic, Hidden];
691-
test_combine!(s)
691+
test_combine!(s);
692692
}
693693

694694
#[test]
695695
fn five() {
696696
let s: &[Styles] = &[Dimmed, Underline, Italic, Blink, Hidden];
697-
test_combine!(s)
697+
test_combine!(s);
698698
}
699699

700700
#[test]
701701
fn six() {
702702
let s: &[Styles] = &[Bold, Dimmed, Underline, Italic, Blink, Hidden];
703-
test_combine!(s)
703+
test_combine!(s);
704704
}
705705

706706
#[test]
@@ -715,7 +715,7 @@ mod tests {
715715
Hidden,
716716
Strikethrough,
717717
];
718-
test_combine!(s)
718+
test_combine!(s);
719719
}
720720
}
721721

@@ -724,9 +724,9 @@ mod tests {
724724
let mut style = Style(Styles::Bold.to_u8());
725725
style.add(Styles::Italic);
726726

727-
assert_eq!(style.contains(Styles::Bold), true);
728-
assert_eq!(style.contains(Styles::Italic), true);
729-
assert_eq!(style.contains(Styles::Dimmed), false);
727+
assert!(style.contains(Styles::Bold));
728+
assert!(style.contains(Styles::Italic));
729+
assert!(!style.contains(Styles::Dimmed));
730730
}
731731

732732
mod style_bitwise_logic {

0 commit comments

Comments
 (0)