Skip to content

Commit

Permalink
style: Re-enable lints
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Oct 22, 2024
1 parent 5fbf977 commit d71b6d7
Show file tree
Hide file tree
Showing 46 changed files with 335 additions and 346 deletions.
110 changes: 55 additions & 55 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,71 +19,71 @@ include = [

[workspace.lints.rust]
# rust_2018_idioms = { level = "warn", priority = -1 }
# unreachable_pub = "warn"
unreachable_pub = "warn"
unsafe_op_in_unsafe_fn = "warn"
unused_lifetimes = "warn"
unused_macro_rules = "warn"
# unused_qualifications = "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"
# 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"
# uninlined_format_args = "warn"
# verbose_file_reads = "warn"
# wildcard_imports = "warn"
# zero_sized_map_values = "warn"
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"
uninlined_format_args = "warn"
verbose_file_reads = "warn"
wildcard_imports = "warn"
zero_sized_map_values = "warn"

[package]
name = "config"
Expand Down
4 changes: 2 additions & 2 deletions examples/custom_file_format/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn main() {

// Deserialize the config object into your Settings struct:
let settings: Settings = settings.try_deserialize().unwrap();
println!("{:#?}", settings);
println!("{settings:#?}");
}

#[derive(Debug, Clone)]
Expand All @@ -34,7 +34,7 @@ impl Format for PemFile {
&self,
uri: Option<&String>,
text: &str,
) -> Result<Map<String, config::Value>, Box<dyn std::error::Error + Send + Sync>> {
) -> Result<Map<String, Value>, Box<dyn std::error::Error + Send + Sync>> {
// Store any valid keys into this map, they'll be merged with other sources into the final config map:
let mut result = Map::new();

Expand Down
10 changes: 5 additions & 5 deletions examples/custom_str_format/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ fn main() {
.build();

match config {
Ok(cfg) => println!("A config: {:#?}", cfg),
Err(e) => println!("An error: {}", e),
Ok(cfg) => println!("A config: {cfg:#?}"),
Err(e) => println!("An error: {e}"),
}
}

Expand All @@ -20,7 +20,7 @@ impl Format for MyFormat {
&self,
uri: Option<&String>,
text: &str,
) -> Result<Map<String, config::Value>, Box<dyn std::error::Error + Send + Sync>> {
) -> Result<Map<String, Value>, Box<dyn std::error::Error + Send + Sync>> {
// Let's assume our format is somewhat malformed, but this is fine
// In real life anything can be used here - nom, serde or other.
//
Expand All @@ -29,11 +29,11 @@ impl Format for MyFormat {

if text == "good" {
result.insert(
"key".to_string(),
"key".to_owned(),
Value::new(uri, ValueKind::String(text.into())),
);
} else {
println!("Something went wrong in {:?}", uri);
println!("Something went wrong in {uri:?}");
}

Ok(result)
Expand Down
2 changes: 1 addition & 1 deletion examples/hierarchical-env/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ fn main() {
let settings = Settings::new();

// Print out our settings
println!("{:?}", settings);
println!("{settings:?}");
}
6 changes: 3 additions & 3 deletions examples/hierarchical-env/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct Braintree {

#[derive(Debug, Deserialize)]
#[allow(unused)]
pub struct Settings {
pub(crate) struct Settings {
debug: bool,
database: Database,
sparkpost: Sparkpost,
Expand All @@ -43,7 +43,7 @@ pub struct Settings {
}

impl Settings {
pub fn new() -> Result<Self, ConfigError> {
pub(crate) fn new() -> Result<Self, ConfigError> {
let run_mode = env::var("RUN_MODE").unwrap_or_else(|_| "development".into());

let s = Config::builder()
Expand All @@ -53,7 +53,7 @@ impl Settings {
// Default to 'development' env
// Note that this file is _optional_
.add_source(
File::with_name(&format!("examples/hierarchical-env/config/{}", run_mode))
File::with_name(&format!("examples/hierarchical-env/config/{run_mode}"))
.required(false),
)
// Add in a local configuration file
Expand Down
4 changes: 2 additions & 2 deletions examples/watch/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ fn show() {
);
}

fn watch() {
fn watch() -> ! {
// Create a channel to receive the events.
let (tx, rx) = channel();

Expand Down Expand Up @@ -62,7 +62,7 @@ fn watch() {
show();
}

Err(e) => println!("watch error: {:?}", e),
Err(e) => println!("watch error: {e:?}"),

_ => {
// Ignore event
Expand Down
22 changes: 11 additions & 11 deletions src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ pub struct Environment {

/// Optional directive to translate collected keys into a form that matches what serializers
/// that the configuration would expect. For example if you have the `kebab-case` attribute
/// for your serde config types, you may want to pass Case::Kebab here.
/// for your serde config types, you may want to pass `Case::Kebab` here.
#[cfg(feature = "convert-case")]
convert_case: Option<convert_case::Case>,
convert_case: Option<Case>,

/// Optional character sequence that separates each env value into a vector. only works when try_parsing is set to true
/// Once set, you cannot have type String on the same environment, unless you set list_parse_keys.
/// Optional character sequence that separates each env value into a vector. only works when `try_parsing` is set to true
/// Once set, you cannot have type String on the same environment, unless you set `list_parse_keys`.
list_separator: Option<String>,
/// A list of keys which should always be parsed as a list. If not set you can have only `Vec<String>` or `String` (not both) in one environment.
list_parse_keys: Option<Vec<String>>,
Expand Down Expand Up @@ -110,7 +110,7 @@ impl Environment {
}
}

/// See [Environment::with_prefix]
/// See [`Environment::with_prefix`]
pub fn prefix(mut self, s: &str) -> Self {
self.prefix = Some(s.into());
self
Expand Down Expand Up @@ -141,7 +141,7 @@ impl Environment {
self
}

/// When set and try_parsing is true, then all environment variables will be parsed as [`Vec<String>`] instead of [`String`].
/// When set and `try_parsing` is true, then all environment variables will be parsed as [`Vec<String>`] instead of [`String`].
/// See
/// [`with_list_parse_key`](Self::with_list_parse_key)
/// when you want to use [`Vec<String>`] in combination with [`String`].
Expand All @@ -151,11 +151,11 @@ impl Environment {
}

/// Add a key which should be parsed as a list when collecting [`Value`]s from the environment.
/// Once list_separator is set, the type for string is [`Vec<String>`].
/// Once `list_separator` is set, the type for string is [`Vec<String>`].
/// To switch the default type back to type Strings you need to provide the keys which should be [`Vec<String>`] using this function.
pub fn with_list_parse_key(mut self, key: &str) -> Self {
if self.list_parse_keys.is_none() {
self.list_parse_keys = Some(vec![key.to_lowercase()])
self.list_parse_keys = Some(vec![key.to_lowercase()]);
} else {
self.list_parse_keys = self.list_parse_keys.map(|mut keys| {
keys.push(key.to_lowercase());
Expand Down Expand Up @@ -246,7 +246,7 @@ impl Source for Environment {
let prefix_pattern = self
.prefix
.as_ref()
.map(|prefix| format!("{}{}", prefix, prefix_separator).to_lowercase());
.map(|prefix| format!("{prefix}{prefix_separator}").to_lowercase());

let collector = |(key, value): (String, String)| {
// Treat empty environment variables as unset
Expand Down Expand Up @@ -295,7 +295,7 @@ impl Source for Environment {
if keys.contains(&key) {
let v: Vec<Value> = value
.split(separator)
.map(|s| Value::new(Some(&uri), ValueKind::String(s.to_string())))
.map(|s| Value::new(Some(&uri), ValueKind::String(s.to_owned())))
.collect();
ValueKind::Array(v)
} else {
Expand All @@ -304,7 +304,7 @@ impl Source for Environment {
} else {
let v: Vec<Value> = value
.split(separator)
.map(|s| Value::new(Some(&uri), ValueKind::String(s.to_string())))
.map(|s| Value::new(Some(&uri), ValueKind::String(s.to_owned())))
.collect();
ValueKind::Array(v)
}
Expand Down
36 changes: 18 additions & 18 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ pub enum Unexpected {
impl fmt::Display for Unexpected {
fn fmt(&self, f: &mut fmt::Formatter) -> result::Result<(), fmt::Error> {
match *self {
Unexpected::Bool(b) => write!(f, "boolean `{}`", b),
Unexpected::I64(i) => write!(f, "64-bit integer `{}`", i),
Unexpected::I128(i) => write!(f, "128-bit integer `{}`", i),
Unexpected::U64(i) => write!(f, "64-bit unsigned integer `{}`", i),
Unexpected::U128(i) => write!(f, "128-bit unsigned integer `{}`", i),
Unexpected::Float(v) => write!(f, "floating point `{}`", v),
Unexpected::Str(ref s) => write!(f, "string {:?}", s),
Unexpected::Bool(b) => write!(f, "boolean `{b}`"),
Unexpected::I64(i) => write!(f, "64-bit integer `{i}`"),
Unexpected::I128(i) => write!(f, "128-bit integer `{i}`"),
Unexpected::U64(i) => write!(f, "64-bit unsigned integer `{i}`"),
Unexpected::U128(i) => write!(f, "128-bit unsigned integer `{i}`"),
Unexpected::Float(v) => write!(f, "floating point `{v}`"),
Unexpected::Str(ref s) => write!(f, "string {s:?}"),
Unexpected::Unit => write!(f, "unit value"),
Unexpected::Seq => write!(f, "sequence"),
Unexpected::Map => write!(f, "map"),
Expand Down Expand Up @@ -142,7 +142,7 @@ impl ConfigError {
} else {
""
};
format!("{}{}{}", segment, dot, key)
format!("{segment}{dot}{key}")
};
match self {
Self::Type {
Expand All @@ -168,12 +168,12 @@ impl ConfigError {

#[must_use]
pub(crate) fn prepend_index(self, idx: usize) -> Self {
self.prepend(&format!("[{}]", idx), false)
self.prepend(&format!("[{idx}]"), false)
}
}

/// Alias for a `Result` with the error type set to `ConfigError`.
pub type Result<T> = result::Result<T, ConfigError>;
pub(crate) type Result<T> = result::Result<T, ConfigError>;

// Forward Debug to Display for readable panic! messages
impl fmt::Debug for ConfigError {
Expand All @@ -189,12 +189,12 @@ impl fmt::Display for ConfigError {

ConfigError::PathParse(ref kind) => write!(f, "{}", kind.description()),

ConfigError::Message(ref s) => write!(f, "{}", s),
ConfigError::Message(ref s) => write!(f, "{s}"),

ConfigError::Foreign(ref cause) => write!(f, "{}", cause),
ConfigError::Foreign(ref cause) => write!(f, "{cause}"),

ConfigError::NotFound(ref key) => {
write!(f, "configuration property {:?} not found", key)
write!(f, "configuration property {key:?} not found")
}

ConfigError::Type {
Expand All @@ -203,24 +203,24 @@ impl fmt::Display for ConfigError {
expected,
ref key,
} => {
write!(f, "invalid type: {}, expected {}", unexpected, expected)?;
write!(f, "invalid type: {unexpected}, expected {expected}")?;

if let Some(ref key) = *key {
write!(f, " for key `{}`", key)?;
write!(f, " for key `{key}`")?;
}

if let Some(ref origin) = *origin {
write!(f, " in {}", origin)?;
write!(f, " in {origin}")?;
}

Ok(())
}

ConfigError::FileParse { ref cause, ref uri } => {
write!(f, "{}", cause)?;
write!(f, "{cause}")?;

if let Some(ref uri) = *uri {
write!(f, " in {}", uri)?;
write!(f, " in {uri}")?;
}

Ok(())
Expand Down
Loading

0 comments on commit d71b6d7

Please sign in to comment.