Skip to content

Commit

Permalink
refactor: migrate clippy lints into Cargo.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
open-schnick committed Sep 3, 2024
1 parent fbfed2b commit d69e420
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 38 deletions.
71 changes: 71 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,74 @@ opentelemetry-datadog = { version = "0.10.0", features = ["reqwest-client"] }
opentelemetry_sdk = "0.22.1"
regex = "1.10.3"
smoothy = "0.4.4"

[lints.rust]
missing_docs = "deny"

[lints.rustdoc]
broken_intra_doc_links = "deny"
private_intra_doc_links = "deny"
private_doc_tests = "warn"
invalid_codeblock_attributes = "deny"
invalid_html_tags = "deny"
invalid_rust_codeblocks = "deny"
bare_urls = "deny"
unescaped_backticks = "deny"
redundant_explicit_links = "deny"

[lints.clippy]
# enable more lint groups
pedantic = { level = "deny", priority = -1 }
nursery = { level = "deny", priority = -1 }
# enable extra restriction lints
as_conversions = "deny"
as_underscore = "deny"
clone_on_ref_ptr = "deny"
dbg_macro = "deny"
deref_by_slicing = "deny"
else_if_without_else = "deny"
empty_drop = "deny"
empty_structs_with_brackets = "deny"
error_impl_error = "deny"
expect_used = "deny"
panic = "deny"
todo = "deny"
try_err = "deny"
unimplemented = "deny"
unreachable = "deny"
unwrap_in_result = "deny"
unwrap_used = "deny"
format_push_string = "deny"
if_then_some_else_none = "deny"
indexing_slicing = "deny"
integer_division = "deny"
let_underscore_must_use = "deny"
let_underscore_untyped = "deny"
mem_forget = "deny"
missing_assert_message = "deny"
mod_module_files = "deny"
mixed_read_write_in_expression = "deny"
multiple_inherent_impl = "deny"
needless_raw_strings = "deny"
print_stderr = "deny"
print_stdout = "deny"
pub_without_shorthand = "deny"
same_name_method = "deny"
semicolon_outside_block = "deny"
shadow_reuse = "deny"
string_add = "deny"
string_slice = "deny"
string_to_string = "deny"
unnecessary_self_imports = "deny"
unneeded_field_pattern = "deny"
wildcard_enum_match_arm = "deny"
missing_errors_doc = "deny"
missing_panics_doc = "deny"
ignored_unit_patterns = "deny"
doc_markdown = "deny"
needless_pass_by_value = "deny"
redundant_pub_crate = "deny"
# allow some lints
module_name_repetitions = "allow"
tests_outside_test_module = "allow"

2 changes: 2 additions & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
allow-unwrap-in-tests = true
allow-expect-in-tests = true
3 changes: 2 additions & 1 deletion src/formatting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::{
};
use chrono::{DateTime, Utc};
use serde_json::{Map, Value};
use std::fmt::Write;
use tracing::Level;

/// All the data required to create a Datadog-compatible log
Expand Down Expand Up @@ -33,7 +34,7 @@ impl DatadogLog {
if field.name != "message" {
let value = field.value.trim_matches('\"');

message.push_str(&format!(" {}={}", field.name, value));
write!(message, " {}={}", field.name, value).expect("Failed to write to message");
log.insert(format!("fields.{}", &field.name), value.into());
}
}
Expand Down
35 changes: 2 additions & 33 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,44 +1,13 @@
#![doc = include_str!("../README.md")]
#![deny(
rust_2018_idioms,
unused_must_use,
clippy::nursery,
clippy::pedantic,
clippy::perf,
clippy::cargo,
clippy::correctness,
clippy::dbg_macro,
clippy::else_if_without_else,
clippy::empty_drop,
clippy::empty_structs_with_brackets,
clippy::expect_used,
clippy::if_then_some_else_none,
clippy::indexing_slicing,
clippy::integer_division,
clippy::multiple_inherent_impl,
clippy::panic,
clippy::print_stderr,
clippy::print_stdout,
clippy::same_name_method,
clippy::string_to_string,
clippy::todo,
clippy::try_err,
clippy::unimplemented,
clippy::unnecessary_self_imports,
clippy::unreachable,
clippy::unwrap_used,
clippy::wildcard_enum_match_arm,
missing_docs
)]
#![allow(clippy::module_name_repetitions)]
// Disable certain lints in tests
#![cfg_attr(
test,
allow(
clippy::pedantic,
clippy::as_conversions,
clippy::indexing_slicing,
clippy::unwrap_used
clippy::unwrap_used,
clippy::unwrap_in_result
)
)]

Expand Down
4 changes: 2 additions & 2 deletions tests/otel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ fn works_with_otel_stack() {
#[instrument(fields(hello = "world"))]
fn some_test(value: &str) {
info!(ola = "salve", value, "Bla {value}");
some_test1()
some_test1();
}

#[instrument(fields(world = "world"))]
fn some_test1() {
debug!(ola = "salve", "Hello");
some_test2()
some_test2();
}

#[instrument()]
Expand Down
4 changes: 2 additions & 2 deletions tests/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ fn works() {
#[instrument(fields(hello = "world"))]
fn some_test(value: &str) {
info!(ola = "salve", value, "Bla {value}");
some_test1()
some_test1();
}

#[instrument(fields(world = "world"))]
fn some_test1() {
debug!(ola = "salve", "Hello");
some_test2()
some_test2();
}

#[instrument()]
Expand Down

0 comments on commit d69e420

Please sign in to comment.