mfontanini / presenterm

A markdown terminal slideshow tool
https://mfontanini.github.io/presenterm/
BSD 2-Clause "Simplified" License
1.19k stars 29 forks source link

refactor: fix all clippy warnings #231

Closed mikavilpas closed 5 months ago

mikavilpas commented 6 months ago

The warnings became visible in rust-analyzer. I could also see the warnings on the command line by executing

cargo clippy --all-targets

I fixed all the warnings using rust-analyzer's LSP code actions.

The full list of warnings:

Details

```rust Checking presenterm v0.7.0 (/Users/mikavilpas/git/presenterm) warning: this expression creates a reference which is immediately dereferenced by the compiler --> src/input/user.rs:535:43 | 535 | let result = binding.match_events(&events); | ^^^^^^^ help: change this to: `events` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow = note: `#[warn(clippy::needless_borrow)]` on by default warning: explicit call to `.into_iter()` in function argument accepting `IntoIterator` --> src/presentation.rs:260:86 | 260 | self.chunks.into_iter().flat_map(|chunk| chunk.operations.into_iter()).chain(self.footer.into_iter()).collect() | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing the `.into_iter()`: `self.footer` | note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()` --> /private/tmp/rust-20240215-5649-scngkd/rustc-1.76.0-src/library/core/src/iter/traits/iterator.rs:524:12 = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_conversion = note: `#[warn(clippy::useless_conversion)]` on by default warning: useless conversion to the same type: `presentation::SlideChunk` --> src/presentation.rs:656:29 | 656 | Slide::new(vec![SlideChunk::from(SlideChunk::default()), SlideChunk::default()], vec![]), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `SlideChunk::from()`: `SlideChunk::default()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_conversion warning: useless conversion to the same type: `presentation::SlideChunk` --> src/presentation.rs:657:29 | 657 | Slide::new(vec![SlideChunk::from(SlideChunk::default()), SlideChunk::default()], vec![]), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `SlideChunk::from()`: `SlideChunk::default()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_conversion warning: useless conversion to the same type: `presentation::SlideChunk` --> src/presentation.rs:658:29 | 658 | Slide::new(vec![SlideChunk::from(SlideChunk::default()), SlideChunk::default()], vec![]), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `SlideChunk::from()`: `SlideChunk::default()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_conversion warning: useless conversion to the same type: `presentation::SlideChunk` --> src/presentation.rs:695:21 | 695 | / SlideChunk::from(SlideChunk::new( 696 | | vec![], 697 | | vec![Box::new(DummyMutator::new(1)), Box::new(DummyMutator::new(2))], 698 | | )), | |______________________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_conversion help: consider removing `SlideChunk::from()` | 695 ~ SlideChunk::new( 696 + vec![], 697 + vec![Box::new(DummyMutator::new(1)), Box::new(DummyMutator::new(2))], 698 ~ ), | warning: useless conversion to the same type: `presentation::SlideChunk` --> src/presentation.rs:704:21 | 704 | SlideChunk::from(SlideChunk::new(vec![], vec![Box::new(DummyMutator::new(2))])), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `SlideChunk::from()`: `SlideChunk::new(vec![], vec![Box::new(DummyMutator::new(2))])` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_conversion warning: redundant closure --> src/processing/builder.rs:1116:77 | 1116 | let operations: Vec<_> = slide.into_operations().into_iter().filter(|op| is_visible(op)).collect(); | ^^^^^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `is_visible` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure = note: `#[warn(clippy::redundant_closure)]` on by default warning: useless conversion to the same type: `impl std::iter::Iterator` --> src/processing/builder.rs:1129:31 | 1129 | for (index, slide) in presentation.iter_slides().into_iter().enumerate() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `presentation.iter_slides()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_conversion warning: called `skip(..).next()` on an iterator --> src/processing/builder.rs:1420:48 | 1420 | let second = presentation.iter_slides().skip(1).next().unwrap(); | ^^^^^^^^^^^^^^^ help: use `nth` instead: `.nth(1)` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#iter_skip_next = note: `#[warn(clippy::iter_skip_next)]` on by default warning: the borrowed expression implements the required traits --> src/render/highlighting.rs:293:60 | 293 | fs::write(directory.path().join("potato.tmTheme"), &theme).expect("writing theme"); | ^^^^^^ help: change this to: `theme` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args = note: `#[warn(clippy::needless_borrows_for_generic_args)]` on by default warning: the borrowed expression implements the required traits --> src/theme.rs:564:57 | 564 | fs::write(directory.path().join("potato.yaml"), &theme).expect("writing theme"); | ^^^^^^ help: change this to: `theme` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args warning: `presenterm` (lib test) generated 12 warnings (run `cargo clippy --fix --lib -p presenterm --tests` to apply 12 suggestions) Finished dev [unoptimized + debuginfo] target(s) in 2.73s ```


I have to admit I'm not experienced with rust and I don't quite understand why all the warnings were not visible with cargo clippy. Could there be some weirdness in the project configuration / build system?

mfontanini commented 5 months ago

Thanks!