-
Notifications
You must be signed in to change notification settings - Fork 1
Standards
Andrew Davidson edited this page Jan 24, 2021
·
14 revisions
Script files should
- have the keyword function and the name of the function on the same line
- have help text detailing the function of the code at the top (For functions this must be inside the function)
- have a [CmdletBinding()] property
- have an [OutputType()] property that must contain one or more OutputTypes
- have a param block (under consideration for removal and is temporarily disabled)
- have any parameters in the param block detailed with a .PARAMETER in the help text
- have variable types for all parameters
Modules should
- have one or more functions in them
- have a valid accompanying module manifest
Module manifests should
- have all public functions from the module exported
- pass a test-manifest check
When testing a module, each function is extracted and is then tested as a script file
Projects should
- adhere to the project structure
ProjectPath
|
-Source
| |
| -Module
| | |
| | -Public
| | -Private
| -Module
| |
| -Public
| -Private
-Tests
|
-Unit
|
-Module
-Module
- have one or more modules in them
- made up of individual script functions
- public functons use PowerShell approved verbs and singular nouns. For approved verbs see (for v5.1) or (for v7.1)
- public functions have a corresponding test file
- private functions do not follow the verb-noun format
- made up of individual script functions
- should not have compiled modules
When testing a project
- each function file is tested as a script file
An example of a valid functions layout:
function Get-File {
<#
.SYNOPSIS
Get the content of the file
.DESCRIPTION
Get and return the content of the passed PowerShell file
.PARAMETER Path
A string containing PowerShell filename
.EXAMPLE
Get-File -Path $File
#>
[CmdletBinding()]
[OutputType([System.String[]])]
param (
[parameter(Mandatory = $true)]
[string]$Path
)
$fileContent = Get-Content -Path $Path -Raw
return $fileContent
}