Skip to content

Commit 0e7cca6

Browse files
bergmeisterJamesWTruher
authored andcommitted
Improve documentation, especially about parameter usage and the settings file (#968)
* improve documentation * Remove extraneous space character * Address remaining PR comments about improvements of the wording
1 parent 6966d51 commit 0e7cca6

File tree

2 files changed

+41
-43
lines changed

2 files changed

+41
-43
lines changed

docs/markdown/Invoke-Formatter.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Invoke-Formatter [-ScriptDefinition] <String> [-Settings <object>] [-Range <int[
1515

1616
## DESCRIPTION
1717

18-
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`.
18+
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.psd1.
1919

2020
## EXAMPLES
2121

@@ -56,14 +56,14 @@ $settings = @{
5656
Invoke-Formatter -ScriptDefinition $scriptDefinition -Settings $settings
5757
```
5858

59-
This command formats the input script text using the settings defined in the `$settings` hashtable.
59+
This command formats the input script text using the settings defined in the $settings hashtable.
6060

6161
### -------------------------- EXAMPLE 3 --------------------------
6262
```
6363
Invoke-Formatter -ScriptDefinition $scriptDefinition -Settings /path/to/settings.psd1
6464
```
6565

66-
This command formats the input script text using the settings defined in the `settings.psd1` file.
66+
This command formats the input script text using the settings defined in the settings.psd1 file.
6767

6868
## PARAMETERS
6969

docs/markdown/Invoke-ScriptAnalyzer.md

+38-40
Original file line numberDiff line numberDiff line change
@@ -24,34 +24,22 @@ Invoke-ScriptAnalyzer [-ScriptDefinition] <String> [-CustomRulePath <String>] [-
2424
```
2525

2626
## DESCRIPTION
27-
Invoke-ScriptAnalyzer evaluates a script or module based on a collection of best practice rules and returns objects
28-
that represent rule violations.
29-
In each evaluation, you can run all rules or use the IncludeRule and ExcludeRule
30-
parameters to run only selected rules.
31-
Invoke-ScriptAnalyzer includes special rules to analyze DSC resources.
32-
33-
Invoke-ScriptAnalyzer evaluates only .ps1 and .psm1 files.
34-
If you specify a path with multiple file types, the .ps1 and
35-
.psm1 files are tested; all other file types are ignored.
27+
Invoke-ScriptAnalyzer evaluates a script or module files (.ps1, .psm1 and .psd1 files) based on a collection of best practice rules and returns objects
28+
that represent rule violations. It also includes special rules to analyze DSC resources.
3629

30+
In each evaluation, you can run either all rules or just a specific set using the -IncludeRule parameter and also exclude rules using the -ExcludeRule parameter.
3731
Invoke-ScriptAnalyzer comes with a set of built-in rules, but you can also use customized rules that you write in
38-
Windows PowerShell scripts, or compile in assemblies by using C#.
39-
Just as with the built-in rules, you can add the
40-
ExcludeRule and IncludeRule parameters to your Invoke-ScriptAnalyzer command to exclude or include custom rules.
32+
Windows PowerShell scripts, or compile in assemblies by using C#. This is possible by using the -CustomRulePath parameter and it will then only run those custom rules, if the built-in rules should still be run, then also specify the -IncludeDefaultRules parameter. Custom rules are also supported together with the -IncludeRule and -ExcludeRule parameters. To include multiple custom rules, the -RecurseCustomRulePath parameter can be used.
4133

4234
To analyze your script or module, begin by using the Get-ScriptAnalyzerRule cmdlet to examine and select the rules you
4335
want to include and/or exclude from the evaluation.
4436

4537
You can also include a rule in the analysis, but suppress the output of that rule for selected functions or scripts.
4638
This feature should be used only when absolutely necessary.
47-
To get rules that were suppressed, run
48-
Invoke-ScriptAnalyzer with the SuppressedOnly parameter.
49-
For instructions on suppressing a rule, see the description of
50-
the SuppressedOnly parameter.
51-
For usage in CI systems, the -EnableExit exits the shell with an exit code equal to the number of error records.
39+
To get rules that were suppressed, run Invoke-ScriptAnalyzer with the -SuppressedOnly parameter.
40+
For instructions on suppressing a rule, see the description of the SuppressedOnly parameter.
5241

53-
The PSScriptAnalyzer module tests the Windows PowerShell code in a script, module, or DSC resource to determine
54-
whether, and to what extent, it fulfils best practice standards.
42+
For usage in CI systems, the -EnableExit exits the shell with an exit code equal to the number of error records.
5543

5644
PSScriptAnalyzer is an open-source project.
5745
For more information about PSScriptAnalyzer, to contribute or file an issue, see GitHub.com\PowerShell\PSScriptAnalyzer.
@@ -219,7 +207,7 @@ Accept wildcard characters: False
219207
```
220208
221209
### -CustomRulePath
222-
Adds the custom rules defined in the specified paths to the analysis.
210+
Uses only the custom rules defined in the specified paths to the analysis. To still use the built-in rules, add the -IncludeDefaultRules switch.
223211
224212
Enter the path to a file that defines rules or a directory that contains files that define rules.
225213
Wildcard characters are supported.
@@ -243,7 +231,8 @@ Accept wildcard characters: False
243231
244232
### -RecurseCustomRulePath
245233
Adds rules defined in subdirectories of the CustomRulePath location.
246-
By default, Invoke-ScriptAnalyzer adds only the custom rules defined in the specified file or directory.
234+
By default, Invoke-ScriptAnalyzer uses only the custom rules defined in the specified file or directory.
235+
To still use the built-in rules, additionally use the -IncludeDefaultRules switch.
247236
248237
```yaml
249238
Type: SwitchParameter
@@ -262,16 +251,12 @@ Omits the specified rules from the Script Analyzer test.
262251
Wildcard characters are supported.
263252
264253
Enter a comma-separated list of rule names, a variable that contains rule names, or a command that gets rule names.
265-
You
266-
can also specify a list of excluded rules in a Script Analyzer profile file.
267-
You can exclude standard rules and rules
268-
in a custom rule path.
254+
You can also specify a list of excluded rules in a Script Analyzer profile file.
255+
You can exclude standard rules and rules in a custom rule path.
269256
270257
When you exclude a rule, the rule does not run on any of the files in the path.
271-
To exclude a rule on a particular line,
272-
parameter, function, script, or class, adjust the Path parameter or suppress the rule.
273-
For information about
274-
suppressing a rule, see the examples.
258+
To exclude a rule on a particular line, parameter, function, script, or class, adjust the Path parameter or suppress the rule.
259+
For information about suppressing a rule, see the examples.
275260
276261
If a rule is specified in both the ExcludeRule and IncludeRule collections, the rule is excluded.
277262
@@ -302,7 +287,6 @@ Accept pipeline input: False
302287
Accept wildcard characters: False
303288
```
304289
305-
306290
### -IncludeRule
307291
Runs only the specified rules in the Script Analyzer test.
308292
By default, PSScriptAnalyzer runs all rules.
@@ -317,8 +301,7 @@ custom rule paths.
317301
If a rule is specified in both the ExcludeRule and IncludeRule collections, the rule is excluded.
318302
319303
Also, Severity takes precedence over IncludeRule.
320-
For example, if Severity is Error, you cannot use IncludeRule to
321-
include a Warning rule.
304+
For example, if Severity is Error, you cannot use IncludeRule to include a Warning rule.
322305
323306
```yaml
324307
Type: String[]
@@ -339,13 +322,11 @@ Valid values are: Error, Warning, and Information.
339322
You can specify one ore more severity values.
340323
341324
Because this parameter filters the rules only after running with all rules, it is not an efficient filter.
342-
To filter
343-
rules efficiently, use Get-ScriptAnalyzer rule to get the rules you want to run or exclude and then use the ExcludeRule
344-
or IncludeRule parameters.
325+
To filter rules efficiently, use Get-ScriptAnalyzer rule to get the rules you want to run or exclude and
326+
then use the ExcludeRule or IncludeRule parameters.
345327
346328
Also, Severity takes precedence over IncludeRule.
347-
For example, if Severity is Error, you cannot use IncludeRule to
348-
include a Warning rule.
329+
For example, if Severity is Error, you cannot use IncludeRule to include a Warning rule.
349330
350331
```yaml
351332
Type: String[]
@@ -401,7 +382,9 @@ Accept wildcard characters: False
401382
### -Fix
402383
Fixes certain warnings which contain a fix in their DiagnosticRecord.
403384
404-
When you used Fix, Invoke-ScriptAnalyzer runs as usual but will apply the fixes before running the analysis. Please make sure that you have a backup of your files when using this switch. It tries to preserve the file encoding but there are still some cases where the encoding can change.
385+
When you used Fix, Invoke-ScriptAnalyzer runs as usual but will apply the fixes before running the analysis.
386+
Please make sure that you have a backup of your files when using this switch.
387+
It tries to preserve the file encoding but there are still some cases where the encoding can change.
405388
406389
```yaml
407390
Type: SwitchParameter
@@ -450,12 +433,16 @@ File path that contains user profile or hash table for ScriptAnalyzer
450433
451434
Runs Invoke-ScriptAnalyzer with the parameters and values specified in a Script Analyzer profile file or hash table
452435
453-
If the path, the file's or hashtable's content are invalid, it is ignored. The parameters and values in the profile take precedence over the same parameter and values specified at the command line.
436+
If the path, the file's or hashtable's content are invalid, it is ignored.
437+
The parameters and values in the profile take precedence over the same parameter and values specified at the command line.
454438
455439
A Script Analyzer profile file is a text file that contains a hash table with one or more of the following keys:
456440
-- Severity
457441
-- IncludeRules
458442
-- ExcludeRules
443+
-- Rules
444+
-- CustomRulePath
445+
-- IncludeDefaultRules
459446
460447
The keys and values in the profile are interpreted as if they were standard parameters and parameter values of Invoke-ScriptAnalyzer.
461448
@@ -469,6 +456,17 @@ For example:
469456
470457
@{ Severity = 'Error', 'Warning'}
471458
459+
A more sophisticated example is:
460+
461+
@{
462+
CustomRulePath='path\to\CustomRuleModule.psm1'
463+
IncludeDefaultRules=$true
464+
ExcludeRules = @(
465+
'PSAvoidUsingWriteHost',
466+
'MyCustomRuleName'
467+
)
468+
}
469+
472470
```yaml
473471
Type: Object
474472
Parameter Sets: (All)
@@ -502,7 +500,7 @@ Accept wildcard characters: False
502500
### -SaveDscDependency
503501
Resolve DSC resource dependency
504502
505-
Whenever Invoke-ScriptAnalyzer (isa) is run on a script having the dynamic keyword "Import-DSCResource -ModuleName <somemodule>", if <somemodule> is not present in any of the PSModulePath, isa gives parse error. This error is caused by the powershell parser not being able to find the symbol for <somemodule>. If isa finds the module on PowerShell Gallery (www.powershellgallery.com) then it downloads the missing module to a temp path. The temp path is then added to PSModulePath only for duration of the scan. The temp location can be found in $LOCALAPPDATA/PSScriptAnalyzer/TempModuleDir.
503+
Whenever Invoke-ScriptAnalyzer is run on a script having the dynamic keyword "Import-DSCResource -ModuleName <somemodule>", if <somemodule> is not present in any of the PSModulePath, Invoke-ScriptAnalyzer gives parse error. This error is caused by the powershell parser not being able to find the symbol for <somemodule>. If Invoke-ScriptAnalyzer finds the module in the PowerShell Gallery (www.powershellgallery.com) then it downloads the missing module to a temp path. The temp path is then added to PSModulePath only for duration of the scan. The temp location can be found in $LOCALAPPDATA/PSScriptAnalyzer/TempModuleDir.
506504
507505
```yaml
508506
Type: SwitchParameter

0 commit comments

Comments
 (0)