Skip to content

[Question] Retrieve all Configurable rules #823

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
LaurentDardenne opened this issue Oct 22, 2017 · 3 comments
Closed

[Question] Retrieve all Configurable rules #823

LaurentDardenne opened this issue Oct 22, 2017 · 3 comments

Comments

@LaurentDardenne
Copy link

LaurentDardenne commented Oct 22, 2017

I try to retrieve all configurable rule with this code, but the 'AvoidAlias' rule is missing, should not this rule be of the ConfigurableRule type ?

$sb= {dir}
#Force Dll Loading
Invoke-ScriptAnalyzer -ScriptDefinition $sb.ast

$BuiltinRules= [System.AppDomain]::CurrentDomain.GetAssemblies()|? location -match 'Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules'
$BuiltinRules.GetTypes()|? {$_.IsSubclassOf([Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic.ConfigurableRule])}
@bergmeister
Copy link
Collaborator

The correct and easier way to retrieve all rules is Get-ScriptAnalyzerRule.
The alias name that you are looking for is PSAvoidUsingCmdletAliases, therefore you can retrive it using Get-ScriptAnalyzerRule -Name PSAvoidUsingCmdletAliases
I don't understand your question about ConfigurableRule type. Can you please elaborate in case this answer has not solved your question please.

@LaurentDardenne
Copy link
Author

I don't understand your question about ConfigurableRule type.
Ok.

1-The AvoidAlias class should they not be inherited from the class ConfigurableRule ?
2-Today Get-ScriptAnalyzerRule can not filter configurable rules. The documentation says 'Rule' and 'Severity' but not if the rule is configurable.

@bergmeister
Copy link
Collaborator

Aha, I see now what you mean. Yes, I think you are right that the rule should probably inherit from ConfigurableRule but filtering configurable rules in Get-ScriptAnalyzer sounds more like a new (but useful) feature to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants