Skip to content

Commit

Permalink
Merge pull request #1251 from JamesWTruher/avoidaliasfix001
Browse files Browse the repository at this point in the history
Fix logic errors in AvoidAlias rule
  • Loading branch information
JamesWTruher authored Jun 5, 2019
2 parents 6c946c0 + 1781717 commit 9d19209
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions Rules/AvoidAlias.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,25 +126,29 @@ public IEnumerable<DiagnosticRecord> 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));
}

}
}

Expand Down Expand Up @@ -264,4 +268,4 @@ public string GetSourceName()
return string.Format(CultureInfo.CurrentCulture, Strings.SourceName);
}
}
}
}

0 comments on commit 9d19209

Please sign in to comment.