Skip to content

Commit aa90ea3

Browse files
committed
use [Type]::new() constructor instead of new-object
1 parent 8eb354e commit aa90ea3

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

ScriptRuleDocumentation.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ Optionally, since version 1.17.0, a `SuggestedCorrections` property of type `IEn
7070
[string]$correction = 'Correct text that replaces Extent text'
7171
[string]$file = $MyInvocation.MyCommand.Definition
7272
[string]$optionalDescription = 'Useful but optional description text'
73-
$correctionExtent = New-Object 'Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic.CorrectionExtent' $startLineNumber,$endLineNumber,$startColumnNumber,$endColumnNumber,$correction,$description
74-
$suggestedCorrections = New-Object System.Collections.ObjectModel.Collection['Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic.CorrectionExtent']
75-
$suggestedCorrections.add($correctionExtent) | out-null
73+
$correctionExtent = [Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic.CorrectionExtent]::new($startLineNumber,$endLineNumber,$startColumnNumber,$endColumnNumber,$correction,$description)
74+
$suggestedCorrections = [System.Collections.ObjectModel.Collection['Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic.CorrectionExtent']]::new()
75+
$suggestedCorrections.Add($correctionExtent)
7676
7777
[Microsoft.Windows.Powershell.ScriptAnalyzer.Generic.DiagnosticRecord]@{
7878
"Message" = "This is a rule with a suggested correction"

Tests/Engine/samplerule/samplerule.psm1

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,16 @@ function Measure-RequiresRunAsAdministrator
2828
[System.Management.Automation.Language.ScriptBlockAst]
2929
$testAst
3030
)
31-
$l=(new-object System.Collections.ObjectModel.Collection["Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic.CorrectionExtent"])
32-
$c = (new-object Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic.CorrectionExtent 1,2,3,4,'text','filePath','description')
33-
$l.Add($c)
34-
$dr = New-Object `
35-
-Typename "Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic.DiagnosticRecord" `
36-
-ArgumentList "This is help",$ast.Extent,$PSCmdlet.MyInvocation.InvocationName,Warning,$null,$null,$l
37-
return $dr
31+
$correctionExtentList = [System.Collections.ObjectModel.Collection[Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic.CorrectionExtent]]::new()
32+
$correctionExtent = [Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic.CorrectionExtent]::new(1,2,3,4,'text','filePath','description')
33+
$correctionExtentList.Add($correctionExtent)
34+
$diagnosticRecord = [Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic.DiagnosticRecord]::new(
35+
"This is help",
36+
$ast.Extent,$PSCmdlet.MyInvocation.InvocationName,
37+
"Warning",
38+
$null,
39+
$null,
40+
$correctionExtentList)
41+
return $diagnosticRecord
3842
}
3943
Export-ModuleMember -Function Measure*

0 commit comments

Comments
 (0)