Skip to content

Commit

Permalink
为lint添加显式标注未使用量的命名识别, 并修复read和write标反了的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
A4-Tacks committed Mar 28, 2024
1 parent 3655c07 commit 05d961f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mindustry_logic_bang_lang"
version = "0.15.3"
version = "0.15.4"
edition = "2021"

authors = ["A4-Tacks <[email protected]>"]
Expand Down
2 changes: 1 addition & 1 deletion tools/logic_lint/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "logic_lint"
version = "0.1.2"
version = "0.1.3"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
11 changes: 7 additions & 4 deletions tools/logic_lint/src/lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ impl VarPat {
method,
var,
}.into()),
VarPat::Lit(s) if s == var.value() => Ok(None),
VarPat::Any => Ok(None),
VarPat::Lit(s) if s == var.value() => Ok(None),
VarPat::Lit(_) => Err(()),
}
}
Expand Down Expand Up @@ -151,8 +151,8 @@ thread_local! {
};
}
make_pats! {
["read" v v v]
["write" a v v]
["read" a v v]
["write" v v v]
["draw" "clear" v v v]
["draw" "color" v v v v]
["draw" "col" v]
Expand Down Expand Up @@ -230,7 +230,9 @@ fn check_assign_var<'a>(
VarType::Var(_) => {
let mut lints = Vec::new();
lints.extend(check_var(src, line, var));
if !src.used_vars.contains(var.value()) {
if !src.used_vars.contains(var.value())
&& !regex_is_match!(r"^_(?:$|[^_])", var.value())
{
lints.push(Lint::new(var, WarningLint::NeverUsed));
}
vec_optiter(lints.into())
Expand Down Expand Up @@ -353,6 +355,7 @@ make_lints! {
}
"ulocate" (8) {
if let [_, mode, btype, args @ ..] = line.args() {
// 考虑到经常需要不用这里的参数, 所以不使用assign
lints.extend(check_oper(mode, &[
"building", "ore", "spawn", "damaged",
]));
Expand Down

0 comments on commit 05d961f

Please sign in to comment.