Skip to content

Commit

Permalink
fix(frontmatter-gen): 🐛 cleaning up
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastienrousseau committed Nov 17, 2024
1 parent 18faa37 commit 46dcd09
Show file tree
Hide file tree
Showing 10 changed files with 269 additions and 147 deletions.
138 changes: 133 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ ssg = [ # Full SSG functionality
"dep:pulldown-cmark",
"dep:tokio",
"dep:dtt",
"dep:log",
"dep:url",
]
logging = ["dep:log"] # Optional logging feature
Expand Down Expand Up @@ -152,11 +153,138 @@ path = "examples/types_examples.rs"
# -----------------------------------------------------------------------------
# Criterion Benchmark
# -----------------------------------------------------------------------------
[[bench]] # Benchmarking configuration.
name = "frontmatter_benchmark" # Name of the benchmark.
harness = false # Disable the default benchmark harness.

[[bench]]
name = "frontmatter_benchmark"
harness = false
# -----------------------------------------------------------------------------
# Documentation Configuration
# -----------------------------------------------------------------------------
[package.metadata.docs.rs]
# Settings for building and hosting documentation on docs.rs.
all-features = true # Build documentation with all features enabled
rustdoc-args = ["--cfg", "docsrs"] # Arguments passed to `rustdoc` when building the documentation
targets = ["x86_64-unknown-linux-gnu"] # Default target platform for the docs

# -----------------------------------------------------------------------------
# Linting Configuration
# -----------------------------------------------------------------------------
[lints.rust]
# Linting rules for the project.

## Warnings
missing_copy_implementations = "warn" # Warn if types can implement `Copy` but don’t
missing_docs = "warn" # Warn if public items lack documentation
unstable_features = "warn" # Warn on the usage of unstable features
unused_extern_crates = "warn" # Warn about unused external crates
unused_results = "warn" # Warn if a result type is unused (e.g., errors ignored)

## Allowances
bare_trait_objects = "allow" # Allow bare trait objects (e.g., `Box<dyn Trait>`)
elided_lifetimes_in_paths = "allow" # Allow lifetimes to be elided in paths
non_camel_case_types = "allow" # Allow non-camel-case types
non_upper_case_globals = "allow" # Allow non-uppercase global variables
trivial_bounds = "allow" # Allow trivial bounds in trait definitions
unsafe_code = "allow" # Allow the usage of unsafe code blocks

## Forbidden
missing_debug_implementations = "forbid" # Forbid missing `Debug` implementations
non_ascii_idents = "forbid" # Forbid non-ASCII identifiers
unreachable_pub = "forbid" # Forbid unreachable `pub` items

## Denials
dead_code = "deny" # Deny unused, dead code in the project
deprecated_in_future = "deny" # Deny code that will be deprecated in the future
ellipsis_inclusive_range_patterns = "deny" # Deny usage of inclusive ranges in match patterns (`...`)
explicit_outlives_requirements = "deny" # Deny unnecessary lifetime outlives requirements
future_incompatible = { level = "deny", priority = -1 } # Handle future compatibility issues
keyword_idents = { level = "deny", priority = -1 } # Deny usage of keywords as identifiers
macro_use_extern_crate = "deny" # Deny macro use of `extern crate`
meta_variable_misuse = "deny" # Deny misuse of meta variables in macros
missing_fragment_specifier = "deny" # Deny missing fragment specifiers in macros
noop_method_call = "deny" # Deny method calls that have no effect
rust_2018_idioms = { level = "deny", priority = -1 } # Enforce Rust 2018 idioms
rust_2021_compatibility = { level = "deny", priority = -1 } # Enforce Rust 2021 compatibility
single_use_lifetimes = "deny" # Deny lifetimes that are used only once
trivial_casts = "deny" # Deny trivial casts (e.g., `as` when unnecessary)
trivial_numeric_casts = "deny" # Deny trivial numeric casts (e.g., `i32` to `i64`)
unused = { level = "deny", priority = -1 } # Deny unused code, variables, etc.
unused_features = "deny" # Deny unused features
unused_import_braces = "deny" # Deny unnecessary braces around imports
unused_labels = "deny" # Deny unused labels in loops
unused_lifetimes = "deny" # Deny unused lifetimes
unused_macro_rules = "deny" # Deny unused macros
unused_qualifications = "deny" # Deny unnecessary type qualifications
variant_size_differences = "deny" # Deny enum variants with significant size differences

# -----------------------------------------------------------------------------
# Clippy Configuration
# -----------------------------------------------------------------------------
[package.metadata.clippy]
# Clippy lint configuration for enhanced code analysis.
warn-lints = [
"clippy::all", # Enable all common Clippy lints
"clippy::pedantic", # Enable pedantic lints for stricter checking
"clippy::cargo", # Enable lints specific to cargo
"clippy::nursery", # Enable experimental lints from Clippy’s nursery
"clippy::complexity", # Warn on code complexity and suggest improvements
"clippy::correctness", # Ensure code correctness, flagging potential issues
"clippy::perf", # Lints that catch performance issues
"clippy::style", # Suggest stylistic improvements
"clippy::suspicious", # Detect suspicious code patterns
"clippy::module_name_repetitions", # Avoid repeating module names in the crate name
]

