February 2019
Intermediate to advanced
626 pages
15h 51m
English
Script analyzer rules are often very simple; it is not always necessary for a rule to perform complex AST searches.
The following example evaluates the named blocks dynamicparam, begin, process, and end. If such a block is declared in a function, script, or script block, and it is empty, the rule will respond. The rule only accepts NamedBlockAst nodes; the script analyzer only passes matching nodes to the rule, and therefore, the rule itself does not have to worry about handling other node types:
using namespace Microsoft.Windows.PowerShell.ScriptAnalyzer.Genericusing namespace System.Management.Automation.Languagefunction PSAvoidEmptyNamedBlocks { [CmdletBinding()] [OutputType([Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic.DiagnosticRecord])] ...Read now
Unlock full access