@@ -5,6 +5,7 @@ This documentation serves as a basic guideline on how to define customized rules
55
66###Basics
771 . Function should have comment-based help. Make sure .DESCRIPTION field is there, as it will be consumed as rule description for the customized rule.
8+ ```
89<#
910.SYNOPSIS
1011 Name of your rule.
@@ -15,30 +16,35 @@ This documentation serves as a basic guideline on how to define customized rules
1516.OUTPUTS
1617.NOTES
1718#>
19+ ```
1820
19212 . Output type should be DiagnosticRecord:
2022[ OutputType([ Microsoft.Windows.Powershell.ScriptAnalyzer.Generic.DiagnosticRecord[ ]] )]
2123
22243 . Make sure the function takes either a Token or an Ast as a parameter
25+ ```
2326Param
2427 (
2528 [Parameter(Mandatory = $true)]
2629 [ValidateNotNullOrEmpty()]
2730 [System.Management.Automation.Language.ScriptBlockAst]
2831 $testAst
2932 )
30-
33+ ```
31345 . DiagnosticRecord should have four properties: Message, Extent, RuleName and Severity
32- $result = [ Microsoft.Windows.Powershell.ScriptAnalyzer.Generic.DiagnosticRecord[ ]] @{"Message" = "this is help";
33- "Extent" = $ast.Extent;
34- "RuleName" = $PSCmdlet.MyInvocation.InvocationName;
35- "Severity" = "Warning"}
36-
35+ ```
36+ $result = [Microsoft.Windows.Powershell.ScriptAnalyzer.Generic.DiagnosticRecord[]]@{"Message" = "This is a sample rule";
37+ "Extent" = $ast.Extent;
38+ "RuleName" = $PSCmdlet.MyInvocation.InvocationName;
39+ "Severity" = "Warning"}
40+ ```
37416 . Make sure you export the function(s) at the end of the script using Export-ModuleMember
42+ ```
3843Export-ModuleMember -Function (FunctionName)
44+ ```
3945
4046###Example
41-
47+ ```
4248<#
4349.SYNOPSIS
4450 Uses #Requires -RunAsAdministrator instead of your own methods.
@@ -144,5 +150,5 @@ function Measure-RequiresRunAsAdministrator
144150 }
145151 }
146152}
147-
153+ ```
148154More examples can be found in * Tests\Engine\CommunityRules*
0 commit comments