diff --git a/Rules/UseOutputTypeCorrectly.cs b/Rules/UseOutputTypeCorrectly.cs index a41c3a23c..93d8353be 100644 --- a/Rules/UseOutputTypeCorrectly.cs +++ b/Rules/UseOutputTypeCorrectly.cs @@ -102,15 +102,20 @@ public override AstVisitAction VisitFunctionDefinition(FunctionDefinitionAst fun List> returnTypes = FindPipelineOutput.OutputTypes(funcAst, _classes); + HashSet specialTypes = new HashSet(StringComparer.OrdinalIgnoreCase); + specialTypes.Add(typeof(Unreached).FullName); + specialTypes.Add(typeof(Undetermined).FullName); + specialTypes.Add(typeof(object).FullName); + specialTypes.Add(typeof(void).FullName); + specialTypes.Add(typeof(PSCustomObject).FullName); + specialTypes.Add(typeof(PSObject).FullName); + foreach (Tuple returnType in returnTypes) { string typeName = returnType.Item1; if (String.IsNullOrEmpty(typeName) - || String.Equals(typeof(Unreached).FullName, typeName, StringComparison.OrdinalIgnoreCase) - || String.Equals(typeof(Undetermined).FullName, typeName, StringComparison.OrdinalIgnoreCase) - || String.Equals(typeof(object).FullName, typeName, StringComparison.OrdinalIgnoreCase) - || String.Equals(typeof(void).FullName, typeName, StringComparison.OrdinalIgnoreCase) + || specialTypes.Contains(typeName) || outputTypes.Contains(typeName, StringComparer.OrdinalIgnoreCase)) { continue; diff --git a/Tests/Rules/GoodCmdlet.ps1 b/Tests/Rules/GoodCmdlet.ps1 index 0fceccd60..93958ebf7 100644 --- a/Tests/Rules/GoodCmdlet.ps1 +++ b/Tests/Rules/GoodCmdlet.ps1 @@ -28,7 +28,7 @@ function Get-File HelpUri = 'http://www.microsoft.com/', ConfirmImpact='Medium')] [Alias()] - [OutputType([String], [System.Double], [Hashtable])] + [OutputType([String], [System.Double], [Hashtable], "MyCustom.OutputType")] [OutputType("System.Int32", ParameterSetName="ID")] Param @@ -91,6 +91,12 @@ function Get-File Write-Debug @b + [pscustomobject]@{ + PSTypeName = 'MyCustom.OutputType' + Prop1 = 'SomeValue' + Prop2 = 'OtherValue' + } + return @{"hash"="true"} } End