Skip to content

Commit

Permalink
Configure lint options in Cargo.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
EFanZh committed Nov 18, 2023
1 parent 5c67d0c commit 28c944d
Show file tree
Hide file tree
Showing 13 changed files with 134 additions and 341 deletions.
114 changes: 114 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,120 @@ version = "0.1.0"
[workspace]
members = ["tools/check-cpp-code-format", "tools/progress-tracker", "xtask"]

[workspace.lints.rust]
absolute_paths_not_starting_with_crate = "warn"
explicit_outlives_requirements = "warn"
let_underscore_drop = "warn"
macro_use_extern_crate = "warn"
meta_variable_misuse = "warn"
missing_abi = "warn"
missing_docs = "allow"
noop_method_call = "warn"
pointer_structural_match = "warn"
single_use_lifetimes = "warn"
trivial_casts = "allow"
trivial_numeric_casts = "warn"
unsafe_code = "warn"
unsafe_op_in_unsafe_fn = "warn"
unused_crate_dependencies = "warn"
unused_extern_crates = "warn"
unused_import_braces = "warn"
unused_lifetimes = "warn"
unused_macro_rules = "warn"
unused_qualifications = "warn"
unused_tuple_struct_fields = "warn"
variant_size_differences = "warn"

[workspace.lints.clippy]
alloc_instead_of_core = "warn"
allow_attributes_without_reason = "warn"
as_ptr_cast_mut = "warn"
branches_sharing_code = "warn"
cargo_common_metadata = "allow"
cast_possible_truncation = "allow"
cast_possible_wrap = "allow"
cast_sign_loss = "allow"
clone_on_ref_ptr = "warn"
cognitive_complexity = "warn"
create_dir = "warn"
dbg_macro = "warn"
debug_assert_with_mut_call = "warn"
decimal_literal_representation = "allow"
deref_by_slicing = "warn"
derive_partial_eq_without_eq = "warn"
empty_drop = "warn"
empty_line_after_outer_attr = "warn"
empty_structs_with_brackets = "warn"
equatable_if_let = "warn"
fallible_impl_from = "warn"
filetype_is_file = "warn"
float_cmp_const = "warn"
format_push_string = "warn"
get_unwrap = "warn"
if_then_some_else_none = "warn"
imprecise_flops = "warn"
iter_on_empty_collections = "warn"
iter_on_single_items = "warn"
iter_with_drain = "warn"
large_include_file = "warn"
let_underscore_must_use = "warn"
lossy_float_literal = "warn"
manual_clamp = "warn"
map_err_ignore = "warn"
missing_panics_doc = "allow"
mixed_read_write_in_expression = "warn"
multiple_inherent_impl = "warn"
must_use_candidate = "allow"
mutex_atomic = "warn"
mutex_integer = "warn"
needless_collect = "warn"
needless_pass_by_value = "allow"
negative_feature_names = "warn"
non_send_fields_in_send_ty = "warn"
nonstandard_macro_braces = "warn"
option_if_let_else = "warn"
or_fun_call = "warn"
panic = "warn"
panic_in_result_fn = "warn"
partial_pub_fields = "warn"
path_buf_push_overwrite = "warn"
pedantic = "warn"
print_stderr = "warn"
print_stdout = "warn"
rc_buffer = "warn"
rc_mutex = "warn"
redundant_feature_names = "warn"
redundant_locals = "allow" # False positive.
redundant_pub_crate = "warn"
rest_pat_in_fully_bound_structs = "warn"
same_name_method = "allow"
self_named_module_files = "warn"
significant_drop_in_scrutinee = "warn"
string_lit_as_bytes = "warn"
string_to_string = "warn"
suboptimal_flops = "warn"
suspicious_operation_groupings = "warn"
todo = "warn"
trailing_empty_array = "warn"
trait_duplication_in_bounds = "warn"
transmute_undefined_repr = "warn"
trivial_regex = "warn"
try_err = "warn"
type_repetition_in_bounds = "warn"
undocumented_unsafe_blocks = "warn"
unimplemented = "warn"
unnecessary_safety_comment = "warn"
unnecessary_safety_doc = "warn"
unnecessary_self_imports = "warn"
unneeded_field_pattern = "warn"
unused_peekable = "warn"
unused_rounding = "warn"
use_debug = "warn"
use_self = "warn"
useless_let_if_seq = "warn"
verbose_file_reads = "warn"
wildcard_dependencies = "allow"

