|
| 1 | +--- |
| 2 | +external help file: Microsoft.Windows.PowerShell.ScriptAnalyzer.dll-Help.xml |
| 3 | +schema: 2.0.0 |
| 4 | +--- |
| 5 | + |
| 6 | +# Invoke-Formatter |
| 7 | + |
| 8 | +## SYNOPSIS |
| 9 | +Formats a script text based on the input settings or default settings. |
| 10 | + |
| 11 | +## SYNTAX |
| 12 | + |
| 13 | +``` |
| 14 | +Invoke-Formatter [-ScriptDefinition] <String> [-Settings <object>] |
| 15 | +``` |
| 16 | + |
| 17 | +## DESCRIPTION |
| 18 | + |
| 19 | +The `Invoke-Formatter` cmdlet takes a string parameter named `ScriptDefinition` and formats it according to the input settings parameter `Settings`. If no `Settings` parameter is provided, the cmdlet assumes the default code formatting settings as defined in `Settings/CodeFormatting.psd`. |
| 20 | + |
| 21 | +## EXAMPLES |
| 22 | + |
| 23 | +### -------------------------- EXAMPLE 1 -------------------------- |
| 24 | +``` |
| 25 | +$scriptDefinition = @' |
| 26 | +function foo { |
| 27 | +"hello" |
| 28 | + } |
| 29 | +'@ |
| 30 | +
|
| 31 | +Invoke-Formatter -ScriptDefinition $scriptDefinition |
| 32 | +``` |
| 33 | + |
| 34 | +This command formats the input script text using the default settings. |
| 35 | + |
| 36 | +### -------------------------- EXAMPLE 2 -------------------------- |
| 37 | +``` |
| 38 | +$scriptDefinition = @' |
| 39 | +function foo { |
| 40 | +"hello" |
| 41 | +} |
| 42 | +'@ |
| 43 | +
|
| 44 | +$settings = @{ |
| 45 | + IncludeRules = @("PSPlaceOpenBrace", "PSUseConsistentIndentation") |
| 46 | + Rules = @{ |
| 47 | + PSPlaceOpenBrace = @{ |
| 48 | + Enable = $true |
| 49 | + OnSameLine = $false |
| 50 | + } |
| 51 | + PSUseConsistentIndentation = @{ |
| 52 | + Enable = $true |
| 53 | + } |
| 54 | + } |
| 55 | +} |
| 56 | +
|
| 57 | +Invoke-Formatter -ScriptDefinition $scriptDefinition -Settings $settings |
| 58 | +``` |
| 59 | + |
| 60 | +This command formats the input script text using the settings defined in the `$settings` hashtable. |
| 61 | + |
| 62 | +### -------------------------- EXAMPLE 3 -------------------------- |
| 63 | +``` |
| 64 | +S> Invoke-Formatter -ScriptDefinition $scriptDefinition -Settings /path/to/settings.psd1 |
| 65 | +
|
| 66 | +This command formats the input script text using the settings defined in the `settings.psd1` file. |
| 67 | +
|
| 68 | +## PARAMETERS |
| 69 | +
|
| 70 | +### -ScriptDefinition |
| 71 | +The script text to be formated. |
| 72 | +
|
| 73 | +*NOTE*: Unlike ScriptBlock parameter, the ScriptDefinition parameter require a string value. |
| 74 | +
|
| 75 | +```yaml |
| 76 | +Type: String |
| 77 | +Parameter Sets: |
| 78 | +Aliases: |
| 79 | +
|
| 80 | +Required: True |
| 81 | +Position: Named |
| 82 | +Default value: |
| 83 | +Accept pipeline input: False |
| 84 | +Accept wildcard characters: False |
| 85 | +``` |
| 86 | + |
| 87 | +### -Settings |
| 88 | +A settings hashtable or a path to a PowerShell data file (.psd1) file that contains the settings. |
| 89 | + |
| 90 | +```yaml |
| 91 | +Type: Object |
| 92 | +Parameter Sets: |
| 93 | + |
| 94 | +Required: False |
| 95 | +Position: Named |
| 96 | +Default value: |
| 97 | +Accept pipeline input: False |
| 98 | +Accept wildcard characters: False |
| 99 | +``` |
0 commit comments