Skip to content

Commit a22fd0f

Browse files
rkeithhillbergmeister
authored andcommitted
Fix table to refer to existing md files, add col for Configurable (#988)
* Fix table to refer to existing md files, add col for Configurable * Remove deprecated rules, rename to match actual rule sans PS prefix * Add Pester tests for rule doc files, add back UseSingularNouns.md file * Add Pester tests for verifying rule doc README.md file * fix typo in documentation folder, remove redundant ipmo call new tests in CI and add to docs * Add rules that will be present in 1.17 and fix typo in md file name * remove redundant import of PSScriptAnalyzerTestHelper test helper module in documentation test * Fix doc tests for PS v4 and PS Core This commit removes rules that aren't available on these versions * Remove leftovers from deprecated rules AvoidUsingFilePath, AvoidUninitializedVariable and AvoidTrapStatement in code and documentation. Fix markdown in PowerShellBestPractices.md and tidy up * added remarks about rules not being available in certain powershell versions * Add superscript/footnote on rules not available everywhere * Update test to strip off the optional superscript markdown
1 parent e5ae9df commit a22fd0f

26 files changed

+330
-506
lines changed

Engine/Settings/PSGallery.psd1

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
'PSAvoidUsingConvertToSecureStringWithPlainText',
2222
'PSUsePSCredentialType',
2323
'PSAvoidUsingUserNameAndPasswordParams',
24-
'PSAvoidUsingFilePath',
2524
'PSDSC*'
2625
)
2726
}

Engine/Settings/ScriptSecurity.psd1

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@
33
'PSAvoidUsingComputerNameHardcoded',
44
'PSAvoidUsingConvertToSecureStringWithPlainText',
55
'PSUsePSCredentialType',
6-
'PSAvoidUsingUserNameAndPasswordParams',
7-
'PSAvoidUsingFilePath')
6+
'PSAvoidUsingUserNameAndPasswordParams')
87
}

PowerShellBestPractices.md

+140-125
Large diffs are not rendered by default.

README.md

