Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions Rules/AvoidAlias.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,27 @@ public IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string fileName)
commandType: CommandTypes.Cmdlet | CommandTypes.Function | CommandTypes.Script);
if (cmdletNameIfCommandWasMissingGetPrefix != null)
{
yield return new DiagnosticRecord(
string.Format(CultureInfo.CurrentCulture, Strings.AvoidUsingCmdletAliasesMissingGetPrefixError, commandName, commdNameWithGetPrefix),
GetCommandExtent(cmdAst),
GetName(),
DiagnosticSeverity.Warning,
fileName,
commandName,
suggestedCorrections: GetCorrectionExtent(cmdAst, commdNameWithGetPrefix));
if (commandName.Equals("process", StringComparison.OrdinalIgnoreCase))
{
yield return new DiagnosticRecord(
Strings.InvalidSyntaxAroundProcessBlockError,
GetCommandExtent(cmdAst),
"InvalidSyntaxAroundProcessBlock",
DiagnosticSeverity.ParseError,
fileName,
commandName);
}
else
{
yield return new DiagnosticRecord(
string.Format(CultureInfo.CurrentCulture, Strings.AvoidUsingCmdletAliasesMissingGetPrefixError, commandName, commdNameWithGetPrefix),
GetCommandExtent(cmdAst),
GetName(),
DiagnosticSeverity.Warning,
fileName,
commandName,
suggestedCorrections: GetCorrectionExtent(cmdAst, commdNameWithGetPrefix));
}
}

}
Expand Down
9 changes: 9 additions & 0 deletions Rules/Strings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Rules/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1149,4 +1149,7 @@
<data name="AvoidUsingDoubleQuotesForConstantStringError" xml:space="preserve">
<value>Use single quotes when a string is constant.</value>
</data>
<data name="InvalidSyntaxAroundProcessBlockError" xml:space="preserve">
<value>When using a process block, only a begin or end block is allowed inside the function but no code.</value>
</data>
</root>
7 changes: 7 additions & 0 deletions Tests/Rules/AvoidUsingAlias.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,12 @@ Configuration MyDscConfiguration {

$violations.Count | Should -Be $expectedViolations
}

It 'Warn about incorrect syntax around process block' {
$scriptDefinition = { function foo { IShouldNotBeHere; process {} } }
$violations = Invoke-ScriptAnalyzer -IncludeRule PSAvoidUsingCmdletAliases -ScriptDefinition "$scriptDefinition"
$violations.Count | Should -Be 1
$violations.Severity | Should -Be ([Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic.DiagnosticSeverity]::ParseError)
}
}
}