PowerShell / PowerShell/PSScriptAnalyzer
Rule Idea: Pipeline Type Checking against Output
还没有人认领这个 Issue。
- 主要语言
- C#
- 星标
- 2.2k
- 派生
- 414
- 平均合并
- 13 小时 1 分钟
- 30 天内合并 PR
- 2
描述
This is just a spitball idea to contribute feedback if it is maybe feasible, I might consider attempting a PR
Problem
Often when writing a pipeline you may pipe an incompatible type, and you won't find out until runtime.
Proposed solution
If the output type of a function can be explicitly determined by:
- Use the .OUTPUT comment based help section to define the output type of a function
- Take all explicit return keywords that explicitly cast to a type e.g.
return [MyType]@{}or can be simply derived from a typed variable e.g.$f = [MyType]::new();return $f
And the function being called either to or from meets the following criteria:
- Has strictly typed non-primitive parameter or ValueFromPipeline
Then we should be able to safely issue a warning or error stating something like "MyFunction expected [MyType] but is receiving [WrongType] via the pipeline" as a static analysis.
#Issues
- Easily castable types like string we have to exclude, they will basically always match
- Probably should support/detect explicit casts or interfaces
Prior Art
How JSDoc can be used to test for type safety in normally-untyped javascript.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先查看 issue 中描述的拟议输出类型来源、管道参数检查、类型转换例外以及 JSDoc 先例。在实现之前定义分析器的入口点和范围;完成的标准是,确定的方案能够检测不兼容的管道类型,同时排除可安全转换的值,并处理显式转换或接口。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- powershell
- 领域
- tooling
- Issue 类型
- 功能
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 25/100