From 869a16ce272310fad947b0a1aee51005528136b3 Mon Sep 17 00:00:00 2001 From: Brett Mayson Date: Wed, 4 Dec 2024 02:39:12 +0000 Subject: [PATCH] clippy the things --- arma/src/conn.rs | 27 ----------------- arma/src/lib.rs | 14 +++++---- arma/src/photoshoot.rs | 30 ++++++++++++------- .../launch/error/bcle2_workshop_not_found.rs | 1 + .../error/bcle3_workshop_mod_not_found.rs | 1 + .../launch/error/bcle4_arma_not_found.rs | 1 + .../launch/error/bcle5_missing_main_prefix.rs | 1 + .../launch/error/bcle7_can_not_quicklaunch.rs | 1 + .../launch/error/bcle9_mission_absolute.rs | 1 + bin/src/commands/launch/launcher.rs | 20 +++++++++++++ bin/src/commands/launch/mod.rs | 9 +++--- bin/src/controller/mod.rs | 15 ++++++++-- bin/src/main.rs | 4 +-- bin/src/modules/bom.rs | 2 +- .../hook/error/bhe1_script_not_found.rs | 2 +- bin/src/modules/rapifier.rs | 2 +- bin/src/report.rs | 2 +- bin/src/utils/photoshoot.rs | 8 +++++ bin/src/utils/sqf/case.rs | 6 ++-- .../common/src/config/project/hemtt/launch.rs | 2 +- .../src/analyze/lints/c01_invalid_value.rs | 6 ++-- .../analyze/lints/c02_duplicate_property.rs | 6 ++-- .../analyze/lints/c03_duplicate_classes.rs | 6 ++-- .../src/analyze/lints/c04_external_missing.rs | 6 ++-- .../analyze/lints/c05_external_parent_case.rs | 6 ++-- .../src/analyze/lints/c06_unexpected_array.rs | 6 ++-- .../src/analyze/lints/c07_expected_array.rs | 6 ++-- .../analyze/lints/c08_missing_semicolon.rs | 6 ++-- .../lints/c09_magwell_missing_magazine.rs | 6 ++-- .../analyze/lints/c10_class_missing_braces.rs | 6 ++-- libs/config/src/model/property.rs | 2 +- libs/paa/src/paa.rs | 2 +- libs/preprocessor/src/defines.rs | 2 +- libs/preprocessor/src/processor/defines.rs | 4 +-- libs/preprocessor/src/processor/mod.rs | 4 +-- .../lints/s01_command_required_version.rs | 6 ++-- .../src/analyze/lints/s02_event_handlers.rs | 22 +++++++------- .../src/analyze/lints/s03_static_typename.rs | 6 ++-- .../sqf/src/analyze/lints/s04_command_case.rs | 6 ++-- libs/sqf/src/analyze/lints/s05_if_assign.rs | 6 ++-- libs/sqf/src/analyze/lints/s06_find_in_str.rs | 6 ++-- .../analyze/lints/s07_select_parse_number.rs | 6 ++-- libs/sqf/src/analyze/lints/s08_format_args.rs | 6 ++-- .../src/analyze/lints/s09_banned_command.rs | 6 ++-- libs/sqf/src/analyze/lints/s11_if_not_else.rs | 6 ++-- .../sqf/src/analyze/lints/s17_var_all_caps.rs | 6 ++-- .../src/analyze/lints/s18_in_vehicle_check.rs | 6 ++-- .../lints/s20_bool_static_comparison.rs | 6 ++-- .../analyze/lints/s21_invalid_comparisons.rs | 6 ++-- libs/sqf/src/analyze/lints/s22_this_call.rs | 6 ++-- .../lints/s23_reassign_reserved_variable.rs | 6 ++-- libs/sqf/src/analyze/lints/s24_marker_spam.rs | 6 ++-- .../src/analyze/lints/01_sorted.rs | 6 ++-- libs/stringtable/src/key.rs | 1 + libs/workspace/src/lint/mod.rs | 18 +++++------ .../src/reporting/diagnostic/label.rs | 2 +- 56 files changed, 198 insertions(+), 170 deletions(-) delete mode 100644 arma/src/conn.rs diff --git a/arma/src/conn.rs b/arma/src/conn.rs deleted file mode 100644 index 3e12732c..00000000 --- a/arma/src/conn.rs +++ /dev/null @@ -1,27 +0,0 @@ -use std::{mem::MaybeUninit, sync::mpsc::Sender}; - -use hemtt_common::arma::control::fromarma::Message; - -pub struct Conn(); - -static mut SINGLETON: MaybeUninit> = MaybeUninit::uninit(); -static mut INIT: bool = false; - -impl Conn { - /// Gets a reference to the sender - /// - /// # Panics - /// - /// Panics if the sender has not been set - pub fn get() -> Sender { - unsafe { SINGLETON.assume_init_ref().clone() } - } - - /// Store the sender - pub fn set(sender: Sender) { - unsafe { - SINGLETON = MaybeUninit::new(sender); - INIT = true; - } - } -} diff --git a/arma/src/lib.rs b/arma/src/lib.rs index 8df80805..f17c1635 100644 --- a/arma/src/lib.rs +++ b/arma/src/lib.rs @@ -1,14 +1,12 @@ use std::io::{Read, Write}; -use arma_rs::{arma, Extension}; -use conn::Conn; +use arma_rs::{arma, Context, ContextState, Extension}; use hemtt_common::arma::control::{ fromarma::{self, Control, Message}, toarma, }; use interprocess::local_socket::{prelude::*, GenericNamespaced, Stream}; -mod conn; mod photoshoot; #[arma] @@ -19,8 +17,8 @@ fn init() -> Extension { .finish(); let ctx = ext.context(); let (send, recv) = std::sync::mpsc::channel::(); + ctx.global().set(send); std::thread::spawn(move || { - Conn::set(send); let mut socket = Stream::connect("hemtt_arma".to_ns_name::().unwrap()).unwrap(); socket.set_nonblocking(true).unwrap(); @@ -73,8 +71,12 @@ fn init() -> Extension { ext } -fn mission(mission: String) { - Conn::get() +fn mission(ctx: Context, mission: String) { + let Some(sender) = ctx.global().get::>() else { + println!("`mission` called without a sender"); + return; + }; + sender .send(Message::Control(Control::Mission(mission))) .unwrap(); } diff --git a/arma/src/photoshoot.rs b/arma/src/photoshoot.rs index e1556b33..ffe3cf46 100644 --- a/arma/src/photoshoot.rs +++ b/arma/src/photoshoot.rs @@ -1,8 +1,6 @@ -use arma_rs::Group; +use arma_rs::{Context, ContextState, Group}; use hemtt_common::arma::control::fromarma::{Message, Photoshoot}; -use crate::conn::Conn; - pub fn group() -> Group { Group::new() .command("ready", ready) @@ -10,20 +8,30 @@ pub fn group() -> Group { .command("previews", previews) } -fn ready() { - Conn::get() - .send(Message::Photoshoot(Photoshoot::Ready)) - .unwrap(); +fn ready(ctx: Context) { + let Some(sender) = ctx.global().get::>() else { + println!("`photoshoot:ready` called without a sender"); + return; + }; + sender.send(Message::Photoshoot(Photoshoot::Ready)).unwrap(); } -fn weapon(weapon: String) { - Conn::get() +fn weapon(ctx: Context, weapon: String) { + let Some(sender) = ctx.global().get::>() else { + println!("`photoshoot:weapon` called without a sender"); + return; + }; + sender .send(Message::Photoshoot(Photoshoot::Weapon(weapon))) .unwrap(); } -fn previews() { - Conn::get() +fn previews(ctx: Context) { + let Some(sender) = ctx.global().get::>() else { + println!("`photoshoot:previews` called without a sender"); + return; + }; + sender .send(Message::Photoshoot(Photoshoot::Previews)) .unwrap(); } diff --git a/bin/src/commands/launch/error/bcle2_workshop_not_found.rs b/bin/src/commands/launch/error/bcle2_workshop_not_found.rs index c6fb085d..5f3fb710 100644 --- a/bin/src/commands/launch/error/bcle2_workshop_not_found.rs +++ b/bin/src/commands/launch/error/bcle2_workshop_not_found.rs @@ -26,6 +26,7 @@ impl Code for WorkshopNotFound { } impl WorkshopNotFound { + #[must_use] pub fn code() -> Arc { Arc::new(Self {}) } diff --git a/bin/src/commands/launch/error/bcle3_workshop_mod_not_found.rs b/bin/src/commands/launch/error/bcle3_workshop_mod_not_found.rs index ac4b8927..738c0684 100644 --- a/bin/src/commands/launch/error/bcle3_workshop_mod_not_found.rs +++ b/bin/src/commands/launch/error/bcle3_workshop_mod_not_found.rs @@ -29,6 +29,7 @@ impl Code for WorkshopModNotFound { } impl WorkshopModNotFound { + #[must_use] pub fn code(id: String) -> Arc { Arc::new(Self { id }) } diff --git a/bin/src/commands/launch/error/bcle4_arma_not_found.rs b/bin/src/commands/launch/error/bcle4_arma_not_found.rs index afa5dce6..a2cade1b 100644 --- a/bin/src/commands/launch/error/bcle4_arma_not_found.rs +++ b/bin/src/commands/launch/error/bcle4_arma_not_found.rs @@ -23,6 +23,7 @@ impl Code for ArmaNotFound { } impl ArmaNotFound { + #[must_use] pub fn code() -> Arc { Arc::new(Self {}) } diff --git a/bin/src/commands/launch/error/bcle5_missing_main_prefix.rs b/bin/src/commands/launch/error/bcle5_missing_main_prefix.rs index ab19492e..aab1dbca 100644 --- a/bin/src/commands/launch/error/bcle5_missing_main_prefix.rs +++ b/bin/src/commands/launch/error/bcle5_missing_main_prefix.rs @@ -23,6 +23,7 @@ impl Code for MissingMainPrefix { } impl MissingMainPrefix { + #[must_use] pub fn code() -> Arc { Arc::new(Self {}) } diff --git a/bin/src/commands/launch/error/bcle7_can_not_quicklaunch.rs b/bin/src/commands/launch/error/bcle7_can_not_quicklaunch.rs index 05cddcd0..2e94626d 100644 --- a/bin/src/commands/launch/error/bcle7_can_not_quicklaunch.rs +++ b/bin/src/commands/launch/error/bcle7_can_not_quicklaunch.rs @@ -25,6 +25,7 @@ impl Code for CanNotQuickLaunch { } impl CanNotQuickLaunch { + #[must_use] pub fn code(reason: String) -> Arc { Arc::new(Self { reason }) } diff --git a/bin/src/commands/launch/error/bcle9_mission_absolute.rs b/bin/src/commands/launch/error/bcle9_mission_absolute.rs index 37f2c0f7..07dcf899 100644 --- a/bin/src/commands/launch/error/bcle9_mission_absolute.rs +++ b/bin/src/commands/launch/error/bcle9_mission_absolute.rs @@ -29,6 +29,7 @@ impl Code for MissionAbsolutePath { } impl MissionAbsolutePath { + #[must_use] pub fn code(reason: String) -> Arc { Arc::new(Self { reason }) } diff --git a/bin/src/commands/launch/launcher.rs b/bin/src/commands/launch/launcher.rs index 0a633643..cb5d62ca 100644 --- a/bin/src/commands/launch/launcher.rs +++ b/bin/src/commands/launch/launcher.rs @@ -36,6 +36,10 @@ pub struct Launcher { } impl Launcher { + /// Creates a new launcher + /// + /// # Errors + /// [`Error::Io`] if the current directory could not be determined pub fn new( launch: &LaunchArgs, options: &LaunchOptions, @@ -73,6 +77,10 @@ impl Launcher { Ok((report, Some(launcher))) } + /// Adds the current project to the mod list + /// + /// # Errors + /// [`Error::Io`] if the current directory could not be determined pub fn add_self_mod(&mut self) -> Result<(), Error> { self.workshop.push({ let mut path = std::env::current_dir()?; @@ -86,6 +94,11 @@ impl Launcher { Ok(()) } + /// Adds a preset to the mod list + /// + /// # Errors + /// [`Error::Io`] if the current directory could not be determined + /// [`Error::Io`] if the preset could not be read pub fn add_preset(&mut self, preset: &str, report: &mut Report) -> Result<(), Error> { let presets = std::env::current_dir()?.join(".hemtt/presets"); trace!("Loading preset: {}", preset); @@ -110,6 +123,13 @@ impl Launcher { } #[allow(clippy::too_many_lines)] + /// Launches the game + /// + /// # Errors + /// [`Error::Io`] if the current directory could not be determined + /// + /// # Panics + /// If regex fails to compile pub fn launch( &self, mut args: Vec, diff --git a/bin/src/commands/launch/mod.rs b/bin/src/commands/launch/mod.rs index bd7857fa..30abe860 100644 --- a/bin/src/commands/launch/mod.rs +++ b/bin/src/commands/launch/mod.rs @@ -252,7 +252,7 @@ pub fn execute(cmd: &Command) -> Result { &config, cmd.launch.config.as_deref().unwrap_or_default(), &mut report, - )?; + ); let Some(launch) = launch else { return Ok(report); }; @@ -318,11 +318,12 @@ pub fn execute(cmd: &Command) -> Result { Ok(report) } +/// Read a launch configuration pub fn read_config( config: &ProjectConfig, configs: &[String], report: &mut Report, -) -> Result, Error> { +) -> Option { let launch = if configs.is_empty() { config .hemtt() @@ -351,7 +352,7 @@ pub fn read_config( hemtt_common::config::LaunchOptions::overlay, ) } else { - return Ok(None); + return None; }; - Ok(Some(launch)) + Some(launch) } diff --git a/bin/src/controller/mod.rs b/bin/src/controller/mod.rs index 10a6e602..42c01d0c 100644 --- a/bin/src/controller/mod.rs +++ b/bin/src/controller/mod.rs @@ -40,6 +40,15 @@ impl Controller { self.actions.push(action); } + /// Run the controller + /// + /// # Errors + /// - [`Error::Io`] if profile files cannot be written to disk in the temporary directory + /// - [`Error::Io`] if there is an issue with the local socket + /// + /// # Panics + /// - If an message is not able to be read from the local socket + /// - If a message is in an unexpected format pub fn run( self, ctx: &Context, @@ -95,8 +104,8 @@ impl Controller { let len = u32::from_le_bytes(len_buf); trace!("Receiving: {}", len); let mut buf = vec![0u8; len as usize]; - socket.read_exact(&mut buf).unwrap(); - let buf = String::from_utf8(buf).unwrap(); + socket.read_exact(&mut buf).expect("Failed to read message"); + let buf = String::from_utf8(buf).expect("Failed to parse message"); let message: fromarma::Message = serde_json::from_str(&buf)?; trace!("Received: {:?}", message); if let fromarma::Message::Control(control) = message { @@ -115,7 +124,7 @@ impl Controller { self.actions .iter() .find(|a| a.missions(ctx).iter().any(|m| &m.1 == current)) - .unwrap() + .expect("No action for mission") .incoming(ctx, message) .iter() .for_each(|m| send(m, &mut socket)); diff --git a/bin/src/main.rs b/bin/src/main.rs index 60561a5e..0d47157a 100644 --- a/bin/src/main.rs +++ b/bin/src/main.rs @@ -6,7 +6,7 @@ fn main() { std::panic::set_hook(Box::new(|panic| { error!("{panic}"); eprintln!( - r#" + " Oh no! HEMTT has crashed! This is a bug in HEMTT itself, not necessarily your project. Even if there is a bug in your project, HEMTT should not crash, but gracefully exit with an error message. @@ -18,7 +18,7 @@ GitHub (https://github.com/BrettMayson/HEMTT) The log from the most recent run can be found in `.hemttout/latest.log`. It is always best to the include the log and a link to your project when reporting a bug, this will help reproduce the issue. -"# +" ); std::process::exit(1); })); diff --git a/bin/src/modules/bom.rs b/bin/src/modules/bom.rs index 80ac1f87..0264919a 100644 --- a/bin/src/modules/bom.rs +++ b/bin/src/modules/bom.rs @@ -23,7 +23,7 @@ impl Module for BOMCheck { .filter(|e| e.file_type().is_file()) .filter(|e| !e.path().display().to_string().contains(".hemttout")) .filter(|e| { - e.path().extension().map_or(false, |e| { + e.path().extension().is_some_and(|e| { !IGNORED_EXTENSIONS.contains(&e.to_str().unwrap_or_default()) }) }) diff --git a/bin/src/modules/hook/error/bhe1_script_not_found.rs b/bin/src/modules/hook/error/bhe1_script_not_found.rs index ced50f5d..9eb2e2c5 100644 --- a/bin/src/modules/hook/error/bhe1_script_not_found.rs +++ b/bin/src/modules/hook/error/bhe1_script_not_found.rs @@ -45,7 +45,7 @@ impl ScriptNotFound { .read_dir()? .iter() .filter_map(|x| { - if x.is_file().map_or(false, |x| x) { + if x.is_file().is_ok_and(|x| x) { Some(x.filename().trim_end_matches(".rhai").to_string()) } else { None diff --git a/bin/src/modules/rapifier.rs b/bin/src/modules/rapifier.rs index 1aa77c19..a903bb42 100644 --- a/bin/src/modules/rapifier.rs +++ b/bin/src/modules/rapifier.rs @@ -142,7 +142,7 @@ pub fn rapify(addon: &Addon, path: &WorkspacePath, ctx: &Context) -> Result Result, Vec>, Error> { let path = from.join(format!("{name}.png")); let mut new = image::open(path)?.into_rgba8(); @@ -30,6 +34,10 @@ impl Photoshoot { Ok(new) } + /// Processes an editor preview screenshot + /// + /// # Errors + /// [`Error::Image`] if the image could not be loaded pub fn preview(path: &Path) -> Result, Vec>, Error> { let new = image::open(path)?.into_rgb8(); let mut new = image::imageops::resize(&new, 455, 256, image::imageops::FilterType::Nearest); diff --git a/bin/src/utils/sqf/case.rs b/bin/src/utils/sqf/case.rs index 5d202426..ca7a5140 100644 --- a/bin/src/utils/sqf/case.rs +++ b/bin/src/utils/sqf/case.rs @@ -104,7 +104,7 @@ fn file(file: &Path) -> Result { } ('/', InsideQuote::No, InsideComment::No, _) => { check_buffer(&mut out, &mut buffer, &wiki); - if out.chars().last().map_or(false, |c| c == '/') { + if out.ends_with('/') { in_comment = InsideComment::Single; } out.push(char); @@ -118,13 +118,13 @@ fn file(file: &Path) -> Result { } ('*', InsideQuote::No, InsideComment::No, _) => { check_buffer(&mut out, &mut buffer, &wiki); - if out.chars().last().map_or(false, |c| c == '/') { + if out.ends_with('/') { in_comment = InsideComment::Multi; } out.push(char); } ('/', InsideQuote::No, InsideComment::Multi, _) => { - if out.chars().last().map_or(false, |c| c == '*') { + if out.ends_with('*') { in_comment = InsideComment::No; } out.push(char); diff --git a/libs/common/src/config/project/hemtt/launch.rs b/libs/common/src/config/project/hemtt/launch.rs index 88a95072..221a4183 100644 --- a/libs/common/src/config/project/hemtt/launch.rs +++ b/libs/common/src/config/project/hemtt/launch.rs @@ -87,7 +87,7 @@ impl LaunchOptions { .map_or_else(|| "arma3_x64", |e| e.as_str()); if std::path::Path::new(executable) .extension() - .map_or(false, |ext| ext.eq_ignore_ascii_case("exe")) + .is_some_and(|ext| ext.eq_ignore_ascii_case("exe")) { (*executable).to_string() } else { diff --git a/libs/config/src/analyze/lints/c01_invalid_value.rs b/libs/config/src/analyze/lints/c01_invalid_value.rs index 278926c6..718fa318 100644 --- a/libs/config/src/analyze/lints/c01_invalid_value.rs +++ b/libs/config/src/analyze/lints/c01_invalid_value.rs @@ -11,7 +11,7 @@ use crate::{analyze::SqfLintData, Item, Value}; crate::analyze::lint!(LintC01InvalidValue); impl Lint for LintC01InvalidValue { - fn ident(&self) -> &str { + fn ident(&self) -> &'static str { "invalid_value" } @@ -19,11 +19,11 @@ impl Lint for LintC01InvalidValue { 10 } - fn description(&self) -> &str { + fn description(&self) -> &'static str { "Reports on any values in the config that could not be parsed into a valid config value." } - fn documentation(&self) -> &str { + fn documentation(&self) -> &'static str { r#"### Example **Incorrect** diff --git a/libs/config/src/analyze/lints/c02_duplicate_property.rs b/libs/config/src/analyze/lints/c02_duplicate_property.rs index b79223e4..dc182134 100644 --- a/libs/config/src/analyze/lints/c02_duplicate_property.rs +++ b/libs/config/src/analyze/lints/c02_duplicate_property.rs @@ -11,7 +11,7 @@ use crate::{analyze::SqfLintData, Class, Config, Ident, Property}; crate::analyze::lint!(LintC02DuplicateProperty); impl Lint for LintC02DuplicateProperty { - fn ident(&self) -> &str { + fn ident(&self) -> &'static str { "duplicate_property" } @@ -19,11 +19,11 @@ impl Lint for LintC02DuplicateProperty { 20 } - fn description(&self) -> &str { + fn description(&self) -> &'static str { "Reports on duplicated properties." } - fn documentation(&self) -> &str { + fn documentation(&self) -> &'static str { "### Example **Incorrect** diff --git a/libs/config/src/analyze/lints/c03_duplicate_classes.rs b/libs/config/src/analyze/lints/c03_duplicate_classes.rs index 212f4841..825c3d12 100644 --- a/libs/config/src/analyze/lints/c03_duplicate_classes.rs +++ b/libs/config/src/analyze/lints/c03_duplicate_classes.rs @@ -11,7 +11,7 @@ use crate::{analyze::SqfLintData, Class, Config, Property}; crate::analyze::lint!(LintC03DuplicateClasses); impl Lint for LintC03DuplicateClasses { - fn ident(&self) -> &str { + fn ident(&self) -> &'static str { "duplicate_classes" } @@ -19,11 +19,11 @@ impl Lint for LintC03DuplicateClasses { 30 } - fn description(&self) -> &str { + fn description(&self) -> &'static str { "Reports on duplicated child classes." } - fn documentation(&self) -> &str { + fn documentation(&self) -> &'static str { "### Example **Incorrect** diff --git a/libs/config/src/analyze/lints/c04_external_missing.rs b/libs/config/src/analyze/lints/c04_external_missing.rs index cc79079a..bbf20e6a 100644 --- a/libs/config/src/analyze/lints/c04_external_missing.rs +++ b/libs/config/src/analyze/lints/c04_external_missing.rs @@ -11,7 +11,7 @@ use crate::{analyze::SqfLintData, Class, Config, Property}; crate::analyze::lint!(LintC04ExternalMissing); impl Lint for LintC04ExternalMissing { - fn ident(&self) -> &str { + fn ident(&self) -> &'static str { "external_missing" } @@ -19,11 +19,11 @@ impl Lint for LintC04ExternalMissing { 40 } - fn description(&self) -> &str { + fn description(&self) -> &'static str { "Reports on classes that extend an external class that is not present in the config" } - fn documentation(&self) -> &str { + fn documentation(&self) -> &'static str { "### Example **Incorrect** diff --git a/libs/config/src/analyze/lints/c05_external_parent_case.rs b/libs/config/src/analyze/lints/c05_external_parent_case.rs index 19d9bed5..19fb5fc0 100644 --- a/libs/config/src/analyze/lints/c05_external_parent_case.rs +++ b/libs/config/src/analyze/lints/c05_external_parent_case.rs @@ -11,7 +11,7 @@ use crate::{analyze::SqfLintData, Class, Property}; crate::analyze::lint!(LintC05ExternalParentCase); impl Lint for LintC05ExternalParentCase { - fn ident(&self) -> &str { + fn ident(&self) -> &'static str { "external_parent_case" } @@ -19,11 +19,11 @@ impl Lint for LintC05ExternalParentCase { 50 } - fn description(&self) -> &str { + fn description(&self) -> &'static str { "Reports on uses of base classes with incorrect case compared to the parent definition" } - fn documentation(&self) -> &str { + fn documentation(&self) -> &'static str { "### Example **Incorrect** diff --git a/libs/config/src/analyze/lints/c06_unexpected_array.rs b/libs/config/src/analyze/lints/c06_unexpected_array.rs index 20a08df8..5f46cb2a 100644 --- a/libs/config/src/analyze/lints/c06_unexpected_array.rs +++ b/libs/config/src/analyze/lints/c06_unexpected_array.rs @@ -11,7 +11,7 @@ use crate::{analyze::SqfLintData, Property, Value}; crate::analyze::lint!(LintC06UnexpectedArray); impl Lint for LintC06UnexpectedArray { - fn ident(&self) -> &str { + fn ident(&self) -> &'static str { "unexpected_array" } @@ -19,11 +19,11 @@ impl Lint for LintC06UnexpectedArray { 60 } - fn description(&self) -> &str { + fn description(&self) -> &'static str { "Reports on properties that are not expected to be arrays, but are defined as arrays" } - fn documentation(&self) -> &str { + fn documentation(&self) -> &'static str { "### Example **Incorrect** diff --git a/libs/config/src/analyze/lints/c07_expected_array.rs b/libs/config/src/analyze/lints/c07_expected_array.rs index 94defd3e..ebdf5bfc 100644 --- a/libs/config/src/analyze/lints/c07_expected_array.rs +++ b/libs/config/src/analyze/lints/c07_expected_array.rs @@ -11,7 +11,7 @@ use crate::{analyze::SqfLintData, Property, Value}; crate::analyze::lint!(LintC07ExpectedArray); impl Lint for LintC07ExpectedArray { - fn ident(&self) -> &str { + fn ident(&self) -> &'static str { "expected_array" } @@ -19,11 +19,11 @@ impl Lint for LintC07ExpectedArray { 70 } - fn description(&self) -> &str { + fn description(&self) -> &'static str { "Reports on properties that are expected to be arrays, but are not defined as arrays" } - fn documentation(&self) -> &str { + fn documentation(&self) -> &'static str { "### Example **Incorrect** diff --git a/libs/config/src/analyze/lints/c08_missing_semicolon.rs b/libs/config/src/analyze/lints/c08_missing_semicolon.rs index 5915daee..005bdabc 100644 --- a/libs/config/src/analyze/lints/c08_missing_semicolon.rs +++ b/libs/config/src/analyze/lints/c08_missing_semicolon.rs @@ -11,7 +11,7 @@ use crate::{analyze::SqfLintData, Property}; crate::analyze::lint!(LintC08MissingSemicolon); impl Lint for LintC08MissingSemicolon { - fn ident(&self) -> &str { + fn ident(&self) -> &'static str { "missing_semicolon" } @@ -19,11 +19,11 @@ impl Lint for LintC08MissingSemicolon { 80 } - fn description(&self) -> &str { + fn description(&self) -> &'static str { "Reports on properties that are missing a semicolon" } - fn documentation(&self) -> &str { + fn documentation(&self) -> &'static str { "### Example **Incorrect** diff --git a/libs/config/src/analyze/lints/c09_magwell_missing_magazine.rs b/libs/config/src/analyze/lints/c09_magwell_missing_magazine.rs index 37a630ca..ebd60284 100644 --- a/libs/config/src/analyze/lints/c09_magwell_missing_magazine.rs +++ b/libs/config/src/analyze/lints/c09_magwell_missing_magazine.rs @@ -11,7 +11,7 @@ use crate::{analyze::SqfLintData, Class, Config, Ident, Item, Property, Str, Val crate::analyze::lint!(LintC09MagwellMissingMagazine); impl Lint for LintC09MagwellMissingMagazine { - fn ident(&self) -> &str { + fn ident(&self) -> &'static str { "magwell_missing_magazine" } @@ -19,11 +19,11 @@ impl Lint for LintC09MagwellMissingMagazine { 90 } - fn description(&self) -> &str { + fn description(&self) -> &'static str { "Reports on magazines that are defined in CfgMagazineWells but not in CfgMagazines" } - fn documentation(&self) -> &str { + fn documentation(&self) -> &'static str { r#"### Example **Incorrect** diff --git a/libs/config/src/analyze/lints/c10_class_missing_braces.rs b/libs/config/src/analyze/lints/c10_class_missing_braces.rs index 30e91530..8e9db632 100644 --- a/libs/config/src/analyze/lints/c10_class_missing_braces.rs +++ b/libs/config/src/analyze/lints/c10_class_missing_braces.rs @@ -11,7 +11,7 @@ use crate::{analyze::SqfLintData, Class, Property}; crate::analyze::lint!(LintC10ClassMissingBraces); impl Lint for LintC10ClassMissingBraces { - fn ident(&self) -> &str { + fn ident(&self) -> &'static str { "class_missing_braces" } @@ -19,11 +19,11 @@ impl Lint for LintC10ClassMissingBraces { 100 } - fn description(&self) -> &str { + fn description(&self) -> &'static str { "Reports on classes that use inheritance without braces" } - fn documentation(&self) -> &str { + fn documentation(&self) -> &'static str { "### Example **Incorrect** diff --git a/libs/config/src/model/property.rs b/libs/config/src/model/property.rs index 707cd0ad..703bcd0c 100644 --- a/libs/config/src/model/property.rs +++ b/libs/config/src/model/property.rs @@ -28,7 +28,7 @@ impl Property { /// /// # Panics /// If this is a [`Class::Root`], which should never occur - pub fn name(&self) -> &Ident { + pub const fn name(&self) -> &Ident { match self { Self::Class(c) => c.name().expect("root should not be a property"), Self::MissingSemicolon(name, _) | Self::Delete(name) | Self::Entry { name, .. } => name, diff --git a/libs/paa/src/paa.rs b/libs/paa/src/paa.rs index 1df5ff1a..e00241aa 100644 --- a/libs/paa/src/paa.rs +++ b/libs/paa/src/paa.rs @@ -59,7 +59,7 @@ impl Paa { while { let mut tagg_sig = [0; 4]; input.read_exact(&mut tagg_sig)?; - std::str::from_utf8(&tagg_sig).map_or(false, |ts| ts == "GGAT") + std::str::from_utf8(&tagg_sig) == Ok("GGAT") } { let name = { let mut bytes = [0; 4]; diff --git a/libs/preprocessor/src/defines.rs b/libs/preprocessor/src/defines.rs index ed251911..827fc057 100644 --- a/libs/preprocessor/src/defines.rs +++ b/libs/preprocessor/src/defines.rs @@ -285,7 +285,7 @@ impl Defines { let Definition::Function(func) = def else { return false; }; - args.map_or(true, |args| func.args().len() == args) + args.is_none_or(|args| func.args().len() == args) }) .map(|(name, _)| (name, levenshtein(name, search))) .collect::>(); diff --git a/libs/preprocessor/src/processor/defines.rs b/libs/preprocessor/src/processor/defines.rs index 528c5e4b..7c496710 100644 --- a/libs/preprocessor/src/processor/defines.rs +++ b/libs/preprocessor/src/processor/defines.rs @@ -172,7 +172,7 @@ impl Processor { if symbol.is_newline() { if body .last() - .map_or(false, |t: &Arc| t.symbol().is_escape()) + .is_some_and(|t: &Arc| t.symbol().is_escape()) { // remove the backslash body.pop(); @@ -237,7 +237,7 @@ impl Processor { }) { for token in [value.first(), value.last()] { - if token.map_or(false, |t| t.symbol().is_whitespace()) { + if token.is_some_and(|t| t.symbol().is_whitespace()) { let warning = PaddedArg::new( Box::new( (**token.expect("token exists from map_or check")).clone(), diff --git a/libs/preprocessor/src/processor/mod.rs b/libs/preprocessor/src/processor/mod.rs index 76615a9d..f92c8f69 100644 --- a/libs/preprocessor/src/processor/mod.rs +++ b/libs/preprocessor/src/processor/mod.rs @@ -191,7 +191,7 @@ impl Processor { } let token = stream.next().expect("peeked above"); if in_macro.is_some() - && stream.peek().map_or(false, |t| t.symbol().is_word() && self.defines.contains_key(&t.symbol().to_string())) + && stream.peek().is_some_and(|t| t.symbol().is_word() && self.defines.contains_key(&t.symbol().to_string())) // check if the # token is from another file, or defined before the callsite, ie not in the root arguments && (token.position().path() != callsite.expect( "callsite should exist if in_macro is some" @@ -300,7 +300,7 @@ impl Processor { if token.symbol().is_newline() && buffer .last() - .map_or(false, |t| t.last_symbol().map_or(false, Symbol::is_escape)) + .is_some_and(|t| t.last_symbol().is_some_and(Symbol::is_escape)) { buffer.pop(); return; diff --git a/libs/sqf/src/analyze/lints/s01_command_required_version.rs b/libs/sqf/src/analyze/lints/s01_command_required_version.rs index ef09a37b..46a7cb9c 100644 --- a/libs/sqf/src/analyze/lints/s01_command_required_version.rs +++ b/libs/sqf/src/analyze/lints/s01_command_required_version.rs @@ -13,7 +13,7 @@ use crate::{analyze::SqfLintData, Statements}; crate::analyze::lint!(LintS01CommandRequiredVersion); impl Lint for LintS01CommandRequiredVersion { - fn ident(&self) -> &str { + fn ident(&self) -> &'static str { "required_version" } @@ -21,11 +21,11 @@ impl Lint for LintS01CommandRequiredVersion { 10 } - fn description(&self) -> &str { + fn description(&self) -> &'static str { "Checks for command usage that requires a newer version than specified in CfgPatches" } - fn documentation(&self) -> &str { + fn documentation(&self) -> &'static str { "### Example **Incorrect** diff --git a/libs/sqf/src/analyze/lints/s02_event_handlers.rs b/libs/sqf/src/analyze/lints/s02_event_handlers.rs index 9fe70894..572b41e8 100644 --- a/libs/sqf/src/analyze/lints/s02_event_handlers.rs +++ b/libs/sqf/src/analyze/lints/s02_event_handlers.rs @@ -11,7 +11,7 @@ use crate::{analyze::{extract_constant, SqfLintData}, parser::database::Database pub struct LintS02EventInsufficientVersion; impl Lint for LintS02EventInsufficientVersion { - fn ident(&self) -> &str { + fn ident(&self) -> &'static str { "event_insufficient_version" } @@ -23,11 +23,11 @@ impl Lint for LintS02EventInsufficientVersion { "02IV".to_string() } - fn description(&self) -> &str { + fn description(&self) -> &'static str { "Checks for event handlers that require a newer version than specified in CfgPatches" } - fn documentation(&self) -> &str { + fn documentation(&self) -> &'static str { r#"### Example **Incorrect** @@ -62,7 +62,7 @@ Check [the wiki](https://community.bistudio.com/wiki/Arma_3:_Event_Handlers) to pub struct LintS02EventUnknown; impl Lint for LintS02EventUnknown { - fn ident(&self) -> &str { + fn ident(&self) -> &'static str { "event_unknown" } @@ -74,11 +74,11 @@ impl Lint for LintS02EventUnknown { "02UE".to_string() } - fn description(&self) -> &str { + fn description(&self) -> &'static str { "Checks for unknown event used in event handlers" } - fn documentation(&self) -> &str { + fn documentation(&self) -> &'static str { r#"### Configuration - **ignore**: List of unknown event names to ignore @@ -115,7 +115,7 @@ Check [the wiki](https://community.bistudio.com/wiki/Arma_3:_Event_Handlers) to pub struct LintS02EventIncorrectCommand; impl Lint for LintS02EventIncorrectCommand { - fn ident(&self) -> &str { + fn ident(&self) -> &'static str { "event_incorrect_command" } @@ -127,11 +127,11 @@ impl Lint for LintS02EventIncorrectCommand { "02IC".to_string() } - fn description(&self) -> &str { + fn description(&self) -> &'static str { "Checks for event handlers used with incorrect commands" } - fn documentation(&self) -> &str { + fn documentation(&self) -> &'static str { r#"### Example **Incorrect** @@ -543,8 +543,8 @@ impl CodeS02IncorrectCommand { .filter(|c| c.contains(&prefix)) .for_each(|c| { alternatives.push(((*c).to_string(), { - database.wiki().commands().get(c).map_or(false, |c| { - c.syntax().first().map_or(false, |s| s.call().is_binary()) + database.wiki().commands().get(c).is_some_and(|c| { + c.syntax().first().is_some_and(|s| s.call().is_binary()) }) })); }); diff --git a/libs/sqf/src/analyze/lints/s03_static_typename.rs b/libs/sqf/src/analyze/lints/s03_static_typename.rs index 695986d4..79c0c279 100644 --- a/libs/sqf/src/analyze/lints/s03_static_typename.rs +++ b/libs/sqf/src/analyze/lints/s03_static_typename.rs @@ -9,7 +9,7 @@ use crate::{analyze::SqfLintData, Expression, NularCommand, UnaryCommand}; crate::analyze::lint!(LintS03StaticTypename); impl Lint for LintS03StaticTypename { - fn ident(&self) -> &str { + fn ident(&self) -> &'static str { "static_typename" } @@ -17,11 +17,11 @@ impl Lint for LintS03StaticTypename { 30 } - fn description(&self) -> &str { + fn description(&self) -> &'static str { "Checks for `typeName` on static values, which can be replaced with the string type directly" } - fn documentation(&self) -> &str { + fn documentation(&self) -> &'static str { r#"### Example **Incorrect** diff --git a/libs/sqf/src/analyze/lints/s04_command_case.rs b/libs/sqf/src/analyze/lints/s04_command_case.rs index d0ad6faa..b5e6a4cf 100644 --- a/libs/sqf/src/analyze/lints/s04_command_case.rs +++ b/libs/sqf/src/analyze/lints/s04_command_case.rs @@ -8,7 +8,7 @@ use crate::{analyze::SqfLintData, Expression}; crate::analyze::lint!(LintS04CommandCase); impl Lint for LintS04CommandCase { - fn ident(&self) -> &str { + fn ident(&self) -> &'static str { "command_case" } @@ -16,11 +16,11 @@ impl Lint for LintS04CommandCase { 40 } - fn description(&self) -> &str { + fn description(&self) -> &'static str { "Checks command usage for casing that matches the wiki" } - fn documentation(&self) -> &str { + fn documentation(&self) -> &'static str { r#"### Configuration - **ignore**: An array of commands to ignore diff --git a/libs/sqf/src/analyze/lints/s05_if_assign.rs b/libs/sqf/src/analyze/lints/s05_if_assign.rs index 76b5f373..3ce051bd 100644 --- a/libs/sqf/src/analyze/lints/s05_if_assign.rs +++ b/libs/sqf/src/analyze/lints/s05_if_assign.rs @@ -8,7 +8,7 @@ use crate::{analyze::{extract_constant, SqfLintData}, BinaryCommand, Expression, crate::analyze::lint!(LintS05IfAssign); impl Lint for LintS05IfAssign { - fn ident(&self) -> &str { + fn ident(&self) -> &'static str { "if_assign" } @@ -16,11 +16,11 @@ impl Lint for LintS05IfAssign { 50 } - fn description(&self) -> &str { + fn description(&self) -> &'static str { "Checks if statements that are used as assignments when select or parseNumber would be more appropriate" } - fn documentation(&self) -> &str { + fn documentation(&self) -> &'static str { r#"### Example **Incorrect** diff --git a/libs/sqf/src/analyze/lints/s06_find_in_str.rs b/libs/sqf/src/analyze/lints/s06_find_in_str.rs index a14f0539..e126bff7 100644 --- a/libs/sqf/src/analyze/lints/s06_find_in_str.rs +++ b/libs/sqf/src/analyze/lints/s06_find_in_str.rs @@ -9,7 +9,7 @@ use crate::{analyze::SqfLintData, BinaryCommand, Expression, UnaryCommand}; crate::analyze::lint!(LintS06FindInStr); impl Lint for LintS06FindInStr { - fn ident(&self) -> &str { + fn ident(&self) -> &'static str { "find_in_str" } @@ -17,11 +17,11 @@ impl Lint for LintS06FindInStr { 60 } - fn description(&self) -> &str { + fn description(&self) -> &'static str { "Checks for `find` commands that can be replaced with `in`" } - fn documentation(&self) -> &str { + fn documentation(&self) -> &'static str { "### Example **Incorrect** diff --git a/libs/sqf/src/analyze/lints/s07_select_parse_number.rs b/libs/sqf/src/analyze/lints/s07_select_parse_number.rs index ac24c275..ca069dbc 100644 --- a/libs/sqf/src/analyze/lints/s07_select_parse_number.rs +++ b/libs/sqf/src/analyze/lints/s07_select_parse_number.rs @@ -10,7 +10,7 @@ use crate::{analyze::SqfLintData, parser::database::Database, BinaryCommand, Exp crate::analyze::lint!(LintS07SelectParseNumber); impl Lint for LintS07SelectParseNumber { - fn ident(&self) -> &str { + fn ident(&self) -> &'static str { "select_parse_number" } @@ -18,11 +18,11 @@ impl Lint for LintS07SelectParseNumber { 70 } - fn description(&self) -> &str { + fn description(&self) -> &'static str { "Checks for `select` commands that can be replaced with `parseNumber`" } - fn documentation(&self) -> &str { + fn documentation(&self) -> &'static str { "### Example **Incorrect** diff --git a/libs/sqf/src/analyze/lints/s08_format_args.rs b/libs/sqf/src/analyze/lints/s08_format_args.rs index 34d66ebe..e29f6966 100644 --- a/libs/sqf/src/analyze/lints/s08_format_args.rs +++ b/libs/sqf/src/analyze/lints/s08_format_args.rs @@ -8,7 +8,7 @@ use crate::{analyze::SqfLintData, Expression, UnaryCommand}; crate::analyze::lint!(LintS08FormatArgs); impl Lint for LintS08FormatArgs { - fn ident(&self) -> &str { + fn ident(&self) -> &'static str { "format_args" } @@ -16,11 +16,11 @@ impl Lint for LintS08FormatArgs { 80 } - fn description(&self) -> &str { + fn description(&self) -> &'static str { "Checks for format commands with incorrect argument counts" } - fn documentation(&self) -> &str { + fn documentation(&self) -> &'static str { r#"### Example **Incorrect** diff --git a/libs/sqf/src/analyze/lints/s09_banned_command.rs b/libs/sqf/src/analyze/lints/s09_banned_command.rs index 26dfda1c..130368f7 100644 --- a/libs/sqf/src/analyze/lints/s09_banned_command.rs +++ b/libs/sqf/src/analyze/lints/s09_banned_command.rs @@ -8,7 +8,7 @@ use crate::{analyze::SqfLintData, Expression}; crate::analyze::lint!(LintS09BannedCommand); impl Lint for LintS09BannedCommand { - fn ident(&self) -> &str { + fn ident(&self) -> &'static str { "banned_commands" } @@ -16,11 +16,11 @@ impl Lint for LintS09BannedCommand { 90 } - fn description(&self) -> &str { + fn description(&self) -> &'static str { "Checks for broken or banned commands." } - fn documentation(&self) -> &str { + fn documentation(&self) -> &'static str { r#"### Configuration - **banned**: Additional commands to check for diff --git a/libs/sqf/src/analyze/lints/s11_if_not_else.rs b/libs/sqf/src/analyze/lints/s11_if_not_else.rs index edc00e88..ab0b60b7 100644 --- a/libs/sqf/src/analyze/lints/s11_if_not_else.rs +++ b/libs/sqf/src/analyze/lints/s11_if_not_else.rs @@ -11,7 +11,7 @@ use crate::{analyze::SqfLintData, BinaryCommand, Expression, UnaryCommand}; crate::analyze::lint!(LintS11IfNotElse); impl Lint for LintS11IfNotElse { - fn ident(&self) -> &str { + fn ident(&self) -> &'static str { "if_not_else" } @@ -19,11 +19,11 @@ impl Lint for LintS11IfNotElse { 110 } - fn description(&self) -> &str { + fn description(&self) -> &'static str { "Checks for unneeded not" } - fn documentation(&self) -> &str { + fn documentation(&self) -> &'static str { r"### Example **Incorrect** diff --git a/libs/sqf/src/analyze/lints/s17_var_all_caps.rs b/libs/sqf/src/analyze/lints/s17_var_all_caps.rs index f2630eda..433f3070 100644 --- a/libs/sqf/src/analyze/lints/s17_var_all_caps.rs +++ b/libs/sqf/src/analyze/lints/s17_var_all_caps.rs @@ -11,7 +11,7 @@ use crate::{analyze::SqfLintData, Expression}; crate::analyze::lint!(LintS17VarAllCaps); impl Lint for LintS17VarAllCaps { - fn ident(&self) -> &str { + fn ident(&self) -> &'static str { "var_all_caps" } @@ -19,11 +19,11 @@ impl Lint for LintS17VarAllCaps { 170 } - fn description(&self) -> &str { + fn description(&self) -> &'static str { "Checks for global variables that are ALL_CAPS and may actually be a undefined macro" } - fn documentation(&self) -> &str { + fn documentation(&self) -> &'static str { r#"### Configuration - **ignore**: An array of vars to ignore diff --git a/libs/sqf/src/analyze/lints/s18_in_vehicle_check.rs b/libs/sqf/src/analyze/lints/s18_in_vehicle_check.rs index cccb3432..c47bc5b3 100644 --- a/libs/sqf/src/analyze/lints/s18_in_vehicle_check.rs +++ b/libs/sqf/src/analyze/lints/s18_in_vehicle_check.rs @@ -11,7 +11,7 @@ use crate::{analyze::SqfLintData, BinaryCommand, Expression, NularCommand, Unary crate::analyze::lint!(LintS18InVehicleCheck); impl Lint for LintS18InVehicleCheck { - fn ident(&self) -> &str { + fn ident(&self) -> &'static str { "in_vehicle_check" } @@ -19,11 +19,11 @@ impl Lint for LintS18InVehicleCheck { 180 } - fn description(&self) -> &str { + fn description(&self) -> &'static str { "Recommends using `isNull objectParent X` instead of `vehicle X == X`" } - fn documentation(&self) -> &str { + fn documentation(&self) -> &'static str { r"### Example **Incorrect** diff --git a/libs/sqf/src/analyze/lints/s20_bool_static_comparison.rs b/libs/sqf/src/analyze/lints/s20_bool_static_comparison.rs index a6b223e6..91789eb1 100644 --- a/libs/sqf/src/analyze/lints/s20_bool_static_comparison.rs +++ b/libs/sqf/src/analyze/lints/s20_bool_static_comparison.rs @@ -8,7 +8,7 @@ use crate::{analyze::SqfLintData, BinaryCommand, Expression}; crate::analyze::lint!(LintS20BoolStaticComparison); impl Lint for LintS20BoolStaticComparison { - fn ident(&self) -> &str { + fn ident(&self) -> &'static str { "bool_static_comparison" } @@ -16,11 +16,11 @@ impl Lint for LintS20BoolStaticComparison { 200 } - fn description(&self) -> &str { + fn description(&self) -> &'static str { "Checks for a variable being compared to `true` or `false`" } - fn documentation(&self) -> &str { + fn documentation(&self) -> &'static str { r"### Example **Incorrect** diff --git a/libs/sqf/src/analyze/lints/s21_invalid_comparisons.rs b/libs/sqf/src/analyze/lints/s21_invalid_comparisons.rs index 97cf8a95..e636049f 100644 --- a/libs/sqf/src/analyze/lints/s21_invalid_comparisons.rs +++ b/libs/sqf/src/analyze/lints/s21_invalid_comparisons.rs @@ -12,7 +12,7 @@ use crate::{analyze::SqfLintData, BinaryCommand, Expression, Statement, UnaryCom crate::analyze::lint!(LintS21InvalidComparisons); impl Lint for LintS21InvalidComparisons { - fn ident(&self) -> &str { + fn ident(&self) -> &'static str { "invalid_comparisons" } @@ -20,11 +20,11 @@ impl Lint for LintS21InvalidComparisons { 210 } - fn description(&self) -> &str { + fn description(&self) -> &'static str { "Checks for if statements with impossible or overlapping conditions" } - fn documentation(&self) -> &str { + fn documentation(&self) -> &'static str { r"### Example **Incorrect** diff --git a/libs/sqf/src/analyze/lints/s22_this_call.rs b/libs/sqf/src/analyze/lints/s22_this_call.rs index 24409a73..1e9cc50e 100644 --- a/libs/sqf/src/analyze/lints/s22_this_call.rs +++ b/libs/sqf/src/analyze/lints/s22_this_call.rs @@ -11,7 +11,7 @@ use crate::{analyze::SqfLintData, BinaryCommand, Expression}; crate::analyze::lint!(LintS22ThisCall); impl Lint for LintS22ThisCall { - fn ident(&self) -> &str { + fn ident(&self) -> &'static str { "this_call" } @@ -19,11 +19,11 @@ impl Lint for LintS22ThisCall { 220 } - fn description(&self) -> &str { + fn description(&self) -> &'static str { "Checks for usage of `_this call`, where `_this` is not necessary" } - fn documentation(&self) -> &str { + fn documentation(&self) -> &'static str { r"### Example **Incorrect** diff --git a/libs/sqf/src/analyze/lints/s23_reassign_reserved_variable.rs b/libs/sqf/src/analyze/lints/s23_reassign_reserved_variable.rs index be1c7357..3d54bc48 100644 --- a/libs/sqf/src/analyze/lints/s23_reassign_reserved_variable.rs +++ b/libs/sqf/src/analyze/lints/s23_reassign_reserved_variable.rs @@ -11,7 +11,7 @@ use crate::{analyze::SqfLintData, BinaryCommand, Expression, Statement, UnaryCom crate::analyze::lint!(LintS23ReassignReservedVariable); impl Lint for LintS23ReassignReservedVariable { - fn ident(&self) -> &str { + fn ident(&self) -> &'static str { "reasign_reserved_variable" } @@ -19,11 +19,11 @@ impl Lint for LintS23ReassignReservedVariable { 230 } - fn description(&self) -> &str { + fn description(&self) -> &'static str { "Prevents reassigning reserved variables" } - fn documentation(&self) -> &str { + fn documentation(&self) -> &'static str { r"### Example **Incorrect** diff --git a/libs/sqf/src/analyze/lints/s24_marker_spam.rs b/libs/sqf/src/analyze/lints/s24_marker_spam.rs index 060f8537..eb47d2b0 100644 --- a/libs/sqf/src/analyze/lints/s24_marker_spam.rs +++ b/libs/sqf/src/analyze/lints/s24_marker_spam.rs @@ -11,7 +11,7 @@ use crate::{analyze::SqfLintData, BinaryCommand, Expression, Statement}; crate::analyze::lint!(LintS24MarkerSpam); impl Lint for LintS24MarkerSpam { - fn ident(&self) -> &str { + fn ident(&self) -> &'static str { "marker_update_spam" } @@ -19,11 +19,11 @@ impl Lint for LintS24MarkerSpam { 240 } - fn description(&self) -> &str { + fn description(&self) -> &'static str { "Checks for repeated calls to global marker updates" } - fn documentation(&self) -> &str { + fn documentation(&self) -> &'static str { r#"### Example **Incorrect** diff --git a/libs/stringtable/src/analyze/lints/01_sorted.rs b/libs/stringtable/src/analyze/lints/01_sorted.rs index 64ed08f7..95a468d6 100644 --- a/libs/stringtable/src/analyze/lints/01_sorted.rs +++ b/libs/stringtable/src/analyze/lints/01_sorted.rs @@ -8,7 +8,7 @@ use crate::{analyze::SqfLintData, Project}; crate::analyze::lint!(LintL01Sorted); impl Lint for LintL01Sorted { - fn ident(&self) -> &str { + fn ident(&self) -> &'static str { "sorted" } @@ -16,11 +16,11 @@ impl Lint for LintL01Sorted { 10 } - fn description(&self) -> &str { + fn description(&self) -> &'static str { "Checks if stringtables are sorted" } - fn documentation(&self) -> &str { + fn documentation(&self) -> &'static str { "Stringtables should be sorted alphabetically and the keys in the order from the [Arma 3 Wiki](https://community.bistudio.com/wiki/Stringtable.xml#Supported_Languages)." } diff --git a/libs/stringtable/src/key.rs b/libs/stringtable/src/key.rs index 37d4eb17..70bdb18c 100644 --- a/libs/stringtable/src/key.rs +++ b/libs/stringtable/src/key.rs @@ -1,6 +1,7 @@ use quick_xml::escape::minimal_escape; use serde::{Deserialize, Serialize, Serializer}; +#[allow(clippy::ref_option)] // `&Option` is expected by serde fn min_escape(s: &Option, ser: S) -> Result where S: Serializer, diff --git a/libs/workspace/src/lint/mod.rs b/libs/workspace/src/lint/mod.rs index d397170c..c8eb9b51 100644 --- a/libs/workspace/src/lint/mod.rs +++ b/libs/workspace/src/lint/mod.rs @@ -8,15 +8,15 @@ use hemtt_common::config::{LintConfig, LintConfigOverride, ProjectConfig}; use crate::reporting::{Code, Codes, Diagnostic, Processed}; pub trait Lint: Sync + Send { - fn ident(&self) -> &str; + fn ident(&self) -> &'static str; fn sort(&self) -> u32 { 0 } fn doc_ident(&self) -> String { format!("{:02}", (self.sort() / 10)) } - fn description(&self) -> &str; - fn documentation(&self) -> &str; + fn description(&self) -> &'static str; + fn documentation(&self) -> &'static str; fn default_config(&self) -> LintConfig; fn minimum_severity(&self) -> Severity { self.default_config().severity() @@ -312,15 +312,15 @@ mod tests { struct LintA; impl Lint<()> for LintA { - fn ident(&self) -> &str { + fn ident(&self) -> &'static str { "LintA" } - fn description(&self) -> &str { + fn description(&self) -> &'static str { "LintA" } - fn documentation(&self) -> &str { + fn documentation(&self) -> &'static str { "LintA" } @@ -355,15 +355,15 @@ mod tests { struct LintB; impl Lint<()> for LintB { - fn ident(&self) -> &str { + fn ident(&self) -> &'static str { "LintB" } - fn description(&self) -> &str { + fn description(&self) -> &'static str { "LintB" } - fn documentation(&self) -> &str { + fn documentation(&self) -> &'static str { "LintB" } diff --git a/libs/workspace/src/reporting/diagnostic/label.rs b/libs/workspace/src/reporting/diagnostic/label.rs index d91bf778..c205e521 100644 --- a/libs/workspace/src/reporting/diagnostic/label.rs +++ b/libs/workspace/src/reporting/diagnostic/label.rs @@ -54,7 +54,7 @@ impl Label { || message .chars() .next() - .map_or(true, |c| c.is_lowercase() || !c.is_alphabetic()), + .is_none_or(|c| c.is_lowercase() || !c.is_alphabetic()), "All label messages should be lowercase (except for text copied from the source), got: {message:?}", ); label = label.with_message(message.clone());