-
-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1399 from Badgerati/Issue-1361
Replaces occurrences of New-Object with new()
- Loading branch information
Showing
39 changed files
with
546 additions
and
430 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,29 @@ | ||
# PSScriptAnalyzerSettings.psd1 | ||
@{ | ||
Severity = @('Error', 'Warning', 'Information') | ||
Severity = @('Error', 'Warning', 'Information') | ||
IncludeDefaultRules = $true | ||
|
||
Rules = @{ | ||
CustomRulePath = @( | ||
'./analyzers/AvoidNewObjectRule.psm1' | ||
) | ||
|
||
Rules = @{ | ||
PSReviewUnusedParameter = @{ | ||
CommandsToTraverse = @( | ||
'Where-Object','Remove-PodeRoute' | ||
'Where-Object', | ||
'Remove-PodeRoute' | ||
) | ||
} | ||
AvoidNewObjectRule = @{ | ||
Severity = 'Warning' | ||
} | ||
} | ||
ExcludeRules = @( 'PSAvoidUsingPlainTextForPassword','PSUseShouldProcessForStateChangingFunctions', | ||
'PSAvoidUsingUsernameAndPasswordParams','PSUseProcessBlockForPipelineCommand','PSAvoidUsingConvertToSecureStringWithPlainText','PSReviewUnusedParameter' ,'PSAvoidAssignmentToAutomaticVariable') | ||
|
||
ExcludeRules = @( | ||
'PSAvoidUsingPlainTextForPassword', | ||
'PSUseShouldProcessForStateChangingFunctions', | ||
'PSAvoidUsingUsernameAndPasswordParams', | ||
'PSUseProcessBlockForPipelineCommand', | ||
'PSAvoidUsingConvertToSecureStringWithPlainText', | ||
'PSReviewUnusedParameter' | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
function Measure-AvoidNewObjectRule { | ||
[CmdletBinding()] | ||
[OutputType([Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic.DiagnosticRecord[]])] | ||
param( | ||
[Parameter(Mandatory = $true)] | ||
[ValidateNotNullOrEmpty()] | ||
[System.Management.Automation.Language.ScriptBlockAst] | ||
$ScriptBlockAst | ||
) | ||
|
||
# Initialize an empty array to collect diagnostic records | ||
$diagnostics = @() | ||
|
||
try { | ||
# Traverse the AST to find all instances of New-Object cmdlet | ||
$ScriptBlockAst.FindAll({ | ||
param($Ast) | ||
$Ast -is [System.Management.Automation.Language.CommandAst] -and | ||
$Ast.CommandElements[0].Extent.Text -eq 'New-Object' | ||
}, $true) | ForEach-Object { | ||
$diagnostics += [PSCustomObject]@{ | ||
Message = "Avoid using 'New-Object' and use '::new()' instead." | ||
Extent = $_.Extent | ||
RuleName = 'AvoidNewObjectRule' | ||
Severity = 'Warning' | ||
ScriptName = $FileName | ||
} | ||
} | ||
|
||
# Return the diagnostic records | ||
return $diagnostics | ||
} | ||
catch { | ||
$PSCmdlet.ThrowTerminatingError($PSItem) | ||
} | ||
} | ||
|
||
Export-ModuleMember -Function Measure-AvoidNewObjectRule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.