Get-ScriptCopRule.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
function Get-ScriptCopRule
{
    <#
    .Synopsis
        Gets all of the script cop rules.
    .Description
        Gets all of the script cop rules, and the relative path to the file defining the rule
    .Example
        Get-ScriptCopRule
    .Link
        Test-Command
    #>

    param()
    
    begin {
        if (-not $script:ScriptCopRules) {
            $script:ScriptCopRules = @{
                TestCommandInfo = @()
                TestCmdletInfo = @()
                TestScriptInfo = @()
                TestFunctionInfo = @()
                TestApplicationInfo=  @()
                TestModuleInfo = @()
                TestScriptToken = @()
                TestHelpContent = @()
            }
        }
    }
    
    process {
        $script:ScriptCopRules | 
            Select-Object -ExpandProperty Values | 
            Select-Object -Unique |
            ForEach-Object { $_ } |
            ForEach-Object { $_ } |
            Select-Object Name, @{
                Label='File'
                Expression={
                    if ($_.Path){ $_.Path.Replace("$psScriptRoot\", "") } else { $_.ScriptBlock.File.Replace("$psScriptRoot\", "") } 
                    
                }
            } | 
            ForEach-Object {
                $_.psObject.typenames.clear()
                $null = $_.psObject.typenames.Add('ScriptcopRule')
                $_
            }
    }
}