+3-9
Original file line numberDiff line numberDiff line change
@@ -158,16 +158,10 @@ Pester-based ScriptAnalyzer Tests are located in `path/to/PSScriptAnalyzer/Tests
158158

159159
* Ensure [Pester 4.3.1](https://www.powershellgallery.com/packages/Pester/4.3.1) is installed
160160
* Copy `path/to/PSScriptAnalyzer/out/PSScriptAnalyzer` to a folder in `PSModulePath`
161-
* Go the Tests folder in your local repository
162-
* Run Engine Tests:
161+
* In the root folder of your local repository, run:
163162
``` PowerShell
164-
cd /path/to/PSScriptAnalyzer/Tests/Engine
165-
Invoke-Pester
166-
```
167-
* Run Tests for Built-in rules:
168-
``` PowerShell
169-
cd /path/to/PSScriptAnalyzer/Tests/Rules
170-
Invoke-Pester
163+
$testScripts = ".\Tests\Engine",".\Tests\Rules",".\Tests\Documentation"
164+
Invoke-Pester -Script $testScripts
171165
```
172166

173167
[Back to ToC](#table-of-contents)

RuleDocumentation/AvoidGlobalAliases.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44

55
## Description
66

7-
Globally scoped aliases override existing aliases within the sessions with matching names. This name collision can cause difficult to debug issues for consumers of modules and scripts.
8-
7+
Globally scoped aliases override existing aliases within the sessions with matching names. This name collision can cause difficult to debug issues for consumers of modules and scripts.
98

109
To understand more about scoping, see ```Get-Help about_Scopes```.
1110

11+
**NOTE** This rule is not available in PowerShell version 3 and 4 due to the `StaticParameterBinder.BindCommand` API that the rule uses internally.
12+
1213
## How
1314

1415
Use other scope modifiers for new aliases.

RuleDocumentation/AvoidTrapStatement.md

-48
This file was deleted.

RuleDocumentation/AvoidUninitializedVariable.md

-34
This file was deleted.

RuleDocumentation/AvoidUsingFilePath.md

-47
This file was deleted.

RuleDocumentation/README.md

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# PSScriptAnalyzer Rules
2+
3+
## Table of Contents
4+
5+
| Rule | Severity | Configurable |
6+
|------|----------------------------------|--------------|
7+
|[AlignAssignmentStatement](./AlignAssignmentStatement.md) | Warning | |
8+
|[AvoidAssignmentToAutomaticVariable](./AvoidAssignmentToAutomaticVariable.md) | Warning | |
9+
|[AvoidDefaultValueForMandatoryParameter](./AvoidDefaultValueForMandatoryParameter.md) | Warning | |
10+
|[AvoidDefaultValueSwitchParameter](./AvoidDefaultValueSwitchParameter.md) | Warning | |
11+
|[AvoidGlobalAliases<sup>*</sup>](./AvoidGlobalAliases.md) | Warning | |
12+
|[AvoidGlobalFunctions](./AvoidGlobalFunctions.md) | Warning | |
13+
|[AvoidGlobalVars](./AvoidGlobalVars.md) | Warning | |
14+
|[AvoidInvokingEmptyMembers](./AvoidInvokingEmptyMembers.md) | Warning | |
15+
|[AvoidNullOrEmptyHelpMessageAttribute](./AvoidNullOrEmptyHelpMessageAttribute.md) | Warning | |
16+
|[AvoidShouldContinueWithoutForce](./AvoidShouldContinueWithoutForce.md) | Warning | |
17+
|[AvoidUsingCmdletAliases](./AvoidUsingCmdletAliases.md) | Warning | Yes |
18+
|[AvoidUsingComputerNameHardcoded](./AvoidUsingComputerNameHardcoded.md) | Error | |
19+
|[AvoidUsingConvertToSecureStringWithPlainText](./AvoidUsingConvertToSecureStringWithPlainText.md) | Error | |
20+
|[AvoidUsingDeprecatedManifestFields](./AvoidUsingDeprecatedManifestFields.md) | Warning | |
21+
|[AvoidUsingEmptyCatchBlock](./AvoidUsingEmptyCatchBlock.md) | Warning | |
22+
|[AvoidUsingInvokeExpression](./AvoidUsingInvokeExpression.md) | Warning | |
23+
|[AvoidUsingPlainTextForPassword](./AvoidUsingPlainTextForPassword.md) | Warning | |
24+
|[AvoidUsingPositionalParameters](./AvoidUsingPositionalParameters.md) | Warning | |
25+
|[AvoidTrailingWhitespace](./AvoidTrailingWhitespace.md) | Warning | |
26+
|[AvoidUsingUsernameAndPasswordParams](./AvoidUsingUsernameAndPasswordParams.md) | Error | |
27+
|[AvoidUsingWMICmdlet](./AvoidUsingWMICmdlet.md) | Warning | |
28+
|[AvoidUsingWriteHost](./AvoidUsingWriteHost.md) | Warning | |
29+
|[DSCDscExamplesPresent](./DSCDscExamplesPresent.md) | Information | |
30+
|[DSCDscTestsPresent](./DSCDscTestsPresent.md) | Information | |
31+
|[DSCReturnCorrectTypesForDSCFunctions](./DSCReturnCorrectTypesForDSCFunctions.md) | Information | |
32+
|[DSCStandardDSCFunctionsInResource](./DSCStandardDSCFunctionsInResource.md) | Error | |
33+
|[DSCUseIdenticalMandatoryParametersForDSC](./DSCUseIdenticalMandatoryParametersForDSC.md) | Error | |
34+
|[DSCUseIdenticalParametersForDSC](./DSCUseIdenticalParametersForDSC.md) | Error | |
35+
|[DSCUseVerboseMessageInDSCResource](./DSCUseVerboseMessageInDSCResource.md) | Error | |
36+
|[MisleadingBacktick](./MisleadingBacktick.md) | Warning | |
37+
|[MissingModuleManifestField](./MissingModuleManifestField.md) | Warning | |
38+
|[PossibleIncorrectComparisonWithNull](./PossibleIncorrectComparisonWithNull.md) | Warning | |
39+
|[PossibleIncorrectUsageOfAssignmentOperator](./PossibleIncorrectUsageOfAssignmentOperator.md) | Warning | |
40+
|[PossibleIncorrectUsageOfRedirectionOperator](./PossibleIncorrectUsageOfRedirectionOperator.md) | Warning | |
41+
|[ProvideCommentHelp](./ProvideCommentHelp.md) | Information | Yes |
42+
|[ReservedCmdletChar](./ReservedCmdletChar.md) | Error | |
43+
|[ReservedParams](./ReservedParams.md) | Error | |
44+
|[ShouldProcess](./ShouldProcess.md) | Error | |
45+
|[UseApprovedVerbs](./UseApprovedVerbs.md) | Warning | |
46+
|[UseBOMForUnicodeEncodedFile](./UseBOMForUnicodeEncodedFile.md) | Warning | |
47+
|[UseCmdletCorrectly](./UseCmdletCorrectly.md) | Warning | |
48+
|[UseDeclaredVarsMoreThanAssignments](./UseDeclaredVarsMoreThanAssignments.md) | Warning | |
49+
|[UseLiteralInitializerForHashtable](./UseLiteralInitializerForHashtable.md) | Warning | |
50+
|[UseOutputTypeCorrectly](./UseOutputTypeCorrectly.md) | Information | |
51+
|[UsePSCredentialType](./UsePSCredentialType.md) | Warning | |
52+
|[UseShouldProcessForStateChangingFunctions](./UseShouldProcessForStateChangingFunctions.md) | Warning | |
53+
|[UseSingularNouns<sup>*</sup>](./UseSingularNouns.md) | Warning | |
54+
|[UseSupportsShouldProcess](./UseSupportsShouldProcess.md) | Warning | |
55+
|[UseToExportFieldsInManifest](./UseToExportFieldsInManifest.md) | Warning | |
56+
|[UseCompatibleCmdlets](./UseCompatibleCmdlets.md) | Warning | Yes |
57+
|[PlaceOpenBrace](./PlaceOpenBrace.md) | Warning | Yes |
58+
|[PlaceCloseBrace](./PlaceCloseBrace.md) | Warning | Yes |
59+
|[UseConsistentIndentation](./UseConsistentIndentation.md) | Warning | Yes |
60+
|[UseConsistentWhitespace](./UseConsistentWhitespace.md) | Warning | Yes |
61+
|[UseUTF8EncodingForHelpFile](./UseUTF8EncodingForHelpFile.md) | Warning | |
62+
63+
<sup>*</sup> Rule is not available on all PowerShell versions, editions and/or OS platforms. See the rule's documentation for details.

RuleDocumentation/UseSingularNouns.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
PowerShell team best practices state cmdlets should use singular nouns and not plurals.
88

9+
**NOTE** This rule is not available in PowerShell Core due to the PluralizationService API that the rule uses internally.
10+
911
## How
1012

1113
Change plurals to singular.
@@ -17,7 +19,7 @@ Change plurals to singular.
1719
``` PowerShell
1820
function Get-Files
1921
{
20-
...
22+
...
2123
}
2224
```
2325

@@ -26,6 +28,6 @@ function Get-Files
2628
``` PowerShell
2729
function Get-File
2830
{
29-
...
31+
...
3032
}
3133
```

Rules/Strings.Designer.cs

+2-110
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)