Skip to content

Commit

Permalink
添加对疑似将匿名变量作为命令执行的lint
Browse files Browse the repository at this point in the history
  • Loading branch information
A4-Tacks committed Oct 22, 2024
1 parent 07db75b commit 56a6e35
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 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.17.5"
version = "0.17.6"
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.7"
version = "0.1.8"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
22 changes: 21 additions & 1 deletion tools/logic_lint/src/lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ macro_rules! make_lints {
},
)*
[] => unreachable!(),
[_, ..] => (),
[cmd, ..] => {
if let Some(lint) = check_cmd($src, $line, cmd) {
$lints.push(lint)
}
},
}
$lints
}
Expand Down Expand Up @@ -270,6 +274,17 @@ fn check_vars<'a>(
vars.into_iter()
.filter_map(|var| check_var(src, line, var))
}
fn check_cmd<'a>(
_src: &'a crate::Source<'a>,
_line: &'a crate::Line<'a>,
var: &'a Var<'a>,
) -> Option<Lint<'a>> {
if regex_is_match!(r"^__", var) && !regex_is_match!(r".__$", var) {
return Some(Lint::new(var, WarningLint::SuspectedVarCmd))
}

None
}
#[must_use]
fn check_argc<'a>(
_src: &'a crate::Source<'a>,
Expand Down Expand Up @@ -546,6 +561,8 @@ pub enum WarningLint {
AssignLiteral,
/// 从命名来看疑似是未被替换的常量
SuspectedConstant,
/// 从命名来看疑似将变量作为命令执行
SuspectedVarCmd,
/// 未被使用
NeverUsed,
NoTargetJump,
Expand All @@ -568,6 +585,9 @@ impl ShowLint for WarningLint {
WarningLint::SuspectedConstant => {
write!(f, "命名疑似未被替换的常量")?
},
WarningLint::SuspectedVarCmd => {
write!(f, "命令疑似将变量作为命令执行")?
},
WarningLint::NeverUsed => write!(f, "未被使用到的量")?,
WarningLint::NoTargetJump => write!(f, "没有目标的跳转")?,
}
Expand Down

0 comments on commit 56a6e35

Please sign in to comment.