PowerShell / PowerShell/PSScriptAnalyzer
Rule request: Prefix parameters with an unambiguous (ASCII) hyphen-minus
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
Hyphen-minus characters are sometimes unintendedly replaced when passed by word processors as Microsoft Office applications as MSWord and Outlook. It is recommended to prefix parameters with an unambiguous hyphen-minus as Unicode dashes might cause parsing errors in earlier versions of PowerShell.
Besides it unnecessary triggers the UseBOMForUnicodeEncodedFile rule with no clear indication of the location.
PowerShell 7
# .\Test.ps1
Write-Host “test” –ForegroundColor ‘Red’ -BackgroundColor ‘Green’
Invoke-ScriptAnalyzer .\Test.ps1
RuleName Severity ScriptName Line Message
-------- -------- ---------- ---- -------
PSAvoidUsingWriteHost Warning Test.ps1 1 File 'Test.ps1' uses Write-Host. Avoid using
Write-Host because it might not work in all hosts,
does not work when there is no host, and (prior to
PS 5.0) cannot be suppressed, captured, or
redirected. Instead, use Write-Output,
Write-Verbose, or Write-Information.
PSUseBOMForUnicodeEncodedFile Warning Test.ps1 Missing BOM encoding for non-ASCII encoded file
'Test.ps1'
Windows PowerShell (5.1)
Windows PowerShell (5.1) still has issue with EM-dashes:
.\test.ps1
At C:\Users\Gebruiker\downloads\Test.ps1:1 char:25
+ ... “test†–ForegroundColor ‘Red’ -BackgroundColor ‘Green’
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The string is missing the terminator: ".
+ CategoryInfo : ParserError: (:) [], ParseException
+ FullyQualifiedErrorId : TerminatorExpectedAtEndOfString
Invoke-ScriptAnalyzer .\Test.ps1
RuleName Severity ScriptName Line Message
-------- -------- ---------- ---- -------
TerminatorExpectedAtEndOfString ParseError Test.ps1 1 The string is missing the terminator: ".
PSAvoidUsingWriteHost Warning Test.ps1 1 File 'Test.ps1' uses Write-Host. Avoid using
Write-Host because it might not work in all hosts,
does not work when there is no host, and (prior to
PS 5.0) cannot be suppressed, captured, or
redirected. Instead, use Write-Output,
Write-Verbose, or Write-Information.
PSUseBOMForUnicodeEncodedFile Warning Test.ps1 Missing BOM encoding for non-ASCII encoded file
'Test.ps1'
Proposed technical implementation details (optional)
See (PowerShell based) prototype UseHyphenMinusForParameter at: https://github.com/iRon7/PSRules
What is the latest version of PSScriptAnalyzer at the point of writing
1.21.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 con los ejemplos de PowerShell del issue y revisa el prototipo enlazado UseHyphenMinusForParameter en PSRules. Compara el comportamiento propuesto con las reglas existentes de PSScriptAnalyzer y la salida de UseBOMForUnicodeEncodedFile. La tarea estará terminada cuando los caracteres de guion Unicode usados para anteponer parámetros se detecten con una ubicación y un diagnóstico claros, incluidos los casos de PowerShell mostrados.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- powershell
- Área
- tooling
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100