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

Update lints defintion and deny config #74

Merged
merged 16 commits into from
Oct 7, 2024
102 changes: 0 additions & 102 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,105 +4,3 @@ rustdocflags = [
"-Arustdoc::private_intra_doc_links",
"-Drustdoc::broken_intra_doc_links",
]

[target.'cfg(all())']
rustflags = [
# https://doc.rust-lang.org/rustc/lints/index.html
"-Wfuture_incompatible",
"-Wlet_underscore",
"-Wnonstandard-style",
"-Wrust_2018_compatibility",
"-Wrust_2018_idioms",
"-Wrust_2021_compatibility",
"-Wtrivial_casts",
"-Wtrivial_numeric_casts",
"-Wunsafe_code",
"-Wunused",
"-Wunused_import_braces",
"-Wunused_lifetimes",
"-Wunused_macro_rules",
"-Wunused_qualifications",
"-Wunused_tuple_struct_fields",
"-Wwarnings",

# This list is based off Embarks clippy list
# https://github.com/EmbarkStudios/rust-ecosystem/blob/main/lints.rs
#
# You can lookup the motivation for each clippy here:
# https://rust-lang.github.io/rust-clippy/master/index.html
#
# The following lints are pending implementation, as they cause significant code churn
#
# "-Wclippy::string_lit_as_bytes",
#
# We also excluded the lint `clippy::map_unwrap_or` as it considers the pattern `map_or_else(.., ..)` more readable than `map(...).unwrap_or(..)`
# We do not.

"-Aclippy::doc_markdown",
"-Wclippy::await_holding_lock",
"-Wclippy::char_lit_as_u8",
"-Wclippy::checked_conversions",
"-Wclippy::dbg_macro",
"-Wclippy::debug_assert_with_mut_call",
"-Wclippy::disallowed_macros",
"-Wclippy::disallowed_methods",
"-Wclippy::disallowed_types",
"-Wclippy::empty_enum",
"-Wclippy::enum_glob_use",
"-Wclippy::exit",
"-Wclippy::explicit_deref_methods",
"-Wclippy::explicit_into_iter_loop",
"-Wclippy::expl_impl_clone_on_copy",
"-Wclippy::fallible_impl_from",
"-Wclippy::filter_map_next",
"-Wclippy::flat_map_option",
"-Wclippy::float_cmp_const",
"-Wclippy::fn_params_excessive_bools",
"-Wclippy::from_iter_instead_of_collect",
"-Wclippy::if_let_mutex",
"-Wclippy::implicit_clone",
"-Wclippy::imprecise_flops",
"-Wclippy::inefficient_to_string",
"-Wclippy::invalid_upcast_comparisons",
"-Wclippy::large_digit_groups",
"-Wclippy::large_stack_arrays",
"-Wclippy::large_types_passed_by_value",
"-Wclippy::let_unit_value",
"-Wclippy::linkedlist",
"-Wclippy::lossy_float_literal",
"-Wclippy::macro_use_imports",
"-Wclippy::manual_ok_or",
"-Wclippy::map_flatten",
"-Wclippy::match_on_vec_items",
"-Wclippy::match_same_arms",
"-Wclippy::match_wildcard_for_single_variants",
"-Wclippy::match_wild_err_arm",
"-Wclippy::mem_forget",
"-Wclippy::mismatched_target_os",
"-Wclippy::missing_enforced_import_renames",
"-Wclippy::mutex_integer",
"-Wclippy::mut_mut",
"-Wclippy::needless_continue",
"-Wclippy::needless_for_each",
"-Wclippy::needless_pass_by_value",
"-Wclippy::option_option",
"-Wclippy::path_buf_push_overwrite",
"-Wclippy::ptr_as_ptr",
"-Wclippy::rc_mutex",
"-Wclippy::ref_option_ref",
"-Wclippy::rest_pat_in_fully_bound_structs",
"-Wclippy::same_functions_in_if_condition",
"-Wclippy::semicolon_if_nothing_returned",
"-Wclippy::single_match_else",
"-Wclippy::string_add",
"-Wclippy::string_add_assign",
"-Wclippy::string_to_string",
"-Wclippy::todo",
"-Wclippy::trait_duplication_in_bounds",
"-Wclippy::unimplemented",
"-Wclippy::unnested_or_patterns",
"-Wclippy::unused_self",
"-Wclippy::useless_transmute",
"-Wclippy::verbose_file_reads",
"-Wclippy::zero_sized_map_values",
]
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
timeout-minutes: 45
steps:
- uses: actions/checkout@v3
- run: cargo clippy --workspace --all-targets --all-features
- run: cargo clippy --workspace --all-targets --all-features -- -Dwarnings

format:
runs-on: ubuntu-latest
Expand Down
45 changes: 45 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,48 @@ resolver = "2"
chrono-tz = { version = "0.9.0", default-features = false, features = ["std"] }
serde_json = { version = "1.0.117", default-features = false }
serde = { version = "1.0.203", features = ["derive"] }

