PowerShell / PowerShell/PSScriptAnalyzer

PSScriptAnalyzer doesn't seem to be using the SuppressMessageAttribute ctor fields as intended.

Abierto
#276 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Issue - Enhancement
Lenguaje dominante
C#
Estrellas
2.2k
Forks
414
Merge medio
13 h 1 min
PR fusionados (30 d)
2

Descripción

So here is an example of how PSScriptAnalyzer is using this attribute to target a parameter:

[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSProvideDefaultParameterValue", "b")]
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSProvideDefaultParameterValue", "a")]
Param([string]$a, [int]$b)

But the intent of the first two parameters of the SuppressMessageAttribute constructor are to uniquely identify the suppressed rule, and to apply to a parameter would use the MessageId property e.g.:

[SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "isChecked")]
[SuppressMessage("Microsoft.Performance", "CA1804:RemoveUnusedLocals", MessageId = "fileIdentifier")]
static void FileNode(string name, bool isChecked)

So I would expect that every PowerShell suppression of a built-in rule would start like this:

[Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.PowerShell", "PSAvoidUsingCmdletAliases")]

This identifies the rule as a built-in rule. I could imagine custom rules would use their module/assembly name in the first field (category).

Suppression of a parameter should look like:

[Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.PowerShell", "PSProvideDefaultParameterValue", MessageId="b")]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.PowerShell", "PSProvideDefaultParameterValue", MessageId="a")]
Param([string]$a, [int]$b)

Note that MessageId is the field that is supposed to be used if Scope/Target aren't sufficiently precise.

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza localizando el código de PSScriptAnalyzer que interpreta SuppressMessageAttribute y rastreando cómo se gestionan sus argumentos de constructor y MessageId. Compara las supresiones dirigidas a parámetros con la semántica del atributo mostrada en el issue; se considera terminado cuando las supresiones de reglas integradas usan los campos de categoría y regla, mientras que los destinos específicos de parámetros usan MessageId.

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
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.