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

make clippy more strict #467

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,39 @@ codegen-units = 1

[lib]
crate-type = ["staticlib", "cdylib", "rlib"]



[lints]
workspace = true

[workspace.lints.clippy]
#perf = { level = "deny", priority = -1 }
#pedantic = { level = "warn", priority = -1 }
#nursery = { level = "warn", priority = -1 }
#cargo = { level = "warn", priority = -1 }
#panic = "deny"
#unwrap_used = "deny"
clone_on_ref_ptr = "warn"
empty_enum_variants_with_brackets = "warn"
empty_structs_with_brackets = "warn"
enum_glob_use = "warn"
error_impl_error = "warn"
format_push_string = "warn"
infinite_loop = "warn"
rc_buffer = "warn"
rc_mutex = "warn"
expect_used = "warn"
missing_docs_in_private_items = "allow"
cargo_common_metadata = "allow" # should be removed if we release our crates to crates.io
cast_possible_truncation = "allow" # should this be on allow?
cast_precision_loss = "allow"
cast_sign_loss = "allow"
cast_possible_wrap = "allow"
or_fun_call = "allow"
multiple_crate_versions = "allow" # should this be on allow?
missing_errors_doc = "allow"
cognitive_complexity = "allow"
float_cmp = "allow" #TODO: this should be changed and f32/f64::EPSILON should be used
doc_markdown = "allow"
too_many_lines = "allow"
5 changes: 3 additions & 2 deletions benches/tree_iterator.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
use std::fs::File;

use criterion::{criterion_group, criterion_main, Criterion};
Expand Down Expand Up @@ -25,7 +26,7 @@ fn wikipedia_main_page(c: &mut Criterion) {
b.iter(|| {
let tree_iterator = TreeIterator::new(&main_document);
let _ = tree_iterator.collect::<Vec<NodeId>>();
})
});
});

group.finish();
Expand All @@ -51,7 +52,7 @@ fn stackoverflow_home(c: &mut Criterion) {
b.iter(|| {
let tree_iterator = TreeIterator::new(&main_document);
let _ = tree_iterator.collect::<Vec<NodeId>>();
})
});
});

group.finish();
Expand Down
3 changes: 3 additions & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
allow-unwrap-in-tests = true
allow-expect-in-tests = true
allow-panic-in-tests = true
4 changes: 4 additions & 0 deletions crates/gosub_bindings/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ gosub_html5 = { path = "../gosub_html5" }

[lib]
crate-type = ["staticlib"]


