Creating a custom rule
A script analyzer rule is a function within a module. A script analyzer allows rules to be written to evaluate AST nodes or tokens.
The name of the function is arbitrary. The community examples use the verb measure; however, use of this verb is not mandatory and does not affect discovery. The script analyzer engine examines each function in the custom rule module, looking for parameters following a particular style. If the such a parameter is found, the function is deemed to be a rule.
If a rule is expected to act based on an AST node, the first parameter name must end with ast. The parameter must use an AST type, such as System.Management.Automation.Language.ScriptBlockAst.
If a rule is expected to act based on a token, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access