Skip to content

Commit

Permalink
Improved message formatting for variable assignment and defining the …
Browse files Browse the repository at this point in the history
…first positional parameter with piping
  • Loading branch information
BenedekFarkas committed Jan 17, 2023
1 parent 08e4d67 commit d000ed3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
8 changes: 5 additions & 3 deletions Lombiq.Analyzers.PowerShell/Invoke-Analyzer.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit d000ed3

Please sign in to comment.