[dependencies]
rand = "0.6"

Expand Down
121 changes: 0 additions & 121 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,124 +1,3 @@
#![warn(
absolute_paths_not_starting_with_crate,
explicit_outlives_requirements,
let_underscore_drop,
macro_use_extern_crate,
meta_variable_misuse,
missing_abi,
missing_docs,
noop_method_call,
pointer_structural_match,
single_use_lifetimes,
trivial_casts,
trivial_numeric_casts,
unsafe_code,
unsafe_op_in_unsafe_fn,
unused_crate_dependencies,
unused_extern_crates,
unused_import_braces,
unused_lifetimes,
unused_macro_rules,
unused_qualifications,
unused_tuple_struct_fields,
variant_size_differences,
clippy::alloc_instead_of_core,
clippy::allow_attributes_without_reason,
clippy::as_ptr_cast_mut,
clippy::branches_sharing_code,
clippy::cargo_common_metadata,
clippy::clone_on_ref_ptr,
clippy::cognitive_complexity,
clippy::create_dir,
clippy::dbg_macro,
clippy::debug_assert_with_mut_call,
clippy::decimal_literal_representation,
clippy::deref_by_slicing,
clippy::derive_partial_eq_without_eq,
clippy::empty_drop,
clippy::empty_line_after_outer_attr,
clippy::empty_structs_with_brackets,
clippy::equatable_if_let,
clippy::fallible_impl_from,
clippy::filetype_is_file,
clippy::float_cmp_const,
clippy::format_push_string,
clippy::get_unwrap,
clippy::if_then_some_else_none,
clippy::imprecise_flops,
clippy::iter_on_empty_collections,
clippy::iter_on_single_items,
clippy::iter_with_drain,
clippy::large_include_file,
clippy::let_underscore_must_use,
clippy::lossy_float_literal,
clippy::manual_clamp,
clippy::map_err_ignore,
clippy::mixed_read_write_in_expression,
clippy::multiple_inherent_impl,
clippy::mutex_atomic,
clippy::mutex_integer,
clippy::needless_collect,
clippy::negative_feature_names,
clippy::non_send_fields_in_send_ty,
clippy::nonstandard_macro_braces,
clippy::option_if_let_else,
clippy::or_fun_call,
clippy::panic,
clippy::panic_in_result_fn,
clippy::partial_pub_fields,
clippy::path_buf_push_overwrite,
clippy::pedantic,
clippy::print_stderr,
clippy::print_stdout,
clippy::rc_buffer,
clippy::rc_mutex,
clippy::redundant_feature_names,
clippy::redundant_pub_crate,
clippy::rest_pat_in_fully_bound_structs,
clippy::same_name_method,
clippy::self_named_module_files,
clippy::significant_drop_in_scrutinee,
clippy::string_lit_as_bytes,
clippy::string_to_string,
clippy::suboptimal_flops,
clippy::suspicious_operation_groupings,
clippy::todo,
clippy::trailing_empty_array,
clippy::trait_duplication_in_bounds,
clippy::transmute_undefined_repr,
clippy::trivial_regex,
clippy::try_err,
clippy::type_repetition_in_bounds,
clippy::undocumented_unsafe_blocks,
clippy::unimplemented,
clippy::unnecessary_safety_comment,
clippy::unnecessary_safety_doc,
clippy::unnecessary_self_imports,
clippy::unneeded_field_pattern,
clippy::unused_peekable,
clippy::unused_rounding,
clippy::use_debug,
clippy::use_self,
clippy::useless_let_if_seq,
clippy::verbose_file_reads,
clippy::wildcard_dependencies
)]
#![allow(
missing_docs,
trivial_casts,
clippy::cargo_common_metadata,
clippy::cast_possible_truncation,
clippy::cast_possible_wrap,
clippy::cast_sign_loss,
clippy::decimal_literal_representation,
clippy::missing_panics_doc,
clippy::must_use_candidate,
clippy::needless_pass_by_value,
clippy::redundant_locals, // False positive.
clippy::same_name_method,
clippy::wildcard_dependencies
)]