# Customize Clippy to allow certain less critical lints.
allow-lints = [
"clippy::module_inception", # Allow modules with the same name as their parents
"clippy::too_many_arguments", # Allow functions with more than 7 arguments if justified
"clippy::missing_docs_in_private_items", # Skip requiring documentation for private items
]

# Enforce specific warnings and errors more strictly.
deny-lints = [
"clippy::unwrap_used", # Deny the use of unwrap to ensure error handling
"clippy::expect_used", # Deny the use of expect to avoid improper error handling
]

# -----------------------------------------------------------------------------
# Profiles
# -----------------------------------------------------------------------------
[profile.dev]
# Development profile configuration for fast builds and debugging.
codegen-units = 256 # Increase codegen units for faster compilation
debug = true # Enable debugging symbols
debug-assertions = true # Enable debug assertions
incremental = true # Enable incremental compilation
lto = false # Disable link-time optimization for development
opt-level = 0 # No optimizations in development
overflow-checks = true # Enable overflow checks for arithmetic operations
panic = 'unwind' # Enable unwinding for panics (useful in development)
rpath = false # Disable rpath generation
strip = false # Do not strip symbols in development builds

[profile.bench]
debug = true
[profile.release]
# Release profile configuration for optimized builds.
codegen-units = 1 # Reduce codegen units for better performance
debug = false # Disable debug symbols in release builds
debug-assertions = false # Disable debug assertions
incremental = false # Disable incremental compilation for optimal binary size
lto = true # Enable link-time optimization for smaller and faster binaries
opt-level = "z" # Optimize for binary size
overflow-checks = false # Disable overflow checks for performance
panic = "abort" # Use abort on panic for minimal overhead
rpath = false # Disable rpath generation
strip = "symbols" # Strip symbols for smaller binary size

