Skip to content

Commit 5b4fff1

Browse files
authored
book: stringtable lints (#958)
* book: stringtable lints * format, typo
1 parent 6fc774a commit 5b4fff1

File tree

7 files changed

+36
-6
lines changed

7 files changed

+36
-6
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

book-gen/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ hemtt = { path = "../bin" }
88
hemtt-common = { path = "../libs/common" }
99
hemtt-config = { path = "../libs/config" }
1010
hemtt-sqf = { path = "../libs/sqf" }
11+
hemtt-stringtable = { path = "../libs/stringtable" }
1112
hemtt-workspace = { path = "../libs/workspace" }
1213

1314
arma3-wiki = { workspace = true }

book-gen/src/lints.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use hemtt_sqf::analyze::{
88
LintS02EventIncorrectCommand, LintS02EventInsufficientVersion, LintS02EventUnknown,
99
},
1010
};
11+
use hemtt_stringtable::analyze::STRINGTABLE_LINTS;
1112
use hemtt_workspace::lint::{Lint, Lints};
1213
use mdbook::book::Chapter;
1314

@@ -20,6 +21,9 @@ pub fn run(chapter: &mut Chapter) {
2021
if chapter.name == "SQF" {
2122
sqf(chapter);
2223
}
24+
if chapter.name == "Stringtables" {
25+
stringtables(chapter);
26+
}
2327
}
2428
}
2529
}
@@ -63,6 +67,19 @@ fn sqf(chapter: &mut Chapter) {
6367
chapter.content = output;
6468
}
6569

70+
fn stringtables(chapter: &mut Chapter) {
71+
let mut output = String::from("# Lints - Stringtables\n\n");
72+
let mut lint_text: Vec<(u32, String)> = Vec::new();
73+
for lint in STRINGTABLE_LINTS.iter().filter(|l| l.display()) {
74+
lint_text.push((lint.sort(), get_text(&**lint, "L-L")));
75+
}
76+
lint_text.sort_by(|a, b| a.0.cmp(&b.0));
77+
for (_, text) in lint_text {
78+
output.push_str(&text);
79+
}
80+
chapter.content = output;
81+
}
82+
6683
fn get_text<D>(lint: &Arc<Box<dyn Lint<D>>>, prefix: &str) -> String {
6784
let mut text = String::new();
6885
text.push_str(&format!("\n***\n## {}\n", lint.ident()));

book/SUMMARY.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,11 @@
5555

5656
# Reference
5757

58-
- [Analysis](analysis/index.md)
58+
- [Lints](analysis/index.md)
5959
- [Preprocessor](analysis/preprocessor.md)
6060
- [Config](analysis/config.md)
6161
- [SQF](analysis/sqf.md)
62+
- [Stringtables](analysis/stringtables.md)
6263

6364
<!--
6465
# Modding Guide

book/analysis/index.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
# Analysis
1+
# Lints
22

3-
HEMTT will analyze your project for some common issues.
3+
HEMTT will analyze your project for some common issues and best practices.
44

55
[Preprocessor](./preprocessor.md)
66
[Config](./config.md)
77
[SQF](./sqf.md)
8+
[Stringtables](./stringtables.md)

book/analysis/stringtables.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# This file will be generated, do not edit it manually

libs/stringtable/src/analyze/lints/l02_usage/mod.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl Lint<LintData> for LintL02Usage {
3838
3939
Configuration
4040
41-
- **ignore**: Array of stringtable entries to ignore
41+
- **ignore**: Array of stringtable entries to ignore, supports regex or wildcards (`*`)
4242
- **ignore_missing**: Bool to ignore missing stringtables (still written to .hemttout when disabled)
4343
- **ignore_unused**: Bool to ignore missing stringtables (still written to .hemttout when disabled)
4444
- **ignore_duplicate**: Bool to ignore missing stringtables (still written to .hemttout when disabled)
@@ -137,8 +137,16 @@ impl LintRunner<LintData> for Runner {
137137
if let Some(toml::Value::Array(ignore)) = config.option("ignore") {
138138
for i in ignore {
139139
let i_lower = i.as_str().map_or(String::new(), str::to_lowercase);
140-
unused.retain(|s| *s != i_lower);
141-
missing.retain(|sp| *sp.0 != i_lower);
140+
if i_lower.contains('*') {
141+
let regex_pattern = &i_lower.replace('*', ".*");
142+
if let Ok(re) = Regex::new(&format!("^{regex_pattern}$")) {
143+
unused.retain(|s| !re.is_match(s));
144+
missing.retain(|sp| !re.is_match(&sp.0));
145+
}
146+
} else {
147+
unused.retain(|s| *s != i_lower);
148+
missing.retain(|sp| *sp.0 != i_lower);
149+
}
142150
}
143151
}
144152
let ignore_missing = config

0 commit comments

Comments
 (0)