Skip to content

Commit

Permalink
lint for stringtables being sorted
Browse files Browse the repository at this point in the history
  • Loading branch information
BrettMayson committed Oct 21, 2024
1 parent 73292eb commit 04653db
Show file tree
Hide file tree
Showing 55 changed files with 619 additions and 271 deletions.
8 changes: 7 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions bin/src/commands/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ use crate::{
context::{self, Context},
error::Error,
executor::Executor,
modules::{bom::BOMCheck, pbo::Collapse, Binarize, Files, Hooks, Rapifier, SQFCompiler},
modules::{pbo::Collapse, Binarize, Files, Rapifier},
report::Report,
};

use super::global_modules;

#[must_use]
pub fn cli() -> Command {
add_just(add_args(
Expand Down Expand Up @@ -82,15 +84,13 @@ pub fn execute(matches: &ArgMatches) -> Result<Report, Error> {
#[must_use]
pub fn executor(ctx: Context, matches: &ArgMatches) -> Executor {
let mut executor = Executor::new(ctx);
global_modules(&mut executor);

executor.collapse(Collapse::No);

executor.add_module(Box::<BOMCheck>::default());
executor.add_module(Box::<Hooks>::default());
if matches.get_one::<bool>("no-rap") != Some(&true) {
executor.add_module(Box::<Rapifier>::default());
}
executor.add_module(Box::new(SQFCompiler::default()));
if matches.get_one::<bool>("no-bin") != Some(&true) {
executor.add_module(Box::<Binarize>::default());
}
Expand Down
7 changes: 3 additions & 4 deletions bin/src/commands/check.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use clap::Command;

use crate::{
commands::global_modules,
context::Context,
error::Error,
executor::Executor,
modules::{bom::BOMCheck, pbo::Collapse, Binarize, Hooks, Rapifier, SQFCompiler},
modules::{pbo::Collapse, Binarize, Rapifier},
report::Report,
};

Expand All @@ -25,13 +26,11 @@ pub fn execute() -> Result<Report, Error> {
)?;

let mut executor = Executor::new(ctx);
global_modules(&mut executor);

executor.collapse(Collapse::Yes);

executor.add_module(Box::<BOMCheck>::default());
executor.add_module(Box::<Hooks>::default());
executor.add_module(Box::<Rapifier>::default());
executor.add_module(Box::<SQFCompiler>::default());
executor.add_module(Box::<Binarize>::new(Binarize::new(true)));

info!("Running checks");
Expand Down
9 changes: 3 additions & 6 deletions bin/src/commands/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ use clap::{ArgAction, ArgMatches, Command};
use hemtt_workspace::addons::Location;

use crate::{
commands::global_modules,
context::Context,
error::Error,
executor::Executor,
modules::{
bom::BOMCheck, pbo::Collapse, Binarize, FilePatching, Files, Hooks, Rapifier, SQFCompiler,
},
modules::{pbo::Collapse, Binarize, FilePatching, Files, Rapifier},
report::Report,
};

Expand Down Expand Up @@ -124,15 +123,13 @@ pub fn context(
}

let mut executor = Executor::new(ctx);
global_modules(&mut executor);

executor.collapse(Collapse::Yes);

executor.add_module(Box::<BOMCheck>::default());
executor.add_module(Box::<Hooks>::default());
if rapify && matches.get_one::<bool>("no-rap") != Some(&true) {
executor.add_module(Box::<Rapifier>::default());
}
executor.add_module(Box::new(SQFCompiler::default()));
executor.add_module(Box::<Files>::default());
executor.add_module(Box::<FilePatching>::default());
if force_binarize || matches.get_one::<bool>("binarize") == Some(&true) {
Expand Down
12 changes: 12 additions & 0 deletions bin/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,15 @@ pub mod script;
pub mod utils;
pub mod value;
pub mod wiki;

/// Adds modules that should apply to:
/// - hemtt check
/// - hemtt dev
/// - hemtt build
/// - hemtt release
pub fn global_modules(executor: &mut crate::executor::Executor) {
executor.add_module(Box::<crate::modules::bom::BOMCheck>::default());
executor.add_module(Box::<crate::modules::Hooks>::default());
executor.add_module(Box::<crate::modules::Stringtables>::default());
executor.add_module(Box::<crate::modules::SQFCompiler>::default());
}
17 changes: 9 additions & 8 deletions bin/src/modules/mod.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
use crate::{context::Context, error::Error, report::Report};

pub mod archive;
pub mod bom;
pub mod hook;
pub mod pbo;

pub use hook::Hooks;

mod binarize;
mod file_patching;
mod files;
mod new;
mod rapifier;
pub(crate) mod sign;
mod sqf;
mod stringtables;

pub mod archive;
pub mod bom;
pub mod hook;
pub mod pbo;
pub(crate) mod sign;

pub use binarize::Binarize;
pub use file_patching::FilePatching;
pub use files::Files;
pub use hook::Hooks;
pub use new::Licenses;
pub use rapifier::Rapifier;
pub use sign::Sign;
pub use sqf::SQFCompiler;
pub use stringtables::Stringtables;

pub trait Module {
fn name(&self) -> &'static str;
Expand Down
4 changes: 2 additions & 2 deletions bin/src/modules/rapifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{
sync::atomic::{AtomicU16, Ordering},
};

use hemtt_config::{lint_check, parse, rapify::Rapify};
use hemtt_config::{analyze::lint_check, parse, rapify::Rapify};
use hemtt_preprocessor::Processor;
use hemtt_workspace::{addons::Addon, WorkspacePath};
use rayon::prelude::{IntoParallelRefIterator, ParallelIterator};
Expand All @@ -25,7 +25,7 @@ impl Module for Rapifier {

fn check(&self, ctx: &Context) -> Result<Report, Error> {
let mut report = Report::new();
report.extend(lint_check(ctx.config()));
report.extend(lint_check(ctx.config().lints().config().clone()));
Ok(report)
}

Expand Down
8 changes: 1 addition & 7 deletions bin/src/modules/sqf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,7 @@ impl Module for SQFCompiler {

fn check(&self, ctx: &Context) -> Result<Report, Error> {
let mut report = Report::new();
report.extend(lint_check(
ctx.config(),
self.database
.as_ref()
.expect("database not initialized")
.clone(),
));
report.extend(lint_check(ctx.config().lints().sqf().clone()));
Ok(report)
}

Expand Down
36 changes: 36 additions & 0 deletions bin/src/modules/stringtables/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use hemtt_stringtable::analyze::{lint_addons, lint_check};

use crate::{context::Context, report::Report, Error};

use super::Module;

#[derive(Debug, Default)]
pub struct Stringtables;
impl Stringtables {
#[must_use]
pub const fn new() -> Self {
Self
}
}

impl Module for Stringtables {
fn name(&self) -> &'static str {
"Stringtables"
}

fn check(&self, ctx: &crate::context::Context) -> Result<crate::report::Report, crate::Error> {
let mut report = Report::new();
report.extend(lint_check(ctx.config().lints().sqf().clone()));
Ok(report)
}

fn pre_build(&self, ctx: &Context) -> Result<Report, Error> {
let mut report = Report::new();
report.extend(lint_addons(
ctx.workspace_path().to_owned(),
&ctx.addons().to_vec(),
Some(ctx.config()),
));
Ok(report)
}
}
5 changes: 3 additions & 2 deletions bin/src/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,9 @@ fn filter_codes(
true
} else {
!c.include()
&& c.diagnostic()
.map_or(true, |d| !d.labels.iter().all(|l| l.file().is_include()))
&& c.diagnostic().map_or(true, |d| {
d.labels.is_empty() || !d.labels.iter().all(|l| l.file().is_include())
})
}
})
.cloned()
Expand Down
2 changes: 1 addition & 1 deletion book-lints/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::sync::Arc;

use arma3_wiki::Wiki;
use hemtt_config::CONFIG_LINTS;
use hemtt_config::analyze::CONFIG_LINTS;
use hemtt_sqf::analyze::{
lints::s02_event_handlers::{
LintS02EventIncorrectCommand, LintS02EventInsufficientVersion, LintS02EventUnknown,
Expand Down
17 changes: 15 additions & 2 deletions libs/common/src/config/project/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq)]
/// Lint group config
pub struct LintGroupConfig {
/// Lints for config
config: HashMap<String, LintConfigOverride>,
sqf: HashMap<String, LintConfigOverride>,
stringtables: HashMap<String, LintConfigOverride>,
}

impl LintGroupConfig {
Expand All @@ -25,6 +25,12 @@ impl LintGroupConfig {
&self.sqf
}

#[must_use]
/// Get the stringtables lints
pub const fn stringtables(&self) -> &HashMap<String, LintConfigOverride> {
&self.stringtables
}

pub fn is_empty(&self) -> bool {
self.config.is_empty() && self.sqf.is_empty()
}
Expand Down Expand Up @@ -103,7 +109,7 @@ impl LintConfig {
}

#[allow(clippy::module_name_repetitions)]
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[derive(Clone, Default, Debug, PartialEq, Deserialize, Serialize)]
pub struct LintConfigOverride {
enabled: Option<bool>,
severity: Option<Severity>,
Expand Down Expand Up @@ -147,6 +153,7 @@ impl LintConfigOverride {
pub struct LintSectionFile {
pub config: Option<HashMap<String, LintConfigFile>>,
pub sqf: Option<HashMap<String, LintConfigFile>>,
pub stringtables: Option<HashMap<String, LintConfigFile>>,
}

impl From<LintSectionFile> for LintGroupConfig {
Expand All @@ -164,6 +171,12 @@ impl From<LintSectionFile> for LintGroupConfig {
.into_iter()
.map(|(k, v)| (k, v.into()))
.collect(),
stringtables: file
.stringtables
.unwrap_or_default()
.into_iter()
.map(|(k, v)| (k, v.into()))
.collect(),
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions libs/config/src/analyze/cfgpatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,20 @@ pub struct CfgPatch {
}

impl CfgPatch {
#[must_use]
pub const fn new(name: Ident, required_version: Version) -> Self {
Self {
name,
required_version,
}
}

#[must_use]
pub const fn name(&self) -> &Ident {
&self.name
}

#[must_use]
pub const fn required_version(&self) -> &Version {
&self.required_version
}
Expand Down
3 changes: 2 additions & 1 deletion libs/config/src/analyze/chumsky.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ impl Code for ChumskyCode {
}

impl ChumskyCode {
#[must_use]
pub fn new(err: Simple<char>, processed: &Processed) -> Self {
Self {
err,
Expand All @@ -33,7 +34,7 @@ impl ChumskyCode {
}

fn generate_processed(mut self, processed: &Processed) -> Self {
self.diagnostic = Diagnostic::new_for_processed(&self, self.err.span(), processed);
self.diagnostic = Diagnostic::from_code_processed(&self, self.err.span(), processed);
if let Some(diag) = &mut self.diagnostic {
diag.notes.push(format!(
"The processed output of the line with the error was:\n{} ",
Expand Down
Loading

0 comments on commit 04653db

Please sign in to comment.