[profile.test]
# Test profile configuration for debugging and development.
codegen-units = 256 # Increase codegen units for faster test builds
debug = true # Enable debugging symbols for test builds
debug-assertions = true # Enable debug assertions for tests
incremental = true # Enable incremental compilation for tests
lto = false # Disable link-time optimization during testing
opt-level = 0 # No optimizations in test builds
overflow-checks = true # Enable overflow checks for tests
rpath = false # Disable rpath generation
strip = false # Do not strip symbols in test builds
4 changes: 2 additions & 2 deletions examples/lib_examples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ fn to_format_example() -> Result<(), FrontmatterError> {
println!("---------------------------------------------");

let mut frontmatter = Frontmatter::new();
frontmatter.insert("title".to_string(), "My Post".into());
frontmatter.insert("date".to_string(), "2025-09-09".into());
let _ = frontmatter.insert("title".to_string(), "My Post".into());
let _ = frontmatter.insert("date".to_string(), "2025-09-09".into());

let yaml = to_format(&frontmatter, Format::Yaml)?;
println!(" ✅ Converted frontmatter to YAML:\n{}", yaml);
Expand Down
14 changes: 7 additions & 7 deletions examples/parser_examples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ fn parse_json_example() -> Result<(), FrontmatterError> {
/// Creates a sample frontmatter for examples
fn create_sample_frontmatter() -> Frontmatter {
let mut frontmatter = Frontmatter::new();
frontmatter.insert(
let _ = frontmatter.insert(
"title".to_string(),
Value::String("My Post".to_string()),
);
frontmatter.insert(
let _ = frontmatter.insert(
"date".to_string(),
Value::String("2025-09-09".to_string()),
);
Expand Down Expand Up @@ -158,20 +158,20 @@ fn ssg_parser_examples() -> Result<(), FrontmatterError> {

// Create a complex frontmatter with SSG-specific fields
let mut frontmatter = Frontmatter::new();
frontmatter.insert(
let _ = frontmatter.insert(
"title".to_string(),
Value::String("My Blog Post".to_string()),
);
frontmatter.insert(
let _ = frontmatter.insert(
"template".to_string(),
Value::String("post".to_string()),
);
frontmatter.insert(
let _ = frontmatter.insert(
"layout".to_string(),
Value::String("blog".to_string()),
);
frontmatter.insert("draft".to_string(), Value::Boolean(false));
frontmatter.insert(
let _ = frontmatter.insert("draft".to_string(), Value::Boolean(false));
let _ = frontmatter.insert(
"tags".to_string(),
Value::Array(vec![
Value::String("rust".to_string()),
Expand Down
24 changes: 12 additions & 12 deletions examples/types_examples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ fn value_examples() -> Result<(), Box<dyn std::error::Error>> {

// Object value example
let mut fm = Frontmatter::new();
fm.insert("key".to_string(), Value::String("value".to_string()));
let _ = fm.insert("key".to_string(), Value::String("value".to_string()));
let object_value = Value::Object(Box::new(fm.clone()));
println!(" ✅ Object value: {:?}", object_value);
assert!(object_value.is_object());
Expand All @@ -106,11 +106,11 @@ fn frontmatter_examples() -> Result<(), Box<dyn std::error::Error>> {
let mut frontmatter = Frontmatter::new();

// Insert and retrieve values
frontmatter.insert(
let _ = frontmatter.insert(
"title".to_string(),
Value::String("My Post".to_string()),
);
frontmatter.insert("views".to_string(), Value::Number(100.0));
let _ = frontmatter.insert("views".to_string(), Value::Number(100.0));
println!(" ✅ Frontmatter with two entries: {:?}", frontmatter);

let title = frontmatter.get("title").unwrap().as_str().unwrap();
Expand All @@ -119,7 +119,7 @@ fn frontmatter_examples() -> Result<(), Box<dyn std::error::Error>> {
println!(" Views: {}", views);

// Test removal
frontmatter.remove("views");
let _ = frontmatter.remove("views");
println!(
" ✅ Frontmatter after removing 'views': {:?}",
frontmatter
Expand All @@ -139,20 +139,20 @@ fn ssg_type_examples() -> Result<(), Box<dyn std::error::Error>> {
let mut frontmatter = Frontmatter::new();

// Add SSG-specific metadata
frontmatter.insert(
let _ = frontmatter.insert(
"title".to_string(),
Value::String("My Blog Post".to_string()),
);
frontmatter.insert(
let _ = frontmatter.insert(
"template".to_string(),
Value::String("post".to_string()),
);
frontmatter.insert(
let _ = frontmatter.insert(
"layout".to_string(),
Value::String("blog".to_string()),
);
frontmatter.insert("draft".to_string(), Value::Boolean(false));
frontmatter.insert(
let _ = frontmatter.insert("draft".to_string(), Value::Boolean(false));
let _ = frontmatter.insert(
"tags".to_string(),
Value::Array(vec![
Value::String("rust".to_string()),
Expand All @@ -162,15 +162,15 @@ fn ssg_type_examples() -> Result<(), Box<dyn std::error::Error>> {

// Add nested metadata
let mut metadata = Frontmatter::new();
metadata.insert(
let _ = metadata.insert(
"author".to_string(),
Value::String("John Doe".to_string()),
);
metadata.insert(
let _ = metadata.insert(
"category".to_string(),
Value::String("Programming".to_string()),
);
frontmatter.insert(
let _ = frontmatter.insert(
"metadata".to_string(),
Value::Object(Box::new(metadata)),
);
Expand Down
4 changes: 2 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ impl Config {
self.validate_path(serve_dir, "serve_dir")?;
}

Url::parse(&self.base_url).map_err(|_| {
let _ = Url::parse(&self.base_url).map_err(|_| {
ConfigError::InvalidUrl(self.base_url.clone())
})?;

Expand Down Expand Up @@ -423,7 +423,7 @@ impl Config {
}

/// Builder for creating Config instances
#[derive(Default)]
#[derive(Default, Debug)]
pub struct ConfigBuilder {
site_name: Option<String>,
site_title: Option<String>,
Expand Down
10 changes: 5 additions & 5 deletions src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl<K: Eq + std::hash::Hash + Clone, V> SizeCache<K, V> {
fn insert(&mut self, key: K, value: V) -> Option<V> {
if self.items.len() >= self.max_size {
if let Some(old_key) = self.items.keys().next().cloned() {
self.items.remove(&old_key);
let _ = self.items.remove(&old_key);
}
}
self.items.insert(key, value)
Expand Down Expand Up @@ -179,7 +179,7 @@ impl Engine {
)?;

if let Some(name) = path.file_stem() {
templates.insert(
let _ = templates.insert(
name.to_string_lossy().into_owned(),
content,
);
Expand Down Expand Up @@ -216,7 +216,7 @@ impl Engine {
if path.extension().map_or(false, |ext| ext == "md") {
let content =
self.process_content_file(&path, config).await?;
content_cache.insert(path.clone(), content);
let _ = content_cache.insert(path.clone(), content);

#[cfg(feature = "logging")]
log::debug!(
Expand Down Expand Up @@ -347,7 +347,7 @@ impl Engine {
stack.push((path, dest_path));
} else {
// Copy files directly.
fs::copy(&path, &dest_path).await?;
let _ = fs::copy(&path, &dest_path).await?;
}
}
}
Expand Down Expand Up @@ -414,7 +414,7 @@ mod tests {
///
/// This function creates the necessary `content`, `templates`, and `public` directories
/// within a temporary folder and returns the `TempDir` instance along with a test `Config`.
pub async fn setup_test_directory(
async fn setup_test_directory(
) -> Result<(tempfile::TempDir, Config)> {
let temp_dir = tempdir()?;
let base_path = temp_dir.path();
Expand Down
Loading

0 comments on commit 46dcd09

Please sign in to comment.