Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: Resolve lints #337

Merged
merged 1 commit into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 58 additions & 63 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,73 +17,68 @@ include = [
]

[workspace.lints.rust]
# rust_2018_idioms = "warn"
# unreachable_pub = "warn"
# unsafe_op_in_unsafe_fn = "warn"
# unused_lifetimes = "warn"
# unused_macro_rules = "warn"
# unused_qualifications = "warn"
rust_2018_idioms = "warn"
unreachable_pub = "warn"
unsafe_op_in_unsafe_fn = "warn"
unused_lifetimes = "warn"
unused_macro_rules = "warn"
unused_qualifications = "warn"

[workspace.lints.clippy]
bool_assert_comparison = "allow"
branches_sharing_code = "allow"
# checked_conversions = "warn"
checked_conversions = "warn"
collapsible_else_if = "allow"
# create_dir = "warn"
# dbg_macro = "warn"
# debug_assert_with_mut_call = "warn"
# doc_markdown = "warn"
# empty_enum = "warn"
# enum_glob_use = "warn"
# expl_impl_clone_on_copy = "warn"
# explicit_deref_methods = "warn"
# explicit_into_iter_loop = "warn"
# fallible_impl_from = "warn"
# filter_map_next = "warn"
# flat_map_option = "warn"
# float_cmp_const = "warn"
# fn_params_excessive_bools = "warn"
# from_iter_instead_of_collect = "warn"
create_dir = "warn"
dbg_macro = "warn"
debug_assert_with_mut_call = "warn"
doc_markdown = "warn"
empty_enum = "warn"
enum_glob_use = "warn"
expl_impl_clone_on_copy = "warn"
explicit_deref_methods = "warn"
explicit_into_iter_loop = "warn"
fallible_impl_from = "warn"
filter_map_next = "warn"
flat_map_option = "warn"
float_cmp_const = "warn"
fn_params_excessive_bools = "warn"
from_iter_instead_of_collect = "warn"
if_same_then_else = "allow"
# implicit_clone = "warn"
# imprecise_flops = "warn"
# inconsistent_struct_constructor = "warn"
# inefficient_to_string = "warn"
# infinite_loop = "warn"
# invalid_upcast_comparisons = "warn"
# large_digit_groups = "warn"
# large_stack_arrays = "warn"
# large_types_passed_by_value = "warn"
implicit_clone = "warn"
imprecise_flops = "warn"
inconsistent_struct_constructor = "warn"
inefficient_to_string = "warn"
infinite_loop = "warn"
invalid_upcast_comparisons = "warn"
large_digit_groups = "warn"
large_stack_arrays = "warn"
large_types_passed_by_value = "warn"
let_and_return = "allow" # sometimes good to name what you are returning
# linkedlist = "warn"
# lossy_float_literal = "warn"
# macro_use_imports = "warn"
# match_wildcard_for_single_variants = "warn"
# mem_forget = "warn"
# mutex_integer = "warn"
# needless_continue = "warn"
# needless_for_each = "warn"
# negative_feature_names = "warn"
# path_buf_push_overwrite = "warn"
# ptr_as_ptr = "warn"
# rc_mutex = "warn"
# redundant_feature_names = "warn"
# ref_option_ref = "warn"
# rest_pat_in_fully_bound_structs = "warn"
# same_functions_in_if_condition = "warn"
# self_named_module_files = "warn"
# semicolon_if_nothing_returned = "warn"
# single_match_else = "warn"
# str_to_string = "warn"
# string_add = "warn"
# string_add_assign = "warn"
# string_lit_as_bytes = "warn"
# string_to_string = "warn"
# todo = "warn"
# trait_duplication_in_bounds = "warn"
# verbose_file_reads = "warn"
# wildcard_imports = "warn"
# zero_sized_map_values = "warn"

