diff --git a/Engine/ScriptAnalyzer.cs b/Engine/ScriptAnalyzer.cs index 01b4ef3cd..46150f2c3 100644 --- a/Engine/ScriptAnalyzer.cs +++ b/Engine/ScriptAnalyzer.cs @@ -1667,8 +1667,7 @@ private List RemoveTypeNotFoundParseErrors(ParseError[] parseErrors, } else { - diagnosticRecords.Add(new DiagnosticRecord( - string.Format(Strings.TypeNotFoundParseErrorFound, parseError.Extent), parseError.Extent, "TypeNotFound", DiagnosticSeverity.Information, parseError.Extent.File)); + outputWriter.WriteWarning(string.Format(Strings.TypeNotFoundParseErrorFound, parseError.Extent, parseError.Extent.StartLineNumber, parseError.Extent.File)); } } diff --git a/Engine/Strings.Designer.cs b/Engine/Strings.Designer.cs index 077b3a591..6ee90cc91 100644 --- a/Engine/Strings.Designer.cs +++ b/Engine/Strings.Designer.cs @@ -592,7 +592,7 @@ internal static string TextLinesNoNullItem { } /// - /// Looks up a localized string similar to Ignoring 'TypeNotFound' parse error on type '{0}'. Check if the specified type is correct. This can also be due the type not being known at parse time due to types imported by 'using' statements.. + /// Looks up a localized string similar to Ignoring 'TypeNotFound' parse error of type '{0}' in line {1} of file '{2}'. Check if the specified type is correct. This can also be due the type not being known at parse time due to types imported by 'using' statements.. /// internal static string TypeNotFoundParseErrorFound { get { diff --git a/Engine/Strings.resx b/Engine/Strings.resx index 743c3ccad..4f9c6321c 100644 --- a/Engine/Strings.resx +++ b/Engine/Strings.resx @@ -325,6 +325,6 @@ Settings object could not be resolved. - Ignoring 'TypeNotFound' parse error on type '{0}'. Check if the specified type is correct. This can also be due the type not being known at parse time due to types imported by 'using' statements. + Ignoring 'TypeNotFound' parse error of type '{0}' in line {1} of file '{2}'. Check if the specified type is correct. This can also be due the type not being known at parse time due to types imported by 'using' statements. \ No newline at end of file diff --git a/Tests/Engine/InvokeScriptAnalyzer.tests.ps1 b/Tests/Engine/InvokeScriptAnalyzer.tests.ps1 index c43cac665..f1d5db88c 100644 --- a/Tests/Engine/InvokeScriptAnalyzer.tests.ps1 +++ b/Tests/Engine/InvokeScriptAnalyzer.tests.ps1 @@ -181,15 +181,15 @@ Describe "Test Path" { $numFilesResult | Should -Be $numFilesExpected } } - + Context "When piping in files" { It "Can be piped in from a string" { $piped = ("$directory\TestScript.ps1" | Invoke-ScriptAnalyzer) $explicit = Invoke-ScriptAnalyzer -Path $directory\TestScript.ps1 - + $piped.Count | Should Be $explicit.Count } - + It "Can be piped from Get-ChildItem" { $piped = ( Get-ChildItem -Path $directory -Filter TestTestPath*.ps1 | Invoke-ScriptAnalyzer) $explicit = Invoke-ScriptAnalyzer -Path $directory\TestTestPath*.ps1 @@ -410,7 +410,7 @@ Describe "Test CustomizedRulePath" { Pop-Location } } - + It "resolves rule preset when passed in via pipeline" { $warnings = 'CodeFormattingStroustrup' | ForEach-Object { Invoke-ScriptAnalyzer -ScriptDefinition 'if ($true){}' -Settings $_} @@ -552,8 +552,8 @@ Describe "Test -EnableExit Switch" { else { $result = powershell -command 'Invoke-Scriptanalyzer -ScriptDefinition gci -ReportSummary' } - - "$result" | Should -BeLike $reportSummaryFor1Warning + + "$result" | Should -BeLike $reportSummaryFor1Warning } It "does not print the report summary when not using -NoReportSummary switch" { if ($IsCoreCLR) { @@ -562,14 +562,15 @@ Describe "Test -EnableExit Switch" { else { $result = powershell -command 'Invoke-Scriptanalyzer -ScriptDefinition gci' } - - "$result" | Should -Not -BeLike $reportSummaryFor1Warning + + "$result" | Should -Not -BeLike $reportSummaryFor1Warning } } # using statements are only supported in v5+ if (!$testingLibraryUsage -and ($PSVersionTable.PSVersion -ge [Version]'5.0.0')) { Describe "Handles parse errors due to unknown types" { + $expectedWarning = "Ignoring 'TypeNotFound' parse error of type 'IStorageContext' in line 4 of file '*" $script = @' using namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels using namespace Microsoft.Azure.Commands.Common.Authentication.Abstractions @@ -577,17 +578,17 @@ Describe "Test -EnableExit Switch" { class MyClass { [IStorageContext]$StorageContext } # This will result in a parser error due to [IStorageContext] type that comes from the using statement but is not known at parse time '@ It "does not throw and detect one expected warning after the parse error has occured when using -ScriptDefintion parameter set" { - $warnings = Invoke-ScriptAnalyzer -ScriptDefinition $script - $warnings.Count | Should -Be 1 - $warnings.RuleName | Should -Be 'TypeNotFound' + Invoke-ScriptAnalyzer -ScriptDefinition $script -WarningVariable warning 3> $null | Should -BeNullOrEmpty + $warning.Count | Should -Be 1 + $warning[0] | Should -BeLike $expectedWarning } $testFilePath = "TestDrive:\testfile.ps1" Set-Content $testFilePath -value $script It "does not throw and detect one expected warning after the parse error has occured when using -Path parameter set" { - $warnings = Invoke-ScriptAnalyzer -Path $testFilePath - $warnings.Count | Should -Be 1 - $warnings.RuleName | Should -Be 'TypeNotFound' + Invoke-ScriptAnalyzer -Path $testFilePath -WarningVariable warning 3> $null | Should -BeNullOrEmpty + $warning.Count | Should -Be 1 + $warning[0] | Should -BeLike $expectedWarning } } }