[lints]
workspace = true
22 changes: 11 additions & 11 deletions crates/gosub_bindings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ use wrapper::node::CNode;
/// to build a render tree. DO NOT take ownership of this pointer in Rust or the
/// universe might collapse.
///
/// Moves an owning pointer to the rendertree using Box::into_raw() to the C API.
/// This pointer MUST be passed to gosub_rendertree_free() after usage for proper cleanup.
/// Moves an owning pointer to the rendertree using `Box::into_raw()` to the C API.
/// This pointer MUST be passed to `gosub_rendertree_free()` after usage for proper cleanup.
#[no_mangle]
pub unsafe extern "C" fn gosub_rendertree_init(html: *const c_char) -> *mut RenderTree {
let html_str = unsafe {
Expand Down Expand Up @@ -50,8 +50,8 @@ pub unsafe extern "C" fn gosub_rendertree_init(html: *const c_char) -> *mut Rend
/// Construct a tree iterator for a render tree and return an owning pointer to it.
///
/// # Safety
/// Moves an owning pointer to the tree iterator using Box::into_raw() to the C API.
/// This pointer MUST be passed to gosub_rendertree_iterator_free() after usage for proper cleanup.
/// Moves an owning pointer to the tree iterator using `Box::into_raw()` to the C API.
/// This pointer MUST be passed to `gosub_rendertree_iterator_free()` after usage for proper cleanup.
#[no_mangle]
pub unsafe extern "C" fn gosub_rendertree_iterator_init(
rendertree: *const RenderTree,
Expand All @@ -60,10 +60,10 @@ pub unsafe extern "C" fn gosub_rendertree_iterator_init(
Box::into_raw(tree_iterator)
}

/// Takes a tree_iterator and returns a non-owning pointer to the next node
/// Takes a `tree_iterator` and returns a non-owning pointer to the next node
///
/// # Safety
/// Takes a tree_iterator pointer (owned by the C API generated by gosub_rendertree_iterator_init())
/// Takes a `tree_iterator` pointer (owned by the C API generated by `gosub_rendertree_iterator_init()`)
/// and modifies it to point to the next tree-order node in the tree. Any heap-allocated data
/// on the current node is free'd before pointing to the next node. Returns a ready-only pointer
/// to the next node.
Expand All @@ -73,16 +73,16 @@ pub unsafe extern "C" fn gosub_rendertree_next_node(
) -> *const Node {
let next = (*tree_iterator).next();
if let Some(next) = next {
next.as_ptr() as *const Node
next.as_ptr().cast_const()
} else {
ptr::null()
}
}

/// Fetch the node data according to the NodeType of the current node.
/// Fetch the node data according to the `NodeType` of the current node.
///
/// # Safety
/// Uses a read-only pointer obtained from gosub_rendertree_next_node()
/// Uses a read-only pointer obtained from `gosub_rendertree_next_node()`
/// and a mutable pointer owned by the C API to write (copy) the contents
/// of the read-only pointer into the mutable pointer.
#[no_mangle]
Expand All @@ -93,7 +93,7 @@ pub unsafe extern "C" fn gosub_rendertree_get_node_data(node: *const Node, c_nod
}
}

/// Free the iterator pointer obtained from gosub_rendertree_iterator_init()
/// Free the iterator pointer obtained from `gosub_rendertree_iterator_init()`
///
/// # Safety
/// This takes ownership of the pointer from the C API and transfers it to Rust so it can
Expand All @@ -103,7 +103,7 @@ pub unsafe extern "C" fn gosub_rendertree_iterator_free(tree_iterator: *mut Tree
let _ = Box::from_raw(tree_iterator);
}

/// Free the rendertree pointer obtained from gosub_rendertree_init()
/// Free the rendertree pointer obtained from `gosub_rendertree_init()`
///
/// # Safety
/// This takes ownership of the pointer from the C API and transfers it to Rust so it can
Expand Down
2 changes: 1 addition & 1 deletion crates/gosub_bindings/src/wrapper.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pub mod node;
pub mod text;

/// Numerical values that map rendertree::NodeType to C
/// Numerical values that map `rendertree::NodeType` to C
#[repr(C)]
pub enum CNodeType {
Root = 0,
Expand Down
2 changes: 2 additions & 0 deletions crates/gosub_bindings/src/wrapper/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ impl Default for CNode {
}

impl CNode {
#[must_use]
pub fn new_root() -> Self {
Self::default()
}

#[must_use]
pub fn new_text(node: &Node, text_node: &TextNode) -> Self {
Self {
tag: CNodeType::Text,
Expand Down
2 changes: 1 addition & 1 deletion crates/gosub_bindings/src/wrapper/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use gosub_rendering::render_tree::text::TextNode;
use std::ffi::c_char;
use std::ffi::CString;

/// This is a C-friendly wrapper around gosub_render_utils::rendertree::text::TextNode
/// This is a C-friendly wrapper around `gosub_render_utils::rendertree::text::TextNode`
/// that converts Rust Strings to owned pointers to pass to the C API.
#[repr(C)]
pub struct CTextNode {
Expand Down
5 changes: 4 additions & 1 deletion crates/gosub_config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@ anyhow = "1.0.86"

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
sqlite = "0.36.1"
ureq = "2.10.1"
ureq = "2.10.1"

[lints]
workspace = true
4 changes: 2 additions & 2 deletions crates/gosub_config/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use thiserror::Error;

/// Parser error that defines an error (message) on the given position
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ParseError {
/// Parse error message
pub message: String,
Expand All @@ -16,7 +16,7 @@ pub struct ParseError {

/// Serious errors and errors from third-party libraries
#[derive(Debug, Error)]
pub enum Error {
pub enum ConfigError {
#[error("config error: {0}")]
Config(String),

Expand Down
Loading