Add git hooks and clean up

embedded
Luke D. Jones 2023-01-16 14:31:59 +13:00
parent 1bc587147f
commit 8a5194e390
14 changed files with 273 additions and 30 deletions

12
.cargo-husky/hooks/pre-commit Executable file
View File

@ -0,0 +1,12 @@
#!/bin/sh
set -e
echo '+cargo +nightly fmt --all -- --check'
cargo +nightly fmt --all -- --check
echo '+cargo clippy --all -- -D warnings'
cargo clippy --all -- -D warnings
echo '+cargo test --all'
cargo test --all
echo '+cargo cranky'
cargo cranky

10
.cargo-husky/hooks/pre-push Executable file
View File

@ -0,0 +1,10 @@
#!/bin/sh
set -e
echo '+cargo +nightly fmt --all -- --check'
cargo +nightly fmt --all -- --check
echo '+cargo clippy --all -- -D warnings'
cargo clippy --all -- -D warnings
echo '+cargo cranky'
cargo cranky

21
Cargo.lock generated
View File

@ -19,6 +19,12 @@ version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "cargo-husky"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b02b629252fe8ef6460461409564e2c21d0c8e77e0944f3d189ff06c4e932ad"
[[package]]
name = "cfg-if"
version = "1.0.0"
@ -70,7 +76,7 @@ dependencies = [
name = "gameplay"
version = "0.11.0"
dependencies = [
"glam 0.20.5",
"glam",
"log",
"sound-sdl2",
"sound-traits",
@ -114,12 +120,6 @@ dependencies = [
"wasi",
]
[[package]]
name = "glam"
version = "0.20.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f43e957e744be03f5801a55472f593d43fabdebf25a4585db250f04d86b1675f"
[[package]]
name = "glam"
version = "0.21.3"
@ -274,7 +274,7 @@ name = "render-soft"
version = "0.9.1"
dependencies = [
"gameplay",
"glam 0.20.5",
"glam",
"render-traits",
"wad",
]
@ -290,6 +290,7 @@ dependencies = [
name = "room4doom"
version = "0.11.0"
dependencies = [
"cargo-husky",
"dirs",
"env_logger",
"finale-doom",
@ -356,7 +357,7 @@ dependencies = [
name = "sound-nosnd"
version = "0.1.0"
dependencies = [
"glam 0.21.3",
"glam",
"log",
"serde",
"sound-traits",
@ -367,7 +368,7 @@ dependencies = [
name = "sound-sdl2"
version = "0.1.0"
dependencies = [
"glam 0.21.3",
"glam",
"log",
"sdl2",
"serde",

View File

@ -54,6 +54,11 @@ dirs = "~4.0"
toml = "0.5"
serde = { version = "1.0", features = ["serde_derive"] }
[workspace.dependencies.cargo-husky]
version = "1"
default-features = false
features = ["user-hooks"]
[profile.release]
lto = true
debug = false

121
Cranky.toml Normal file
View File

@ -0,0 +1,121 @@
# https://github.com/ericseppanen/cargo-cranky
# cargo install cargo-cranky && cargo cranky
error = [
"clippy::all",
"clippy::await_holding_lock",
"clippy::bool_to_int_with_if",
"clippy::char_lit_as_u8",
"clippy::checked_conversions",
"clippy::dbg_macro",
"clippy::debug_assert_with_mut_call",
"clippy::disallowed_methods",
"clippy::disallowed_script_idents",
"clippy::doc_link_with_quotes",
"clippy::doc_markdown",
"clippy::empty_enum",
"clippy::enum_glob_use",
"clippy::equatable_if_let",
"clippy::exit",
"clippy::expl_impl_clone_on_copy",
"clippy::explicit_deref_methods",
"clippy::explicit_into_iter_loop",
"clippy::explicit_iter_loop",
"clippy::fallible_impl_from",
"clippy::filter_map_next",
"clippy::flat_map_option",
"clippy::float_cmp_const",
"clippy::fn_params_excessive_bools",
"clippy::fn_to_numeric_cast_any",
"clippy::from_iter_instead_of_collect",
"clippy::if_let_mutex",
"clippy::implicit_clone",
"clippy::imprecise_flops",
"clippy::index_refutable_slice",
"clippy::inefficient_to_string",
"clippy::invalid_upcast_comparisons",
"clippy::iter_not_returning_iterator",
"clippy::iter_on_empty_collections",
"clippy::iter_on_single_items",
"clippy::large_digit_groups",
"clippy::large_stack_arrays",
"clippy::large_types_passed_by_value",
"clippy::let_unit_value",
"clippy::linkedlist",
"clippy::lossy_float_literal",
"clippy::macro_use_imports",
"clippy::manual_assert",
"clippy::manual_instant_elapsed",
"clippy::manual_ok_or",
"clippy::manual_string_new",
"clippy::map_err_ignore",
"clippy::map_flatten",
"clippy::map_unwrap_or",
"clippy::match_on_vec_items",
"clippy::match_same_arms",
"clippy::match_wild_err_arm",
"clippy::match_wildcard_for_single_variants",
"clippy::mem_forget",
"clippy::mismatched_target_os",
"clippy::mismatching_type_param_order",
"clippy::missing_enforced_import_renames",
# "clippy::missing_errors_doc",
"clippy::missing_safety_doc",
"clippy::mut_mut",
"clippy::mutex_integer",
"clippy::needless_borrow",
"clippy::needless_continue",
"clippy::needless_for_each",
"clippy::needless_pass_by_value",
"clippy::negative_feature_names",
"clippy::nonstandard_macro_braces",
"clippy::option_option",
"clippy::path_buf_push_overwrite",
"clippy::ptr_as_ptr",
"clippy::rc_mutex",
"clippy::ref_option_ref",
"clippy::rest_pat_in_fully_bound_structs",
"clippy::same_functions_in_if_condition",
"clippy::semicolon_if_nothing_returned",
"clippy::single_match_else",
"clippy::str_to_string",
"clippy::string_add_assign",
"clippy::string_add",
"clippy::string_lit_as_bytes",
"clippy::string_to_string",
"clippy::todo",
"clippy::trailing_empty_array",
"clippy::trait_duplication_in_bounds",
"clippy::unimplemented",
"clippy::unnecessary_wraps",
"clippy::unnested_or_patterns",
"clippy::unused_peekable",
"clippy::unused_rounding",
# "clippy::unused_self",
"clippy::useless_transmute",
"clippy::verbose_file_reads",
"clippy::zero_sized_map_values",
"elided_lifetimes_in_paths",
"future_incompatible",
"nonstandard_style",
"rust_2018_idioms",
"rust_2021_prelude_collisions",
"rustdoc::missing_crate_level_docs",
"semicolon_in_expressions_from_macros",
"trivial_numeric_casts",
"unused_extern_crates",
"unused_import_braces",
"unused_lifetimes",
]
allow = [
# TODO(emilk): enable more lints
"clippy::cloned_instead_of_copied",
"clippy::derive_partial_eq_without_eq",
"clippy::type_complexity",
"clippy::undocumented_unsafe_blocks",
"trivial_casts",
"unsafe_op_in_unsafe_fn", # `unsafe_op_in_unsafe_fn` may become the default in future Rust versions: https://github.com/rust-lang/rust/issues/71668
"unused_qualifications",
]

69
deny.toml Normal file
View File

@ -0,0 +1,69 @@
# https://embarkstudios.github.io/cargo-deny/
targets = [
{ triple = "aarch64-apple-darwin" },
{ triple = "aarch64-linux-android" },
{ triple = "wasm32-unknown-unknown" },
{ triple = "x86_64-apple-darwin" },
{ triple = "x86_64-pc-windows-msvc" },
{ triple = "x86_64-unknown-linux-gnu" },
{ triple = "x86_64-unknown-linux-musl" },
]
[advisories]
vulnerability = "deny"
unmaintained = "warn"
yanked = "deny"
ignore = [
"RUSTSEC-2020-0071", # https://rustsec.org/advisories/RUSTSEC-2020-0071 - chrono/time: Potential segfault in the time crate
"RUSTSEC-2020-0159", # https://rustsec.org/advisories/RUSTSEC-2020-0159 - chrono/time: Potential segfault in localtime_r invocations
"RUSTSEC-2021-0127", # https://rustsec.org/advisories/RUSTSEC-2021-0127 - https://github.com/bheisler/criterion.rs/issues/534
]
[bans]
multiple-versions = "deny"
wildcards = "allow" # at least until https://github.com/EmbarkStudios/cargo-deny/issues/241 is fixed
deny = [
{ name = "openssl" }, # prefer rustls
{ name = "openssl-sys" }, # prefer rustls
]
skip-tree = [
{ name = "criterion" }, # dev-dependency
{ name = "glium" }, # legacy crate, lots of old dependencies
{ name = "rfd" }, # example dependency
{ name = "three-d" }, # example dependency
]
[licenses]
unlicensed = "deny"
allow-osi-fsf-free = "neither"
confidence-threshold = 0.92 # We want really high confidence when inferring licenses from text
copyleft = "deny"
allow = [
"Apache-2.0", # https://tldrlegal.com/license/apache-license-2.0-(apache-2.0)
"BSD-2-Clause", # https://tldrlegal.com/license/bsd-2-clause-license-(freebsd)
"BSD-3-Clause", # https://tldrlegal.com/license/bsd-3-clause-license-(revised)
"BSL-1.0", # https://tldrlegal.com/license/boost-software-license-1.0-explained
"CC0-1.0", # https://creativecommons.org/publicdomain/zero/1.0/
"ISC", # https://tldrlegal.com/license/-isc-license
"LicenseRef-UFL-1.0", # https://tldrlegal.com/license/ubuntu-font-license,-1.0 - no official SPDX, see https://github.com/emilk/egui/issues/2321
"MIT", # https://tldrlegal.com/license/mit-license
"MPL-2.0", # https://www.mozilla.org/en-US/MPL/2.0/FAQ/ - see Q11
"OFL-1.1", # https://spdx.org/licenses/OFL-1.1.html
"OpenSSL", # https://www.openssl.org/source/license.html
"Unicode-DFS-2016", # https://spdx.org/licenses/Unicode-DFS-2016.html
"Zlib", # https://tldrlegal.com/license/zlib-libpng-license-(zlib)
]
[[licenses.clarify]]
name = "webpki"
expression = "ISC"
license-files = [{ path = "LICENSE", hash = 0x001c7e6c }]
[[licenses.clarify]]
name = "ring"
expression = "MIT AND ISC AND OpenSSL"
license-files = [{ path = "LICENSE", hash = 0xbd0eed23 }]

View File

@ -34,3 +34,6 @@ env_logger.workspace = true
dirs.workspace = true
toml.workspace = true
serde.workspace = true
[dev-dependencies]
cargo-husky.workspace = true

View File

@ -329,11 +329,11 @@ pub fn validate_field(input: &str) -> String {
} else if input.starts_with("A_") {
// Action function
let lower = input.to_lowercase();
return if PLAYER_FUNCS.contains(&lower.as_str()) {
if PLAYER_FUNCS.contains(&lower.as_str()) {
format!("ActFn::P({lower})")
} else {
format!("ActFn::A({lower})")
};
}
} else {
input.to_string()
}

9
rust-toolchain Normal file
View File

@ -0,0 +1,9 @@
# If you see this, run "rustup self update" to get rustup 1.23 or newer.
# NOTE: above comment is for older `rustup` (before TOML support was added),
# which will treat the first line as the toolchain name, and therefore show it
# to the user in the error, instead of "error: invalid channel name '[toolchain]'".
[toolchain]
channel = "1.65.0"
components = [ "rustfmt", "clippy" ]

15
rustfmt.toml Normal file
View File

@ -0,0 +1,15 @@
condense_wildcard_suffixes = true
edition = "2021"
format_strings = true
group_imports = "StdExternalCrate"
hex_literal_case = "Lower"
imports_granularity = "Module"
max_width = 100
normalize_comments = true
normalize_doc_attributes = true
reorder_impl_items = true
reorder_imports = true
reorder_modules = true
unstable_features = true
use_field_init_shorthand = true
wrap_comments = true

View File

@ -54,7 +54,7 @@ where
/// object owns which sounds so it can be stopped e.g, death, shoot..
uid: usize,
/// The Sound effect this object has
sfx: S,
_sfx: S,
/// The world XY coords of this object
x: f32,
y: f32,
@ -69,30 +69,30 @@ where
struct SfxInfo {
/// Up to 6-character name. In the Lump the names are typically prefixed by `DS` or `DP`, so
/// the full Lump name is 8-char, while the name here has the prefix striped off.
name: String,
_name: String,
/// Priority of sound
priority: i32,
// Not really used
pitch: i32,
volume: i32,
_pitch: i32,
_volume: i32,
/// Pre-processed SDL2 Chunk data
data: Option<Chunk>,
/// this is checked every second to see if sound can be thrown out (if 0,
/// then decrement, if -1, then throw out, if > 0, then it is in use)
usefulness: i32,
_usefulness: i32,
}
impl SfxInfo {
pub(crate) fn new(name: String, priority: i32, data: Option<Chunk>) -> Self {
Self {
name,
_name: name,
priority,
pitch: -1,
volume: -1,
_pitch: -1,
_volume: -1,
data,
usefulness: 0,
_usefulness: 0,
}
}
}
@ -242,7 +242,7 @@ impl<'a> SoundServer<SfxName, usize, sdl2::Error> for Snd<'a> {
let chunk = &self.chunks[sfx as usize];
let mut origin = SoundObject {
uid,
sfx,
_sfx: sfx,
x,
y,
angle,

View File

@ -110,7 +110,7 @@ pub const EPISODE4_MUS: [MusTrack; 9] = [
MusTrack::E1M9, // Tim e4m9
];
#[derive(Debug, PartialOrd, PartialEq, Copy, Clone)]
#[derive(Debug, PartialOrd, PartialEq, Eq, Ord, Copy, Clone)]
#[allow(non_camel_case_types)]
pub enum MusTrack {
None,

View File

@ -1,5 +1,5 @@
/// Identifiers for all sfx in game-exe.
#[derive(Debug, Copy, Clone, PartialEq)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub enum SfxName {
None,
Pistol,

View File

@ -252,12 +252,10 @@ impl WadData {
/// Find a general lump by name
pub fn get_lump(&self, name: &str) -> Option<&Lump> {
for info in self.lumps.iter().rev() {
if info.name == name.to_ascii_uppercase() {
return Some(info);
}
}
None
self.lumps
.iter()
.rev()
.find(|lump| lump.name == name.to_ascii_uppercase())
}
/// Find a general lump by name