PowerShell / PowerShell/PSScriptAnalyzer
Add rule for unused namespaces
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- C#
- Estrellas
- 2.2k
- Forks
- 414
- Merge medio
- 13 h 1 min
- PR fusionados (30 d)
- 2
Descripción
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
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza rastreando el AST raíz y las búsquedas FindAll de nodos TypeExpressionAst, TypeConstraintAst, AttributeAst y New-Object CommandAst descritas en el issue. Determina cómo se resuelven los nombres de tipos y cómo deberían manejarse New-Object, los aceleradores de tipo y los posibles alias. Se considerará completado cuando el analizador pueda identificar instrucciones using namespace no utilizadas sin eliminar namespaces a los que se hace referencia.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- csharp, powershell
- Área
- tooling
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100