From d000ed36044294702358edc891ba654f7f9ad4c6 Mon Sep 17 00:00:00 2001 From: Benedek Farkas Date: Tue, 17 Jan 2023 22:47:11 +0100 Subject: [PATCH] Improved message formatting for variable assignment and defining the first positional parameter with piping --- Lombiq.Analyzers.PowerShell/Invoke-Analyzer.ps1 | 8 +++++--- .../Measure-AutomaticVariableAlias.psm1 | 6 ++++-- .../Measure-LineContinuation.psm1 | 6 ++++-- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/Lombiq.Analyzers.PowerShell/Invoke-Analyzer.ps1 b/Lombiq.Analyzers.PowerShell/Invoke-Analyzer.ps1 index 21b546f9..020d2672 100644 --- a/Lombiq.Analyzers.PowerShell/Invoke-Analyzer.ps1 +++ b/Lombiq.Analyzers.PowerShell/Invoke-Analyzer.ps1 @@ -95,9 +95,11 @@ if ((Get-InstalledModule PSScriptAnalyzer -ErrorAction SilentlyContinue).Version catch { $infoUrl = 'https://docs.microsoft.com/en-us/powershell/utility-modules/psscriptanalyzer/overview?view=ps-modules#installing-psscriptanalyzer' - Write-FileError ('Unable to detect Invoke-ScriptAnalyzer and failed to install PSScriptAnalyzer. If you are' + - ' on Windows Powershell, open an administrator shell and type "Install-Module -Name PSScriptAnalyzer' + - " -RequiredVersion $installVersion`". Otherwise see $infoUrl to learn more.") + @( + 'Unable to detect Invoke-ScriptAnalyzer and failed to install PSScriptAnalyzer. If you are on Windows' + 'Powershell, open an administrator shell and type "Install-Module -Name PSScriptAnalyzer -RequiredVersion' + "$installVersion`". Otherwise see $infoUrl to learn more." + ) -join ' ' | Write-FileError exit -2 } } diff --git a/Lombiq.Analyzers.PowerShell/Rules/Measure-AutomaticVariableAlias/Measure-AutomaticVariableAlias.psm1 b/Lombiq.Analyzers.PowerShell/Rules/Measure-AutomaticVariableAlias/Measure-AutomaticVariableAlias.psm1 index 2a0eb567..ccff0ed0 100644 --- a/Lombiq.Analyzers.PowerShell/Rules/Measure-AutomaticVariableAlias/Measure-AutomaticVariableAlias.psm1 +++ b/Lombiq.Analyzers.PowerShell/Rules/Measure-AutomaticVariableAlias/Measure-AutomaticVariableAlias.psm1 @@ -48,8 +48,10 @@ function Measure-AutomaticVariableAlias $results += [Microsoft.Windows.Powershell.ScriptAnalyzer.Generic.DiagnosticRecord]@{ 'Extent' = $automaticVariableAliasToken.Extent - 'Message' = '"$_" is an alias of the automatic variable "$PSItem". Please consider using the full' + - ' name of this variable for consistency.' + 'Message' = @( + '"$_" is an alias of the automatic variable "$PSItem". Please use the full name of this' + 'variable for consistency.' + ) -join ' ' 'RuleName' = 'PSAvoidUsingAutomaticVariableAlias' 'RuleSuppressionID' = 'PSAvoidUsingAutomaticVariableAlias' 'Severity' = 'Warning' diff --git a/Lombiq.Analyzers.PowerShell/Rules/Measure-LineContinuation/Measure-LineContinuation.psm1 b/Lombiq.Analyzers.PowerShell/Rules/Measure-LineContinuation/Measure-LineContinuation.psm1 index 004bdfd2..34c94188 100644 --- a/Lombiq.Analyzers.PowerShell/Rules/Measure-LineContinuation/Measure-LineContinuation.psm1 +++ b/Lombiq.Analyzers.PowerShell/Rules/Measure-LineContinuation/Measure-LineContinuation.psm1 @@ -39,8 +39,10 @@ function Measure-LineContinuation { $results += [Microsoft.Windows.Powershell.ScriptAnalyzer.Generic.DiagnosticRecord]@{ 'Extent' = $lineContinuationToken.Extent - 'Message' = 'Using backtick (line continuation) makes the code harder to read and maintain.' + - ' Please use parameter splatting instead.' + 'Message' = @( + 'Using backtick (line continuation) makes the code harder to read and maintain. Please use' + 'parameter splatting instead.' + ) -join ' ' 'RuleName' = 'PSAvoidUsingLineContinuation' 'RuleSuppressionID' = 'PSAvoidUsingLineContinuation' 'Severity' = 'Warning'