PowerShell / PowerShell/PSScriptAnalyzer
`PSPossibleIncorrectUsageOfAssignmentOperator` fires when assigning value inside `if($())`
Ninguém assumiu esta issue ainda.
- Linguagem predominante
- C#
- Estrelas
- 2.2k
- Forks
- 415
- Merge médio
- 13h 1min
- PRs com merge (30d)
- 2
Descrição
Before submitting a bug report:
- Make sure you are able to repro it on the latest released version
- Perform a quick search for existing issues to check if this bug has already been reported
Steps to reproduce
Invoke-ScriptAnalyzer -ScriptDefinition (
[scriptblock]::Create{
if (
[bool]$(Try{$null=[datetime]('2024-11-12T09:44:00Z');$?}Catch{$false})
) {
Write-Output -InputObject 'Could be parsed as datetime'
}
else {
Write-Output -InputObject 'Could not be parsed as datetime'
}
}.ToString()
) -IncludeRule 'PSPossibleIncorrectUsageOfAssignmentOperator' | Format-List
Expected behavior
Actual behavior
RuleName : PSPossibleIncorrectUsageOfAssignmentOperator
Severity : Warning
Line : 3
Column : 30
Message : Did you mean to use the assignment operator '='? The equality operator in PowerShell is 'eq'.
If an unexpected error was thrown then please report the full error details using e.g. $error[0] | Select-Object *
Environment data
PS > $PSVersionTable
Name Value
---- -----
PSVersion 7.4.6
PSEdition Core
GitCommitId 7.4.6
OS Microsoft Windows 10.0.26100
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
PS > (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }
1.23.0
PS >
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Direção de pesquisa
Comece com a reprodução fornecida do Invoke-ScriptAnalyzer e a regra PSPossibleIncorrectUsageOfAssignmentOperator. Rastreie como a expressão aninhada if($()) é analisada e, em seguida, verifique a cobertura existente das regras para um caso de regressão. Considera-se concluído quando a reprodução não relatar mais esse falso positivo e as verificações existentes do analisador continuarem passando.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- csharp, powershell
- Domínio
- tooling
- Tipo de issue
- Bug
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Status de atividade
- Estagnada
- Clareza
- Precisa de esclarecimento
- Facilidade para iniciantes
- 35/100