PowerShell / PowerShell/PSScriptAnalyzer

Use proper output streams for messages output by PSScriptAnalyzer

未关闭
#212 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

Issue - Enhancement Up-for-Grabs
主要语言
C#
星标
2.2k
派生
414
平均合并
13 小时 1 分钟
30 天内合并 PR
2

描述

This issue is a great example of why issue #193 should be approved and implemented.

Today if you run Invoke-ScriptAnalyzer on a moderate sized module recursively with the -Verbose switch, you get 38 verbose output messages per file in your module. For one of my modules that has 58 files (I put each function in its own file if the module is only small-to-medium in size), this results in 2204 verbose messages being sent to the console. These 2204 verbose messages are nothing but noise to me.

For each of the files that are processed, I get one verbose message that indicates a file is being analyzed and then I get 37 messages (one for each rule, so that will only grow over time) indicating that a rule is being processed for that file. Those should be progress messages, not verbose messages, and so they should be output using WriteProgress, not WriteVerbose. Verbose should be reserved for non-progress messages that provide some additional detail about what is happening behind the scenes -- some small amount of information that would be useful for the invoker to know if they want the additional detail, but that they don't see regularly. This is exactly why the PSProvideVerboseMessage rule needs to go away -- it encourages users to wrongly add verbose message output where there shouldn't be any.

The reason why I invoked Invoke-ScriptAnalyzer with -Verbose in the first place is because I wanted to see if it was writing a verbose message to the output stream when a rule is found but suppressed. It is not doing this, but that is a great example of the kind of output I would expect to be in a verbose stream for this command. This verbose output would not be noise, because it includes additional detail that is not visible by default (and rightly so) that would add value to a caller trying to figure out why a particular rule is not showing up in certain scenarios. This verbose output would also be highly useful to the community because it would allow them to catch scripts and/or modules that were a little too "suppress-happy", in which case they could inform the author about the error in their ways.

In summary, Invoke-ScriptAnalyzer should:
a) convert the current WriteVerbose calls that output what are really progress messages to the verbose stream to WriteProgress calls (this will also help wrt performance, so that end users see the progress as it is happening)
b) add WriteVerbose calls that output verbose messages indicating when a rule is suppressed, identifying the rule that is suppressed, the line/file where it would have been raised, and ideally the line/file where the attribute to suppress that rule was defined (the source of the suppression).

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 Invoke-ScriptAnalyzer 开始,定位当前用于文件和规则处理的 WriteVerbose 调用。检查进度流和 verbose 流的处理方式,然后根据 issue 中说明的标准,验证所请求的进度输出和抑制细节。描述中没有指定文件或测试,因此识别相关的实现位置和测试位置也是工作的一部分。

由索引模型根据 Issue 内容生成。

评估

技术栈
csharp, powershell
领域
cli, tooling
Issue 类型
功能
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。