# use only "allow" and "warn" for lints (both rustc and clippy)
# the Github CI task will fail on warnings but
# we only want the warnings during local development
[workspace.lints.rust]
# Lint groups are set to warn so new lints are used as they become available
future_incompatible = { level = "warn", priority = -1 }
let_underscore = { level = "warn", priority = -1 }
nonstandard-style = { level = "warn", priority = -1 }
rust_2018_compatibility = { level = "warn", priority = -1 }
rust_2018_idioms = { level = "warn", priority = -1 }
rust_2021_compatibility = { level = "warn", priority = -1 }
unused = { level = "warn", priority = -1 }
warnings = { level = "warn", priority = -1 }

# 2024 compatibility is allow for now and will be fixed in a near-future PR
rust_2024_compatibility = { level = "allow", priority = -2 }

# We also warn on a set of individual lints that are ont included in any group
async_fn_in_trait = "warn"
dead_code = "warn"
trivial_casts = "warn"
trivial_numeric_casts = "warn"
unsafe_code = "warn"
unused_import_braces = "warn"
unused_lifetimes = "warn"
unused_macro_rules = "warn"
unused_qualifications = "warn"

[workspace.lints.clippy]
# Lint groups are set to warn so new lints are used as they become available
complexity = { level = "warn", priority = -1 }
correctness = { level = "warn", priority = -1 }
pedantic = { level = "warn", priority = -1 }
perf = { level = "warn", priority = -1 }
style = { level = "warn", priority = -1 }
suspicious = { level = "warn", priority = -1 }

# These lints are explicitly allowed.
missing_errors_doc = "allow" # the Error type is self documenting
map_unwrap_or = "allow" # we prefer to `map(a).unwrap_or(b)` as it's clear what the fallback value is

# These lints are allowed, but we want to deny them over time
missing_panics_doc = "allow"
module_name_repetitions = "allow"
3 changes: 3 additions & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ console = { version = "0.15.8" }
ocpi-tariffs = { version = "0.6.1", path = "../ocpi-tariffs", features = ["ocpi-v211"] }
serde_json.workspace = true
serde.workspace = true

[lints]
workspace = true
25 changes: 13 additions & 12 deletions cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ pub struct Validate {
}

