From 5208225a67f4613a08984e3f2bc869347ca914c6 Mon Sep 17 00:00:00 2001 From: Uwe Klotz Date: Wed, 4 Oct 2023 01:33:24 +0200 Subject: [PATCH] Update dependencies and lints --- .codespellignore | 1 + .pre-commit-config.yaml | 8 ++++---- Cargo.toml | 10 +++++----- src/lib.rs | 32 ++++++++++++++++++-------------- src/library/database.rs | 2 +- src/tag/format/enveloped.rs | 19 ++++++++++++++----- src/tag/markers2.rs | 17 +++++++++++------ src/tag/util.rs | 8 ++++---- src/util.rs | 8 ++++---- 9 files changed, 62 insertions(+), 43 deletions(-) diff --git a/.codespellignore b/.codespellignore index 2dbec76..9acf48d 100644 --- a/.codespellignore +++ b/.codespellignore @@ -1,2 +1,3 @@ crate +mis wll diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c8167cb..54eabab 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -21,7 +21,7 @@ repos: - id: mixed-line-ending - id: trailing-whitespace - repo: https://github.com/codespell-project/codespell - rev: v2.2.2 + rev: v2.2.6 hooks: - id: codespell args: @@ -48,11 +48,11 @@ repos: warnings, ] - repo: https://github.com/DavidAnson/markdownlint-cli2 - rev: v0.6.0 + rev: v0.10.0 hooks: - id: markdownlint-cli2 - repo: https://github.com/pre-commit/mirrors-prettier - rev: v3.0.0-alpha.4 + rev: v3.0.3 hooks: - id: prettier # We use markdowncli @@ -66,6 +66,6 @@ repos: hooks: - id: sourceheaders - repo: https://github.com/jorisroovers/gitlint - rev: v0.19.0dev + rev: v0.19.1 hooks: - id: gitlint diff --git a/Cargo.toml b/Cargo.toml index 6cc4e86..6ecbbaa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,10 +11,10 @@ categories = ["parser-implementations"] edition = "2021" [dependencies] -nom = "7" -base64 = "0.13" -thiserror = "1" +nom = "7.1" +base64 = "0.21" +thiserror = "1.0" [dev-dependencies] -id3 = "1" -textwrap = "0.14" +id3 = "1.8" +textwrap = "0.16" diff --git a/src/lib.rs b/src/lib.rs index 4a9756d..d94096b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -110,21 +110,25 @@ //! possible, but since this feature is still under development, the API is *not* stable yet and //! might change in the future. +// Opt-in for allowed-by-default lints (in alphabetical order) +// See also: +#![warn(future_incompatible)] +#![warn(let_underscore)] +#![warn(missing_debug_implementations)] +//#![warn(missing_docs)] // TODO +#![warn(rust_2018_idioms)] +#![warn(rust_2021_compatibility)] +#![warn(unreachable_pub)] #![warn(unsafe_code)] -#![cfg_attr(not(debug_assertions), deny(warnings))] -#![deny(rust_2018_idioms)] -#![deny(rust_2021_compatibility)] -#![deny(missing_debug_implementations)] -// TODO: Add missing docs -//#![deny(missing_docs)] -#![deny(rustdoc::broken_intra_doc_links)] -#![deny(clippy::all)] -#![deny(clippy::explicit_deref_methods)] -#![deny(clippy::explicit_into_iter_loop)] -#![deny(clippy::explicit_iter_loop)] -#![deny(clippy::must_use_candidate)] -#![cfg_attr(not(test), deny(clippy::panic_in_result_fn))] -#![cfg_attr(not(debug_assertions), deny(clippy::used_underscore_binding))] +#![warn(unused)] +// Clippy lints +//#![warn(clippy::pedantic)] // TODO +// Additional restrictions +#![warn(clippy::clone_on_ref_ptr)] +//#![warn(clippy::missing_const_for_fn)] // TODO +// Relaxations +#![allow(clippy::module_name_repetitions)] // OK +#![allow(clippy::needless_pub_self)] // TODO pub mod error; pub mod library; diff --git a/src/library/database.rs b/src/library/database.rs index efdbeb6..bb8818d 100644 --- a/src/library/database.rs +++ b/src/library/database.rs @@ -115,7 +115,7 @@ fn take_u16_bytes(input: &[u8]) -> Res<&[u8], Vec> { fn parse_u16_text(input: &[u8]) -> Res<&[u8], String> { let (input, bytes) = nom::combinator::all_consuming(take_u16_bytes)(input)?; - let text = std::char::decode_utf16(bytes.into_iter()) + let text = std::char::decode_utf16(bytes) .map(|r| r.unwrap_or(std::char::REPLACEMENT_CHARACTER)) .collect::(); Ok((input, text)) diff --git a/src/tag/format/enveloped.rs b/src/tag/format/enveloped.rs index 95d7902..fdf74ad 100644 --- a/src/tag/format/enveloped.rs +++ b/src/tag/format/enveloped.rs @@ -8,11 +8,14 @@ //! Helper for FLAC and MP4 tags +use std::io; +use std::io::Cursor; + +use base64::Engine as _; + use super::Tag; use crate::error::Error; use crate::util::{take_utf8, Res}; -use std::io; -use std::io::Cursor; pub trait EnvelopedTag: Tag { fn parse_enveloped(input: &[u8]) -> Result { @@ -49,14 +52,18 @@ pub fn take_base64_with_newline(input: &[u8]) -> Res<&[u8], &[u8]> { nom::bytes::complete::take_while(|b| is_base64(b) || is_newline(b))(input) } -const BASE64_FORGIVING: base64::Config = base64::STANDARD_NO_PAD.decode_allow_trailing_bits(true); +const BASE64_FORGIVING: base64::engine::GeneralPurpose = + base64::engine::general_purpose::GeneralPurpose::new( + &base64::alphabet::STANDARD, + base64::engine::general_purpose::NO_PAD.with_decode_allow_trailing_bits(true), + ); pub fn base64_decode(input: &[u8]) -> Result, Error> { let mut encoded: Vec = input.iter().filter(|&b| !is_newline(*b)).copied().collect(); if encoded.len() % 4 != 2 { encoded.pop(); } - let decoded = base64::decode_config(encoded, BASE64_FORGIVING); + let decoded = BASE64_FORGIVING.decode(encoded); match decoded { Ok(data) => Ok(data), Err(e) => Err(Error::Base64DecodeError { source: e }), @@ -70,7 +77,9 @@ pub fn base64_encode(writer: &mut impl io::Write, input: &[u8]) -> Result Res<&[u8], Color> { +pub(crate) fn take_color(input: &[u8]) -> Res<&[u8], Color> { let (input, bytes) = nom::bytes::complete::take(3usize)(input)?; let (bytes, red) = nom::number::complete::u8(bytes)?; let (bytes, green) = nom::number::complete::u8(bytes)?; @@ -51,13 +51,13 @@ fn test_take_color() { assert!(take_color(&[0xAB, 0xCD]).is_err()); } -pub fn write_color(writer: &mut impl io::Write, color: Color) -> Result { +pub(crate) fn write_color(writer: &mut impl io::Write, color: Color) -> Result { let Color { blue, green, red } = color; Ok(writer.write(&[red, green, blue])?) } /// Returns a `Version` struct parsed from the first 2 input bytes. -pub fn take_version(input: &[u8]) -> Res<&[u8], Version> { +pub(crate) fn take_version(input: &[u8]) -> Res<&[u8], Version> { let (input, version) = take(2usize)(input)?; Ok(( input, @@ -81,7 +81,7 @@ fn test_take_version() { assert!(take_version(&[0x0A]).is_err()); } -pub fn write_version(writer: &mut impl io::Write, version: Version) -> Result { +pub(crate) fn write_version(writer: &mut impl io::Write, version: Version) -> Result { let Version { major, minor } = version; Ok(writer.write(&[major, minor])?) } diff --git a/src/util.rs b/src/util.rs index f56743a..d5acb8f 100644 --- a/src/util.rs +++ b/src/util.rs @@ -10,12 +10,12 @@ use nom::bytes::complete::take_until; -pub type Res = nom::IResult>; +pub(crate) type Res = nom::IResult>; pub(crate) const NULL: &[u8] = &[0x00]; /// Returns the input slice until the first occurrence of a null byte. -pub fn take_until_nullbyte(input: &[u8]) -> Res<&[u8], &[u8]> { +pub(crate) fn take_until_nullbyte(input: &[u8]) -> Res<&[u8], &[u8]> { take_until(NULL)(input) } @@ -32,7 +32,7 @@ fn test_take_until_nullbyte() { assert!(take_until_nullbyte(&[0xAB, 0xCD]).is_err()); } -pub fn parse_utf8(input: &[u8]) -> Res<&[u8], &str> { +pub(crate) fn parse_utf8(input: &[u8]) -> Res<&[u8], &str> { std::str::from_utf8(input) .map(|s| (&b""[..], s)) .map_err(|_| nom::Err::Incomplete(nom::Needed::Unknown)) @@ -43,7 +43,7 @@ fn test_parse_utf8() { assert_eq!(parse_utf8(&[0x41, 0x42]), Ok((&b""[..], "AB"))); } -pub fn take_utf8(input: &[u8]) -> Res<&[u8], &str> { +pub(crate) fn take_utf8(input: &[u8]) -> Res<&[u8], &str> { let (input, data) = take_until_nullbyte(input)?; let (_, value) = parse_utf8(data)?; let (input, _) = nom::bytes::complete::take(1usize)(input)?;