Closed
Description
Invoke-Formatter will convert "?" to "%".
Before formatting
1..10 | ? { ($_ % 2) -eq 0 }
After formatting
1..10 | % { ($_ % 2) -eq 0 }
I found this bug when I research PowerShell/vscode-powershell#1842 and PowerShell/vscode-powershell#1849 .
It's a ridiculous bug.
Steps to reproduce
In the standalone Windows PowerShell console.
PS C:\> Get-Module PSScriptAnalyzer -ListAvailable
PS C:\> Install-Module PSScriptAnalyzer -Force -Scope CurrentUser
PS C:\> Get-Module PSScriptAnalyzer -ListAvailable
Directory: C:\Users\Administrator\Documents\WindowsPowerShell\Modules
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Script 1.18.0 PSScriptAnalyzer {Get-ScriptAnalyzerRule, Invoke-ScriptAnalyzer, Invoke-Formatter}
PS C:\> Invoke-Formatter '1..10 | ? { ($_ % 2) -eq 0 }' -Verbose
VERBOSE: Using settings file at C:\Users\Administrator\Documents\WindowsPowerShell\Modules\PSScriptAnalyzer\1.18.0\Settings\CodeFormatting.psd1.
VERBOSE: Analyzing Script Definition.
VERBOSE: Running PSPlaceCloseBrace rule.
VERBOSE: Found 0 violations.
VERBOSE: Fixed 0 violations.
VERBOSE: Analyzing Script Definition.
VERBOSE: Running PSPlaceOpenBrace rule.
VERBOSE: Found 0 violations.
VERBOSE: Fixed 0 violations.
VERBOSE: Analyzing Script Definition.
VERBOSE: Running PSUseConsistentWhitespace rule.
VERBOSE: Found 0 violations.
VERBOSE: Fixed 0 violations.
VERBOSE: Analyzing Script Definition.
VERBOSE: Running PSUseConsistentIndentation rule.
VERBOSE: Found 0 violations.
VERBOSE: Fixed 0 violations.
VERBOSE: Analyzing Script Definition.
VERBOSE: Running PSAlignAssignmentStatement rule.
VERBOSE: Found 0 violations.
VERBOSE: Fixed 0 violations.
VERBOSE: Analyzing Script Definition.
VERBOSE: Running PSUseCorrectCasing rule.
VERBOSE: Found 1 violations.
VERBOSE: Fixed 1 violations.
1..10 | % { ($_ % 2) -eq 0 }
Environment data
PS C:\> $PSVersionTable
Name Value
---- -----
PSVersion 5.1.17763.316
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.17763.316
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
PS C:\> (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }
1.18.0