From e0cf455a7fec4f865f122b0fde1f1066d367bf66 Mon Sep 17 00:00:00 2001 From: Mateusz Gienieczko Date: Tue, 27 Feb 2024 18:25:02 +0100 Subject: [PATCH] fix clippy lints in tests --- .../rsonpath-lib/src/automaton/minimizer.rs | 1 - .../rsonpath-lib/src/automaton/small_set.rs | 1 - .../classifier_correctness_tests.rs | 2 +- crates/rsonpath-lib/src/input/padding.rs | 2 +- crates/rsonpath-syntax/src/error.rs | 100 ++++++++++-------- 5 files changed, 59 insertions(+), 47 deletions(-) diff --git a/crates/rsonpath-lib/src/automaton/minimizer.rs b/crates/rsonpath-lib/src/automaton/minimizer.rs index 405ca65c..5903e60f 100644 --- a/crates/rsonpath-lib/src/automaton/minimizer.rs +++ b/crates/rsonpath-lib/src/automaton/minimizer.rs @@ -321,7 +321,6 @@ impl<'q> Minimizer<'q> { mod tests { use super::super::*; use super::*; - use nfa::NfaState; use pretty_assertions::assert_eq; use smallvec::smallvec; diff --git a/crates/rsonpath-lib/src/automaton/small_set.rs b/crates/rsonpath-lib/src/automaton/small_set.rs index 21cbcc87..11f0775e 100644 --- a/crates/rsonpath-lib/src/automaton/small_set.rs +++ b/crates/rsonpath-lib/src/automaton/small_set.rs @@ -242,7 +242,6 @@ mod tests256 { use super::*; use itertools::Itertools; use proptest::{collection, proptest}; - use std::collections::BTreeSet; const MAX_SET_SIZE: usize = 256; const MAX_INPUT_SIZE: usize = 1024; diff --git a/crates/rsonpath-lib/src/classification/classifier_correctness_tests.rs b/crates/rsonpath-lib/src/classification/classifier_correctness_tests.rs index bbe10504..1ffaacba 100644 --- a/crates/rsonpath-lib/src/classification/classifier_correctness_tests.rs +++ b/crates/rsonpath-lib/src/classification/classifier_correctness_tests.rs @@ -149,7 +149,7 @@ fn block_boundary() { mod prop_test { use super::{apply_offset, classify_string, BracketType, Structural}; - use proptest::{self, collection, prelude::*}; + use proptest::{collection, prelude::*}; use std::fmt::Debug; /// A string inside quotes (quotes included) diff --git a/crates/rsonpath-lib/src/input/padding.rs b/crates/rsonpath-lib/src/input/padding.rs index d5b146b6..510c27d4 100644 --- a/crates/rsonpath-lib/src/input/padding.rs +++ b/crates/rsonpath-lib/src/input/padding.rs @@ -594,7 +594,7 @@ fn seek_non_whitespace_backward_impl(bytes: &[u8], from: usize) -> Option<(usize #[cfg(test)] mod test { - use super::{PaddedBlock, JSON_SPACE_BYTE, *}; + use super::*; use pretty_assertions::assert_eq; #[test] diff --git a/crates/rsonpath-syntax/src/error.rs b/crates/rsonpath-syntax/src/error.rs index f47f5aec..dd9be05c 100644 --- a/crates/rsonpath-syntax/src/error.rs +++ b/crates/rsonpath-syntax/src/error.rs @@ -12,9 +12,9 @@ use std::fmt::{self, Display}; use thiserror::Error; #[cfg(feature = "color")] -use colored::ErrorStyle; +use colored::OwoColorsErrorStyle as ErrorStyleImpl; #[cfg(not(feature = "color"))] -use plain::ErrorStyle; +use plain::PlainErrorStyle as ErrorStyleImpl; #[derive(Debug)] pub(crate) struct ParseErrorBuilder { @@ -56,7 +56,7 @@ impl ParseErrorBuilder { impl Display for ParseError { #[inline] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - fmt_parse_error(self, &ErrorStyle::empty(), f) + fmt_parse_error(self, &ErrorStyleImpl::empty(), f) } } @@ -72,7 +72,7 @@ impl ParseError { } #[inline(always)] -fn fmt_parse_error(error: &ParseError, style: &ErrorStyle, f: &mut fmt::Formatter<'_>) -> fmt::Result { +fn fmt_parse_error(error: &ParseError, style: &ErrorStyleImpl, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut suggestion = Suggestion::new(); for syntax_error in &error.syntax_errors { writeln!( @@ -143,7 +143,7 @@ impl SyntaxError { - A list of lines of the input, each with an optional underline message. - A list of notes/suggestions at the end. */ - fn display(&self, input: &str, suggestion: &mut Suggestion, style: ErrorStyle) -> DisplayableSyntaxError { + fn display(&self, input: &str, suggestion: &mut Suggestion, style: ErrorStyleImpl) -> DisplayableSyntaxError { let start_idx = input.len() - self.rev_idx; let end_idx = start_idx + self.len - 1; let mut builder = DisplayableSyntaxErrorBuilder::new(); @@ -368,7 +368,7 @@ impl DisplayableSyntaxErrorBuilder { toplevel_message: String, start_idx: usize, end_idx: usize, - style: ErrorStyle, + style: ErrorStyleImpl, ) -> DisplayableSyntaxError { self.finish_line(); DisplayableSyntaxError { @@ -408,7 +408,7 @@ struct DisplayableSyntaxError { end_idx: usize, lines: Vec, notes: Vec, - style: ErrorStyle, + style: ErrorStyleImpl, } struct SyntaxErrorNote { @@ -702,6 +702,18 @@ impl SyntaxErrorKind { } } +pub(super) trait ErrorStyle { + fn empty() -> Self; + fn error_prefix<'a, D: Display>(&self, target: &'a D) -> impl Display + 'a; + fn error_message<'a, D: Display>(&self, target: &'a D) -> impl Display + 'a; + fn error_position_hint<'a, D: Display>(&self, target: &'a D) -> impl Display + 'a; + fn error_underline<'a, D: Display>(&self, target: &'a D) -> impl Display + 'a; + fn error_underline_message<'a, D: Display>(&self, target: &'a D) -> impl Display + 'a; + fn line_numbers<'a, D: Display>(&self, target: &'a D) -> impl Display + 'a; + fn note_prefix<'a, D: Display>(&self, target: &'a D) -> impl Display + 'a; + fn suggestion<'a, D: Display>(&self, target: &'a D) -> impl Display + 'a; +} + #[cfg(feature = "color")] mod colored { use super::{fmt_parse_error, ParseError}; @@ -713,12 +725,12 @@ mod colored { impl Display for ColoredParseError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - fmt_parse_error(&self.0, &ErrorStyle::colored(), f) + fmt_parse_error(&self.0, &OwoColorsErrorStyle::colored(), f) } } #[derive(Clone)] - pub(super) struct ErrorStyle { + pub(super) struct OwoColorsErrorStyle { error_prefix: owo_colors::Style, error_message: owo_colors::Style, error_position_hint: owo_colors::Style, @@ -729,21 +741,7 @@ mod colored { suggestion: owo_colors::Style, } - impl ErrorStyle { - pub(super) fn empty() -> Self { - let empty_style = owo_colors::Style::new(); - Self { - error_prefix: empty_style, - error_message: empty_style, - error_position_hint: empty_style, - error_underline: empty_style, - error_underline_message: empty_style, - line_numbers: empty_style, - note_prefix: empty_style, - suggestion: empty_style, - } - } - + impl OwoColorsErrorStyle { pub(super) fn colored() -> Self { let error_color = owo_colors::Style::new().bright_red(); let error_message = owo_colors::Style::new().bold(); @@ -763,43 +761,59 @@ mod colored { suggestion: suggestion_color, } } + } + + impl super::ErrorStyle for OwoColorsErrorStyle { + fn empty() -> Self { + let empty_style = owo_colors::Style::new(); + Self { + error_prefix: empty_style, + error_message: empty_style, + error_position_hint: empty_style, + error_underline: empty_style, + error_underline_message: empty_style, + line_numbers: empty_style, + note_prefix: empty_style, + suggestion: empty_style, + } + } - pub(super) fn error_prefix<'a, D: Display>(&self, target: &'a D) -> impl Display + 'a { + fn error_prefix<'a, D: Display>(&self, target: &'a D) -> impl Display + 'a { use owo_colors::OwoColorize; target.style(self.error_prefix) } - pub(super) fn error_message<'a, D: Display>(&self, target: &'a D) -> impl Display + 'a { + fn error_message<'a, D: Display>(&self, target: &'a D) -> impl Display + 'a { use owo_colors::OwoColorize; target.style(self.error_message) } - pub(super) fn error_position_hint<'a, D: Display>(&self, target: &'a D) -> impl Display + 'a { + fn error_position_hint<'a, D: Display>(&self, target: &'a D) -> impl Display + 'a { use owo_colors::OwoColorize; target.style(self.error_position_hint) } - pub(super) fn error_underline<'a, D: Display>(&self, target: &'a D) -> impl Display + 'a { + fn error_underline<'a, D: Display>(&self, target: &'a D) -> impl Display + 'a { use owo_colors::OwoColorize; target.style(self.error_underline) } - pub(super) fn error_underline_message<'a, D: Display>(&self, target: &'a D) -> impl Display + 'a { + fn error_underline_message<'a, D: Display>(&self, target: &'a D) -> impl Display + 'a { use owo_colors::OwoColorize; target.style(self.error_underline_message) } - pub(super) fn line_numbers<'a, D: Display>(&self, target: &'a D) -> impl Display + 'a { + fn line_numbers<'a, D: Display>(&self, target: &'a D) -> impl Display + 'a { use owo_colors::OwoColorize; target.style(self.line_numbers) } - pub(super) fn note_prefix<'a, D: Display>(&self, target: &'a D) -> impl Display + 'a { + fn note_prefix<'a, D: Display>(&self, target: &'a D) -> impl Display + 'a { use owo_colors::OwoColorize; target.style(self.note_prefix) } - pub(super) fn suggestion<'a, D: Display>(&self, target: &'a D) -> impl Display + 'a { + fn suggestion<'a, D: Display>(&self, target: &'a D) -> impl Display + 'a { use owo_colors::OwoColorize; target.style(self.suggestion) } @@ -811,42 +825,42 @@ mod plain { use std::fmt::Display; #[derive(Clone)] - pub(super) struct ErrorStyle; + pub(super) struct PlainErrorStyle; - impl ErrorStyle { - pub(super) fn empty() -> Self { + impl super::ErrorStyle for PlainErrorStyle { + fn empty() -> Self { Self } - pub(super) fn error_prefix<'a, D: Display>(&self, target: &'a D) -> impl Display + 'a { + fn error_prefix<'a, D: Display>(&self, target: &'a D) -> impl Display + 'a { target } - pub(super) fn error_message<'a, D: Display>(&self, target: &'a D) -> impl Display + 'a { + fn error_message<'a, D: Display>(&self, target: &'a D) -> impl Display + 'a { target } - pub(super) fn error_position_hint<'a, D: Display>(&self, target: &'a D) -> impl Display + 'a { + fn error_position_hint<'a, D: Display>(&self, target: &'a D) -> impl Display + 'a { target } - pub(super) fn error_underline<'a, D: Display>(&self, target: &'a D) -> impl Display + 'a { + fn error_underline<'a, D: Display>(&self, target: &'a D) -> impl Display + 'a { target } - pub(super) fn error_underline_message<'a, D: Display>(&self, target: &'a D) -> impl Display + 'a { + fn error_underline_message<'a, D: Display>(&self, target: &'a D) -> impl Display + 'a { target } - pub(super) fn line_numbers<'a, D: Display>(&self, target: &'a D) -> impl Display + 'a { + fn line_numbers<'a, D: Display>(&self, target: &'a D) -> impl Display + 'a { target } - pub(super) fn note_prefix<'a, D: Display>(&self, target: &'a D) -> impl Display + 'a { + fn note_prefix<'a, D: Display>(&self, target: &'a D) -> impl Display + 'a { target } - pub(super) fn suggestion<'a, D: Display>(&self, target: &'a D) -> impl Display + 'a { + fn suggestion<'a, D: Display>(&self, target: &'a D) -> impl Display + 'a { target } }