PowerShell / PowerShell/PSScriptAnalyzer
Add rule for unused namespaces
還沒有人認領這個 Issue。
- 主要語言
- C#
- 星號
- 2.2k
- 分支
- 415
- 平均合併
- 13 小時 1 分鐘
- 30 天內合併 PR
- 2
描述
Summary of the new feature
It would be nice with a rule to find and remove unused using namespace statements similar to what you can do in C# in editors like VS.
Cleaning up unused namespaces can slightly improve type resolution performance and of course it makes scripts more neat and clean.
Proposed technical implementation details (optional)
Use FindAll on the root AST to find all Asts of the following types: TypeExpressionAst, TypeConstraintAst, AttributeAst and CommandAst where the command name is New-Object and try to resolve the specified TypeNames with GetReflectionType. Compare the written typename with the resolved typename and see if part of the namespace is missing, and if so if that part is listed in the list of namespaces. If it is then that namespace is in use and should stay.
For New-Object we can't use GetReflectionType so I'm not sure how to handle that. Type accelerators and in the future type/namespace aliases should probably also be taken into consideration.
What is the latest version of PSScriptAnalyzer at the point of writing
1.22.0
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
首先追蹤 issue 中描述的根 AST,以及針對 TypeExpressionAst、TypeConstraintAst、AttributeAst 和 New-Object CommandAst 節點的 FindAll 搜尋。確定型別名稱的解析方式,以及應如何處理 New-Object、型別加速器和可能的別名。完成標準是分析器能夠識別未使用的 using namespace 陳述式,同時不會移除被參照的 namespace。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- csharp, powershell
- 領域
- tooling
- Issue 類型
- 功能
- 難度
- 5/5
- 預估耗時
- 一週以上
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100