Skip to content

Commit

Permalink
fix(libmake): 🐛 fix lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastienrousseau committed Mar 16, 2024
1 parent 179fd7f commit e1ccb5e
Show file tree
Hide file tree
Showing 17 changed files with 304 additions and 246 deletions.
12 changes: 3 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ tempfile = "3.10.1"
toml = "0.8.11"
vrd = "0.0.6"
xtasks = "0.0.2"
uuid ={ version = "1.7.0", features = ["v4"] }

# Unix platforms use OpenSSL for now to provide SSL functionality
[target.'cfg(all(unix, not(target_os = "macos")))'.dependencies]
Expand All @@ -92,7 +93,7 @@ default = []

## Forbid
missing_debug_implementations = "forbid"
missing_docs = "forbid"
missing_docs = "warn"
non_ascii_idents = "forbid"
unreachable_pub = "forbid"
unsafe_code = "forbid"
Expand All @@ -115,8 +116,6 @@ single_use_lifetimes = "deny"
trivial_casts = "deny"
trivial_numeric_casts = "deny"
unused = "deny"
# unused_crate_dependencies = "deny"
# unused_extern_crates = "deny"
unused_features = "deny"
unused_import_braces = "deny"
unused_labels = "deny"
Expand All @@ -126,6 +125,7 @@ unused_qualifications = "deny"
variant_size_differences = "deny"

[lints.clippy]

## Allow
blocks_in_conditions = "allow"
cognitive_complexity = "allow"
Expand Down Expand Up @@ -157,12 +157,9 @@ mem_forget = "deny"
mut_mut = "deny"
mutex_integer = "deny"
nonstandard_macro_braces = "deny"
nursery = "deny"
option_if_let_else = "deny"
panic = "deny"
pedantic = "deny"
print_stderr = "deny"
print_stdout = "deny"
range_minus_one = "deny"
rc_buffer = "deny"
rc_mutex = "deny"
Expand All @@ -181,16 +178,13 @@ unneeded_field_pattern = "deny"
unreachable = "deny"
unused_unit = "deny"
unwrap_used = "deny"
use_debug = "deny"
use_self = "deny"
used_underscore_binding = "deny"
useless_conversion = "deny"
vec_init_then_push = "deny"
verbose_file_reads = "deny"
wildcard_dependencies = "deny"
wildcard_imports = "deny"
wrong_pub_self_convention = "deny"
wrong_self_convention = "deny"

[profile.dev]
codegen-units = 256
Expand Down
22 changes: 18 additions & 4 deletions benches/criterion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,30 @@
//! Running this benchmark will provide performance metrics for the `run` function
//! from the `libmake` crate, helping you evaluate and optimize its performance.

//! This crate is responsible for benchmarking various components of the application.
#![allow(missing_docs)]
extern crate criterion;
extern crate libmake;

use criterion::{criterion_group, criterion_main, Criterion};
use libmake::run;

/// Benchmark function for the `run` function from the libmake library.
///
/// This function measures the performance of the `run` function.
///
/// # Arguments
///
/// * `c` - A mutable reference to a `Criterion` struct.
fn libmake_benchmark(c: &mut Criterion) {
c.bench_function("libmake", |b| b.iter(run));
}

criterion_group!(benches, libmake_benchmark);
// Entry point for all benchmarks.
criterion_group! {
// Name of the group.
name = benches;
// Description of the group.
config = Criterion::default();
// Targets of the group.
targets = libmake_benchmark,
}
// Run benchmarks
criterion_main!(benches);
6 changes: 3 additions & 3 deletions examples/example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
// SPDX-License-Identifier: Apache-2.0 OR MIT indicates dual licensing under Apache 2.0 or MIT licenses.
// Copyright © 2024 LibMake. All rights reserved.

