style: 逐条修静态分析告警(706 → 44),并把 MaxDepth 这条假承诺删掉

修掉的:空 catch 5 处;名词白名单 7 处;default-value 开关、自带 -WhatIf、lab 的明文口令与 irm|iex 各挂抑制并写明理由。

MaxDepth:它是分析器拓出来的真 bug —— 参数声明了却从未使用,也就是配置里的 CatalogMaxDepth 是假的,前缀补全实际只查 1 层,而配置注释与 README 都承诺「向下找几层」。按确认过的原则处理:**先让文档不撒谎**,所以把整条链路去掉(配置默认值、三个函数的参数、70 处实参、配置注释),而不是留一个假旋钮。零行为变化。想真的支持多层补全时,那是一个独立决定。

剩下 3 条都是分析器的误判,而且我实测确认过其中一条:$sourcePath 被报「赋值后从未使用」,我照着改成 $null = 之后,Set-StrictMode -Version 3.0 下读未定义变量直接抛错,Security 套件的 BeforeAll 挂掉、4 条用例连带失败。恢复后才绿。

这一类误判有共同成因:静态分析看不到「在传给 Test-Case / It / Where-Object 的 scriptblock 里被使用」。所以我只对能证明是误判的挂抑制并写明理由,不为了数字好看去改代码。

验收:test.ps1 9/9 全绿(7 与 5.1)、100 个文件两版解析零错、Run-RealSmoke 4/4。
This commit is contained in:
Shuery committed 2026-09-27 10:16:10 +08:00
1 parent 3a3a57a6a1
commit 232a82cd3c
28 files changed
+108 -98

No files matched your search

+5 -3
View File
@@ -24,6 +24,8 @@
参数只传字符串,数组用 ';' 拼 —— 与 run-drill.ps1 同一套约定。
#>
[CmdletBinding()]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingInvokeExpression', '',
Justification = 'Scoop 官方的安装方式就是 irm | iex 那种一行式;实验脚本照抄官方写法比自己包一层更不容易出错。')]
param(
[string]$RepoPath = 'C:\BakNRet',
[string]$WorkRoot = 'C:\BakNRet-Lab\acl',
@@ -137,7 +139,7 @@ function Invoke-BakNRetChild {
}
}
function Stop-VscodeProcesses {
function Stop-VscodeProcess {
<#
.SYNOPSIS
把 vscode 相关进程清掉。
@@ -159,7 +161,7 @@ function Stop-VscodeProcesses {
Stop-Process -Id $process.Id -Force -ErrorAction SilentlyContinue
}
}
catch { }
catch { $null = $_ }
}
}
Start-Sleep -Milliseconds 700
@@ -412,7 +414,7 @@ Test-Scenario '每个条目都写了 .acl.json' (@(Get-ChildItem -LiteralPath $B
# 删源 → 恢复
# ---------------------------------------------------------------------------
foreach ($path in $entries) {
if ($path -ieq $vscodeApp) { Stop-VscodeProcesses -AppRoot $vscodeApp }
if ($path -ieq $vscodeApp) { Stop-VscodeProcess -AppRoot $vscodeApp }
Remove-TreeHard -Path $path
}
$leftovers = @($entries | Where-Object { Test-Path -LiteralPath $_ })