diff --git a/Rules/AvoidAlias.cs b/Rules/AvoidAlias.cs index ad35ec4fe..dd488527f 100644 --- a/Rules/AvoidAlias.cs +++ b/Rules/AvoidAlias.cs @@ -126,25 +126,29 @@ public IEnumerable AnalyzeScript(Ast ast, string fileName) fileName, commandName, suggestedCorrections: GetCorrectionExtent(cmdAst, cmdletNameIfCommandNameWasAlias)); + // do not continue the search, but go to the next command + continue; + } + + // If we find match of any kind, do not continue with the Get-{commandname} check + if ( Helper.Instance.GetCommandInfo(commandName) != null ) { + continue; } - var isNativeCommand = Helper.Instance.GetCommandInfo(commandName, CommandTypes.Application | CommandTypes.ExternalScript) != null; - if (!isNativeCommand) + var commdNameWithGetPrefix = $"Get-{commandName}"; + var cmdletNameIfCommandWasMissingGetPrefix = Helper.Instance.GetCommandInfo(commdNameWithGetPrefix); + if (cmdletNameIfCommandWasMissingGetPrefix != null) { - var commdNameWithGetPrefix = $"Get-{commandName}"; - var cmdletNameIfCommandWasMissingGetPrefix = Helper.Instance.GetCommandInfo($"Get-{commandName}"); - 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)); - } + yield return new DiagnosticRecord( + string.Format(CultureInfo.CurrentCulture, Strings.AvoidUsingCmdletAliasesMissingGetPrefixError, commandName, commdNameWithGetPrefix), + GetCommandExtent(cmdAst), + GetName(), + DiagnosticSeverity.Warning, + fileName, + commandName, + suggestedCorrections: GetCorrectionExtent(cmdAst, commdNameWithGetPrefix)); } + } } @@ -264,4 +268,4 @@ public string GetSourceName() return string.Format(CultureInfo.CurrentCulture, Strings.SourceName); } } -} \ No newline at end of file +}