//! This is an example crate for LibMake.
//! This is an example crate for `LibMake`.
//!
//! This crate provides various modules and examples for demonstrating the functionality
//! of LibMake. Each module focuses on a specific feature or functionality.
//! of `LibMake`. Each module focuses on a specific feature or functionality.
//!
//! Copyright © 2024 LibMake. All rights reserved.
//! Copyright © 2024 `LibMake`. All rights reserved.
//!
//! Dual-licensed under the terms of the Apache License, Version 2.0, or the MIT License,
//! at your option. See the 'LICENSE' file for details.
Expand Down
11 changes: 8 additions & 3 deletions examples/generate_from_csv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ pub(crate) fn main() {
let csv_file_path = "./tests/data/mylibrary.csv";

// Attempt to generate template files from the specified CSV file.
// If successful, it indicates that the generation process worked as expected.
generate_from_csv(csv_file_path)
.expect("Failed to generate the template files");
match generate_from_csv(csv_file_path) {
Ok(()) => {
println!("Template files generated successfully!");
}
Err(err) => {
eprintln!("Failed to generate the template files: {err}");
}
}
}
7 changes: 4 additions & 3 deletions examples/generate_from_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ pub(crate) fn main() {
let json_file_path = "./tests/data/mylibrary.json";

// Generate template files based on the data in the JSON file.
// If the generation process fails, an error message is printed.
generate_from_json(json_file_path)
.expect("Failed to generate the template files");
// If the generation process fails, print an error message.
if let Err(err) = generate_from_json(json_file_path) {
eprintln!("Failed to generate the template files: {err}");
}
}
7 changes: 4 additions & 3 deletions examples/generate_from_toml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ pub(crate) fn main() {
let toml_file_path = "./tests/data/mylibrary.toml";

// Generate template files based on the configuration in the TOML file.
// If generation fails, it will print an error message.
generate_from_toml(toml_file_path)
.expect("Failed to generate the template files");
// If generation fails, print an error message.
if let Err(err) = generate_from_toml(toml_file_path) {
eprintln!("Failed to generate the template files: {err}");
}
}
5 changes: 3 additions & 2 deletions examples/generate_from_yaml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub(crate) fn main() {
let yaml_file_path = "./tests/data/mylibrary.yaml";

// Generate template files from the specified YAML file.
generate_from_yaml(yaml_file_path)
.expect("Failed to generate the template files");
if let Err(err) = generate_from_yaml(yaml_file_path) {
eprintln!("Failed to generate the template files: {err}");
}
}
28 changes: 24 additions & 4 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ use crate::generator::{
generate_from_json, generate_from_toml, generate_from_yaml,
};
use clap::ArgMatches;
use dtt::DateTime;
use rlg::{log_format::LogFormat, log_level::LogLevel, macro_log};
use std::error::Error;