impl Validate {
#[allow(clippy::too_many_lines)]
fn run(self) -> Result<()> {
let (report, cdr, _) = self.args.load_all()?;

Expand Down Expand Up @@ -314,7 +315,7 @@ impl Validate {

table.retain_rows(|v| !v[1].is_empty() || !v[2].is_empty());

println!("{}", table);
println!("{table}");

if !is_valid {
println!(
Expand All @@ -323,13 +324,13 @@ impl Validate {
);

exit(1);
} else {
println!(
"Calculation {} all totals in the CDR.\n",
style("matches").green().bold()
);
}

println!(
"Calculation {} all totals in the CDR.\n",
style("matches").green().bold()
);

Ok(())
}
}
Expand Down Expand Up @@ -365,7 +366,7 @@ impl Analyze {
"Flat",
]);

for period in report.periods.iter() {
for period in &report.periods {
let start_time = period.start_date_time.with_timezone(&time_zone);
let dim = &period.dimensions;

Expand All @@ -379,7 +380,7 @@ impl Analyze {
]);

table.row(&[
"".to_string(),
String::new(),
"Price".to_string(),
to_string_or_default(dim.energy.price.map(|p| p.price)),
to_string_or_default(dim.time.price.map(|p| p.price)),
Expand All @@ -396,19 +397,19 @@ impl Analyze {
report.total_energy.to_string(),
report.total_time.to_string(),
report.total_parking_time.to_string(),
"".to_string(),
String::new(),
]);

table.row(&[
"".to_string(),
String::new(),
"Price".to_string(),
to_string_or_default(report.total_energy_cost.map(|p| p.excl_vat)),
to_string_or_default(report.total_time_cost.map(|p| p.excl_vat)),
to_string_or_default(report.total_parking_cost.map(|p| p.excl_vat)),
to_string_or_default(report.total_fixed_cost.map(|p| p.excl_vat)),
]);

println!("{}", table);
println!("{table}");

Ok(())
}
Expand Down Expand Up @@ -499,7 +500,7 @@ impl Display for Table {
write!(f, "|")?;

for (value, &width) in row.iter().zip(&self.widths) {
write!(f, " {0: <1$} |", value, width)?;
write!(f, " {value: <width$} |")?;
}

writeln!(f)?;
Expand Down
12 changes: 3 additions & 9 deletions deny.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
[advisories]
vulnerability = "deny"
unmaintained = "deny"
notice = "deny"
unsound = "deny"
ignore = []
version = 2
yanked = "warn"

[bans]
multiple-versions = "allow"
Expand All @@ -22,13 +19,10 @@ allow-registry = ["https://github.com/rust-lang/crates.io-index"]
allow-git = []

[licenses]
unlicensed = "deny"
allow-osi-fsf-free = "neither"
copyleft = "deny"
# We want really high confidence when inferring licenses from text
confidence-threshold = 0.93
# (extending this list is only allowed after agreement by TD management)
allow = ["Apache-2.0", "Apache-2.0 WITH LLVM-exception", "MIT"]
allow = ["Apache-2.0", "MIT"]

# ignore the local workspace crates
[licenses.private]
Expand Down
3 changes: 3 additions & 0 deletions ocpi-tariffs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ license.workspace = true
[features]
ocpi-v211 = []

[lints]
workspace = true

[dependencies]
chrono-tz.workspace = true
chrono = { version = "0.4.35", default-features = false, features = ["serde"] }
Expand Down
1 change: 0 additions & 1 deletion ocpi-tariffs/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![deny(missing_docs)]
//! # OCPI Tariffs library
//!
//! Functionality to calculate the (sub)totals of a charge session. Use the
Expand Down
16 changes: 8 additions & 8 deletions ocpi-tariffs/src/ocpi/v211/tariff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ pub struct OcpiPriceComponent {

/// Price per unit (excluding VAT) for this tariff dimension
pub price: Money,
/// Minimum amount to be billed. This unit will be billed in this step_size
/// blocks. For example: if type is time and step_size is 300, then time will
/// Minimum amount to be billed. This unit will be billed in this `step_size`
/// blocks. For example: if type is time and `step_size` is 300, then time will
/// be billed in blocks of 5 minutes, so if 6 minutes is used, 10 minutes (2
/// blocks of step_size) will be billed
/// blocks of `step_size`) will be billed
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes are the result of running cargo clippy --fix with doc_markdown=warn.

pub step_size: u64,
}

Expand All @@ -62,13 +62,13 @@ pub struct OcpiTariffElement {
#[derive(Debug, Copy, PartialEq, Eq, Clone, Hash, Deserialize, Serialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum TariffDimensionType {
/// Defined in kWh, step_size multiplier: 1 Wh
/// Defined in kWh, `step_size` multiplier: 1 Wh
Energy,
/// Flat fee, no unit for step_size
/// Flat fee, no unit for `step_size`
Flat,
/// Time not charging: defined in hours, step_size multiplier: 1 second
/// Time not charging: defined in hours, `step_size` multiplier: 1 second
ParkingTime,
/// Time charging: defined in hours, step_size multiplier: 1 second
/// Time charging: defined in hours, `step_size` multiplier: 1 second
Time,
}

Expand All @@ -80,7 +80,7 @@ pub struct OcpiTariffRestriction {
pub start_time: Option<OcpiTime>,

/// End time of day, for example 19:45, valid until this
/// time of the day. Same syntax as start_time
/// time of the day. Same syntax as `start_time`
pub end_time: Option<OcpiTime>,

/// Start date, for example: 2015-12-24, valid from this day
Expand Down
16 changes: 8 additions & 8 deletions ocpi-tariffs/src/ocpi/v221/tariff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ pub struct OcpiPriceComponent {
/// Optionally specify a VAT percentage for this component.
pub vat: CompatibilityVat,

/// Minimum amount to be billed. This unit will be billed in this step_size
/// blocks. For example: if type is time and step_size is 300, then time will
/// Minimum amount to be billed. This unit will be billed in this `step_size`
/// blocks. For example: if type is time and `step_size` is 300, then time will
/// be billed in blocks of 5 minutes, so if 6 minutes is used, 10 minutes (2
/// blocks of step_size) will be billed
/// blocks of `step_size`) will be billed
pub step_size: u64,
}

Expand Down Expand Up @@ -104,13 +104,13 @@ pub struct OcpiTariffElement {
#[derive(Debug, Copy, PartialEq, Eq, Clone, Hash, Deserialize, Serialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum TariffDimensionType {
/// Defined in kWh, step_size multiplier: 1 Wh
/// Defined in kWh, `step_size` multiplier: 1 Wh
Energy,
/// Flat fee, no unit for step_size
/// Flat fee, no unit for `step_size`
Flat,
/// Time not charging: defined in hours, step_size multiplier: 1 second
/// Time not charging: defined in hours, `step_size` multiplier: 1 second
ParkingTime,
/// Time charging: defined in hours, step_size multiplier: 1 second
/// Time charging: defined in hours, `step_size` multiplier: 1 second
Time,
}

Expand All @@ -122,7 +122,7 @@ pub struct OcpiTariffRestriction {
pub start_time: Option<OcpiTime>,

/// End time of day, for example 19:45, valid until this
/// time of the day. Same syntax as start_time
/// time of the day. Same syntax as `start_time`
pub end_time: Option<OcpiTime>,

/// Start date, for example: 2015-12-24, valid from this day
Expand Down
Loading
Loading