pub(crate) mod data_structures;
pub mod problem_0001_two_sum;
pub mod problem_0002_add_two_numbers;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![allow(non_snake_case)]
#![allow(non_snake_case)] // Expected.

use super::guess;

Expand Down
2 changes: 1 addition & 1 deletion src/problem_0405_convert_a_number_to_hexadecimal/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![allow(clippy::wrong_self_convention)]
#![allow(clippy::wrong_self_convention)] // Expected.

pub mod cheating;
pub mod iterative;
Expand Down
1 change: 0 additions & 1 deletion src/problem_0778_swim_in_rising_water/bidirectional_bfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ impl Solution {
}

pub fn swim_in_water(grid: Vec<Vec<i32>>) -> i32 {
let grid = grid;
let n = grid.len();

if n < 2 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ mod tests {
}

#[test]
#[should_panic]
#[should_panic(expected = "internal error: entered unreachable code")]
fn test_unwrap_occupied_failure() {
super::Solution::unwrap_occupied(HashMap::from([(2, (3_u16, 5_u16))]).entry(5));
}
Expand Down
2 changes: 1 addition & 1 deletion src/problem_1001_grid_illumination/iterative.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ mod tests {
}

#[test]
#[should_panic]
#[should_panic(expected = "internal error: entered unreachable code")]
fn test_unwrap_occupied_failure() {
super::Counter::unwrap_occupied(HashMap::from([(2_u32, 5_u16)]).entry(5));
}
Expand Down
20 changes: 8 additions & 12 deletions src/problem_1036_escape_a_large_maze/bfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,14 @@ impl Solution {
pub fn is_escape_possible(blocked: Vec<Vec<i32>>, source: Vec<i32>, target: Vec<i32>) -> bool {
const MAZE_SIZE: u32 = 1_000_000;

let blocked = {
let blocked = blocked;

blocked
.iter()
.map(|point| {
let [x, y]: [_; 2] = point.as_slice().try_into().unwrap();

(x as u32, y as u32)
})
.collect::<HashSet<_>>()
};
let blocked = blocked
.into_iter()
.map(|point| {
let [x, y]: [_; 2] = point.try_into().ok().unwrap();

(x as u32, y as u32)
})
.collect::<HashSet<_>>();

let source = Self::unwrap_point(source);
let target = Self::unwrap_point(target);
Expand Down
20 changes: 8 additions & 12 deletions src/problem_1105_filling_bookcase_shelves/dynamic_programming.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,14 @@ use std::convert::TryInto;

impl Solution {
pub fn min_height_shelves(books: Vec<Vec<i32>>, shelf_width: i32) -> i32 {
let books = {
let books = books;

books
.iter()
.map(|book| {
let [thickness, height]: [_; 2] = book.as_slice().try_into().unwrap();

(thickness as u32, height as u32)
})
.collect::<Vec<_>>()
};
let books = books
.into_iter()
.map(|book| {
let [thickness, height]: [_; 2] = book.try_into().ok().unwrap();

(thickness as u32, height as u32)
})
.collect::<Vec<_>>();

let shelf_width = shelf_width as u32;
let mut cache = Vec::with_capacity(books.len());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ impl Solution {
let mut waiting = 0;

for (i, customer) in (1..).zip(customers) {
let customer = customer;

waiting += customer;

let onboard = waiting.min(4);
Expand Down
Loading

0 comments on commit 28c944d

Please sign in to comment.