/// Processes the command line arguments provided to the program.
Expand All @@ -36,6 +38,11 @@ use std::error::Error;
pub fn process_arguments(
matches: &ArgMatches,
) -> Result<(), Box<dyn Error>> {
// Generating a new date and time and a new UUID.
let date = DateTime::new();
let iso = date.iso_8601;
let uuid = uuid::Uuid::new_v4().to_string();

// Extracting optional argument values from the parsed matches.
let author = matches.get_one::<String>("author").cloned();
let build = matches.get_one::<String>("build").cloned();
Expand All @@ -57,8 +64,7 @@ pub fn process_arguments(
let website = matches.get_one::<String>("website").cloned();

// Check which subcommand was used and perform the corresponding action.
if matches.contains_id("csv") {
let csv_file_path = matches.get_one::<String>("csv").unwrap();
if let Some(csv_file_path) = matches.get_one::<String>("csv") {
generate_from_csv(csv_file_path)?;
} else if let Some(yaml_file_path) =
matches.get_one::<String>("yml")
Expand Down Expand Up @@ -95,9 +101,23 @@ pub fn process_arguments(
website,
};
generate_files(params)?;
println!("\n\nTemplate files generated successfully!");
macro_log!(
&uuid,
&iso,
&LogLevel::INFO,
"args",
"Template files generated successfully!",
&LogFormat::CLF
);
} else {
println!("❌ No arguments provided. Please provide the required arguments to generate the template files.");
macro_log!(
&uuid,
&iso,
&LogLevel::ERROR,
"args",
"No arguments provided. Please provide the required arguments to generate the template files.",
&LogFormat::CLF
);
}

Ok(())
Expand Down
74 changes: 36 additions & 38 deletions src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ impl FileGenerationParams {
/// or other I/O-related errors.
///
pub fn create_directory(path: &Path) -> io::Result<()> {
fs::create_dir(path).or_else(|e| match e.kind() {
fs::create_dir_all(path).or_else(|e| match e.kind() {
io::ErrorKind::AlreadyExists => Ok(()),
_ => Err(e),
})
Expand All @@ -223,28 +223,27 @@ pub fn create_template_folder() -> io::Result<()> {
// println!("Creating template directory: {:?}", template_dir_path);
create_directory(&template_dir_path)?;
let url = "https://raw.githubusercontent.com/sebastienrousseau/libmake/main/template/";
let files =
[
"AUTHORS.tpl",
"build.tpl",
"Cargo.tpl",
"ci.tpl",
"CONTRIBUTING.tpl",
"criterion.tpl",
"deepsource.tpl",
"deny.tpl",
"example.tpl",
"gitignore.tpl",
"lib.tpl",
"loggers.tpl",
"macros.tpl",
"main.tpl",
"README.tpl",
"rustfmt.tpl",
"TEMPLATE.tpl",
"test.tpl",
"test_loggers.tpl",
];
let files = [
"AUTHORS.tpl",
"build.tpl",
"Cargo.tpl",
"ci.tpl",
"CONTRIBUTING.tpl",
"criterion.tpl",
"deepsource.tpl",
"deny.tpl",
"example.tpl",
"gitignore.tpl",
"lib.tpl",
"loggers.tpl",
"macros.tpl",
"main.tpl",
"README.tpl",
"rustfmt.tpl",
"TEMPLATE.tpl",
"test.tpl",
"test_loggers.tpl",
];
for file in &files {
let file_path = template_dir_path.join(file);
// Check if the file already exists
Expand Down Expand Up @@ -351,15 +350,14 @@ pub fn generate_files(params: FileGenerationParams) -> io::Result<()> {
create_template_folder()?;

// Define the subdirectories to be created within the project directory
let subdirectories =
[
"src",
"benches",
"examples",
"tests",
".github/",
".github/workflows",
];
let subdirectories = [
"src",
"benches",
"examples",
"tests",
".github/",
".github/workflows",
];

// Iterate over the subdirectories and create them
for subdir in &subdirectories {
Expand Down Expand Up @@ -643,9 +641,9 @@ pub fn generate_from_json(path: &str) -> std::io::Result<()> {
pub fn generate_from_yaml(path: &str) -> std::io::Result<()> {
let contents = fs::read_to_string(path)?;
let params: FileGenerationParams = serde_yaml::from_str(&contents)
.map_err(
|e| std::io::Error::new(std::io::ErrorKind::Other, e)
)?;
.map_err(|e| {
std::io::Error::new(std::io::ErrorKind::Other, e)
})?;
generate_files(params)?;
Ok(())
}
Expand Down Expand Up @@ -684,9 +682,9 @@ pub fn generate_from_yaml(path: &str) -> std::io::Result<()> {
pub fn generate_from_toml(path: &str) -> std::io::Result<()> {
let contents = fs::read_to_string(path)?;
let params: FileGenerationParams = toml::from_str(&contents)
.map_err(
|e| std::io::Error::new(std::io::ErrorKind::Other, e)
)?;
.map_err(|e| {
std::io::Error::new(std::io::ErrorKind::Other, e)
})?;
generate_files(params)?;
Ok(())
}
Expand Down
Loading

0 comments on commit e1ccb5e

Please sign in to comment.