# Remove these later:
assigning_clones = "allow"
linkedlist = "warn"
lossy_float_literal = "warn"
macro_use_imports = "warn"
mem_forget = "warn"
mutex_integer = "warn"
needless_continue = "warn"
needless_for_each = "warn"
negative_feature_names = "warn"
path_buf_push_overwrite = "warn"
ptr_as_ptr = "warn"
rc_mutex = "warn"
redundant_feature_names = "warn"
ref_option_ref = "warn"
rest_pat_in_fully_bound_structs = "warn"
same_functions_in_if_condition = "warn"
self_named_module_files = "warn"
semicolon_if_nothing_returned = "warn"
str_to_string = "warn"
string_add = "warn"
string_add_assign = "warn"
string_lit_as_bytes = "warn"
string_to_string = "warn"
todo = "warn"
trait_duplication_in_bounds = "warn"
verbose_file_reads = "warn"
wildcard_imports = "warn"
zero_sized_map_values = "warn"
2 changes: 1 addition & 1 deletion crates/snapbox/src/assert/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl Backtrace {

#[cfg(feature = "debug")]
impl std::fmt::Display for Backtrace {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
// `backtrace::Backtrace` uses `Debug` instead of `Display`
write!(f, "{:?}", self.0)
}
Expand Down
8 changes: 4 additions & 4 deletions crates/snapbox/src/assert/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl Assert {
#[track_caller]
#[deprecated(since = "0.6.0", note = "Replaced with `Assert::eq`")]
pub fn eq_(&self, actual: impl IntoData, expected: impl IntoData) {
self.eq(actual, expected)
self.eq(actual, expected);
}

pub fn try_eq(
Expand Down Expand Up @@ -193,7 +193,7 @@ impl Assert {
actual_name: Option<&dyn std::fmt::Display>,
actual: &crate::Data,
expected: &crate::Data,
) -> crate::assert::Result<()> {
) -> Result<()> {
if actual != expected {
let mut buf = String::new();
crate::report::write_diff(
Expand Down Expand Up @@ -223,7 +223,7 @@ impl Assert {
) {
let expected_root = expected_root.into();
let actual_root = actual_root.into();
self.subset_eq_inner(expected_root, actual_root)
self.subset_eq_inner(expected_root, actual_root);
}

#[track_caller]
Expand All @@ -248,7 +248,7 @@ impl Assert {
) {
let pattern_root = pattern_root.into();
let actual_root = actual_root.into();
self.subset_matches_inner(pattern_root, actual_root)
self.subset_matches_inner(pattern_root, actual_root);
}

#[track_caller]
Expand Down
2 changes: 1 addition & 1 deletion crates/snapbox/src/bin/snap-fixture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn run() -> Result<(), Box<dyn Error>> {
}

if env::var("echo_cwd").as_deref() == Ok("1") {
if let Ok(cwd) = std::env::current_dir() {
if let Ok(cwd) = env::current_dir() {
eprintln!("{}", cwd.display());
}
}
Expand Down
6 changes: 3 additions & 3 deletions crates/snapbox/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ pub fn display_exit_status(status: std::process::ExitStatus) -> String {
pub fn display_exit_status(status: std::process::ExitStatus) -> String {
#[cfg(unix)]
fn detailed_exit_status(status: std::process::ExitStatus) -> Option<String> {
use std::os::unix::process::*;
use std::os::unix::process::ExitStatusExt;

let signal = status.signal()?;
let name = match signal as libc::c_int {
Expand Down Expand Up @@ -963,7 +963,7 @@ pub(crate) mod examples {

#[allow(clippy::type_complexity)]
fn decode_example_message<'m>(
message: &'m escargot::format::Message,
message: &'m escargot::format::Message<'_>,
) -> Option<crate::assert::Result<(&'m str, crate::assert::Result<std::path::PathBuf>)>> {
match message {
escargot::format::Message::CompilerMessage(msg) => {
Expand Down Expand Up @@ -1003,7 +1003,7 @@ pub(crate) mod examples {
}
}

fn is_example_target(target: &escargot::format::Target) -> bool {
fn is_example_target(target: &escargot::format::Target<'_>) -> bool {
target.crate_types == ["bin"] && target.kind == ["example"]
}
}
4 changes: 2 additions & 2 deletions crates/snapbox/src/data/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ impl IntoData for &'_ str {
impl IntoData for Inline {
fn into_data(self) -> Data {
let trimmed = self.trimmed();
super::Data::text(trimmed).with_source(self)
Data::text(trimmed).with_source(self)
}
}

Expand Down Expand Up @@ -781,7 +781,7 @@ impl<'s> From<&'s str> for Data {
}
}

impl From<Inline> for super::Data {
impl From<Inline> for Data {
fn from(other: Inline) -> Self {
other.into_data()
}
Expand Down
2 changes: 1 addition & 1 deletion crates/snapbox/src/data/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ world

#[test]
fn test_patchwork() {
let mut patchwork = Patchwork::new("one two three".to_string());
let mut patchwork = Patchwork::new("one two three".to_owned());
patchwork.patch(4..7, "zwei");
patchwork.patch(0..3, "один");
patchwork.patch(8..13, "3");
Expand Down
2 changes: 1 addition & 1 deletion crates/snapbox/src/data/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ fn binary_to_text() {
let binary = String::from("test").into_bytes();
let d = Data::binary(binary);
let text = d.coerce_to(DataFormat::Text);
assert_eq!(DataFormat::Text, text.format())
assert_eq!(DataFormat::Text, text.format());
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion crates/snapbox/src/filter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ fn normalize_json_string(value: &mut serde_json::Value, op: &dyn Fn(&str) -> Str
}
serde_json::Value::Array(arr) => {
for value in arr.iter_mut() {
normalize_json_string(value, op)
normalize_json_string(value, op);
}
}
serde_json::Value::Object(obj) => {
Expand Down
30 changes: 13 additions & 17 deletions crates/snapbox/src/filter/pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::Data;

/// Adjust `actual` based on `expected`
pub struct NormalizeToExpected<'a> {
substitutions: Option<&'a crate::Redactions>,
substitutions: Option<&'a Redactions>,
unordered: bool,
}

Expand Down Expand Up @@ -44,7 +44,7 @@ impl<'a> NormalizeToExpected<'a> {
/// - `[..]`: match multiple characters within a line
///
/// Built-ins cannot automatically be applied to `actual` but are inferred from `expected`
pub fn redact_with(mut self, redactions: &'a crate::Redactions) -> Self {
pub fn redact_with(mut self, redactions: &'a Redactions) -> Self {
self.substitutions = Some(redactions);
self
}
Expand Down Expand Up @@ -128,7 +128,7 @@ fn normalize_data_to_unordered(actual: Data, expected: &Data) -> Data {

#[cfg(feature = "structured-data")]
fn normalize_value_to_unordered(actual: &mut serde_json::Value, expected: &serde_json::Value) {
use serde_json::Value::*;
use serde_json::Value::{Array, Object, String};

match (actual, expected) {
(String(act), String(exp)) => {
Expand Down Expand Up @@ -159,7 +159,7 @@ fn normalize_value_to_unordered(actual: &mut serde_json::Value, expected: &serde
(Object(act), Object(exp)) => {
for (actual_key, mut actual_value) in std::mem::replace(act, serde_json::Map::new()) {
if let Some(expected_value) = exp.get(&actual_key) {
normalize_value_to_unordered(&mut actual_value, expected_value)
normalize_value_to_unordered(&mut actual_value, expected_value);
}
act.insert(actual_key, actual_value);
}
Expand Down Expand Up @@ -206,7 +206,7 @@ const VALUE_WILDCARD: &str = "{...}";
fn normalize_data_to_unordered_redactions(
actual: Data,
expected: &Data,
substitutions: &crate::Redactions,
substitutions: &Redactions,
) -> Data {
let source = actual.source;
let filters = actual.filters;
Expand Down Expand Up @@ -260,9 +260,9 @@ fn normalize_data_to_unordered_redactions(
fn normalize_value_to_unordered_redactions(
actual: &mut serde_json::Value,
expected: &serde_json::Value,
substitutions: &crate::Redactions,
substitutions: &Redactions,
) {
use serde_json::Value::*;
use serde_json::Value::{Array, Object, String};

match (actual, expected) {
(act, String(exp)) if exp == VALUE_WILDCARD => {
Expand Down Expand Up @@ -310,7 +310,7 @@ fn normalize_value_to_unordered_redactions(
&mut actual_value,
expected_value,
substitutions,
)
);
} else if has_key_wildcard {
continue;
}
Expand All @@ -327,7 +327,7 @@ fn normalize_value_to_unordered_redactions(
fn normalize_str_to_unordered_redactions(
actual: &str,
expected: &str,
substitutions: &crate::Redactions,
substitutions: &Redactions,
) -> String {
if actual == expected {
return actual.to_owned();
Expand Down Expand Up @@ -366,11 +366,7 @@ fn normalize_str_to_unordered_redactions(
normalized.join("")
}

fn normalize_data_to_redactions(
actual: Data,
expected: &Data,
substitutions: &crate::Redactions,
) -> Data {
fn normalize_data_to_redactions(actual: Data, expected: &Data, substitutions: &Redactions) -> Data {
let source = actual.source;
let filters = actual.filters;
let inner = match (actual.inner, &expected.inner) {
Expand Down Expand Up @@ -423,9 +419,9 @@ fn normalize_data_to_redactions(
fn normalize_value_to_redactions(
actual: &mut serde_json::Value,
expected: &serde_json::Value,
substitutions: &crate::Redactions,
substitutions: &Redactions,
) {
use serde_json::Value::*;
use serde_json::Value::{Array, Object, String};

match (actual, expected) {
(act, String(exp)) if exp == VALUE_WILDCARD => {
Expand Down Expand Up @@ -473,7 +469,7 @@ fn normalize_value_to_redactions(
exp.get(KEY_WILDCARD).and_then(|v| v.as_str()) == Some(VALUE_WILDCARD);
for (actual_key, mut actual_value) in std::mem::replace(act, serde_json::Map::new()) {
if let Some(expected_value) = exp.get(&actual_key) {
normalize_value_to_redactions(&mut actual_value, expected_value, substitutions)
normalize_value_to_redactions(&mut actual_value, expected_value, substitutions);
} else if has_key_wildcard {
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions crates/snapbox/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,14 @@ mod test {
fn closure_fn_path() {
(|| {
assert_eq!(fn_path!(), "snapbox::macros::test::closure_fn_path");
})()
})();
}

#[test]
fn nested_fn_path() {
fn nested() {
assert_eq!(fn_path!(), "snapbox::macros::test::nested_fn_path::nested");
}
nested()
nested();
}
}
Loading
Loading