Skip to content

Commit 4a5b2d7

Browse files
committed
Update rule docs
1 parent 8db488d commit 4a5b2d7

File tree

94 files changed

+1714
-1499
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+1714
-1499
lines changed

README.md

+13-13
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ usage of Invoke-Expression etc. Additional functionalities such as exclude/inclu
5151
Usage
5252
======================
5353

54-
``` PowerShell
54+
```powershell
5555
Get-ScriptAnalyzerRule [-CustomRulePath <String[]>] [-RecurseCustomRulePath] [-Name <String[]>] [-Severity <String[]>] [<CommonParameters>]
5656
5757
Invoke-ScriptAnalyzer [-Path] <String> [-CustomRulePath <String[]>] [-RecurseCustomRulePath]
@@ -188,7 +188,7 @@ Pester-based ScriptAnalyzer Tests are located in `path/to/PSScriptAnalyzer/Tests
188188

189189
* Ensure [Pester 4.3.1](https://www.powershellgallery.com/packages/Pester/4.3.1) or higher is installed
190190
* In the root folder of your local repository, run:
191-
``` PowerShell
191+
```powershell
192192
./build -Test
193193
```
194194

@@ -251,7 +251,7 @@ Suppressing Rules
251251
You can suppress a rule by decorating a script/function or script/function parameter with .NET's [SuppressMessageAttribute](https://docs.microsoft.com/dotnet/api/system.diagnostics.codeanalysis.suppressmessageattribute).
252252
`SuppressMessageAttribute`'s constructor takes two parameters: a category and a check ID. Set the `categoryID` parameter to the name of the rule you want to suppress and set the `checkID` parameter to a null or empty string. You can optionally add a third named parameter with a justification for suppressing the message:
253253

254-
``` PowerShell
254+
```powershell
255255
function SuppressMe()
256256
{
257257
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSProvideCommentHelp', '', Justification='Just an example')]
@@ -265,7 +265,7 @@ function SuppressMe()
265265
All rule violations within the scope of the script/function/parameter you decorate will be suppressed.
266266

267267
To suppress a message on a specific parameter, set the `SuppressMessageAttribute`'s `CheckId` parameter to the name of the parameter:
268-
``` PowerShell
268+
```powershell
269269
function SuppressTwoVariables()
270270
{
271271
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSProvideDefaultParameterValue', 'b')]
@@ -280,7 +280,7 @@ Use the `SuppressMessageAttribute`'s `Scope` property to limit rule suppression
280280

281281
Use the value `Function` to suppress violations on all functions within the attribute's scope. Use the value `Class` to suppress violations on all classes within the attribute's scope:
282282

283-
``` PowerShell
283+
```powershell
284284
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSProvideCommentHelp', '', Scope='Function')]
285285
param(
286286
)
@@ -296,7 +296,7 @@ function InternalFunction
296296
You can further restrict suppression based on a function/parameter/class/variable/object's name by setting the `SuppressMessageAttribute's` `Target` property to a regular expression or a glob pattern. Few examples are given below.
297297

298298
Suppress `PSAvoidUsingWriteHost` rule violation in `start-bar` and `start-baz` but not in `start-foo` and `start-bam`:
299-
``` PowerShell
299+
```powershell
300300
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingWriteHost', '', Scope='Function', Target='start-ba[rz]')]
301301
param()
302302
function start-foo {
@@ -317,13 +317,13 @@ function start-bam {
317317
```
318318

319319
Suppress violations in all the functions:
320-
``` PowerShell
320+
```powershell
321321
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingWriteHost', '', Scope='Function', Target='*')]
322322
Param()
323323
```
324324

325325
Suppress violation in `start-bar`, `start-baz` and `start-bam` but not in `start-foo`:
326-
``` PowerShell
326+
```powershell
327327
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingWriteHost', '', Scope='Function', Target='start-b*')]
328328
Param()
329329
```
@@ -354,7 +354,7 @@ Along with `PSGallery` there are a few other built-in presets, including, `DSC`
354354
The following example excludes two rules from the default set of rules and any rule
355355
that does not output an Error or Warning diagnostic record.
356356

357-
``` PowerShell
357+
```powershell
358358
# PSScriptAnalyzerSettings.psd1
359359
@{
360360
Severity=@('Error','Warning')
@@ -365,13 +365,13 @@ that does not output an Error or Warning diagnostic record.
365365

366366
Then invoke that settings file when using `Invoke-ScriptAnalyzer`:
367367

368-
``` PowerShell
368+
```powershell
369369
Invoke-ScriptAnalyzer -Path MyScript.ps1 -Settings PSScriptAnalyzerSettings.psd1
370370
```
371371

372372
The next example selects a few rules to execute instead of all the default rules.
373373

374-
``` PowerShell
374+
```powershell
375375
# PSScriptAnalyzerSettings.psd1
376376
@{
377377
IncludeRules=@('PSAvoidUsingPlainTextForPassword',
@@ -380,15 +380,15 @@ The next example selects a few rules to execute instead of all the default rules
380380
```
381381

382382
Then invoke that settings file:
383-
``` PowerShell
383+
```powershell
384384
Invoke-ScriptAnalyzer -Path MyScript.ps1 -Settings PSScriptAnalyzerSettings.psd1
385385
```
386386

387387
### Implicit
388388

389389
If you place a PSScriptAnayzer settings file named `PSScriptAnalyzerSettings.psd1` in your project root, PSScriptAnalyzer will discover it if you pass the project root as the `Path` parameter.
390390

391-
```PowerShell
391+
```powershell
392392
Invoke-ScriptAnalyzer -Path "C:\path\to\project" -Recurse
393393
```
394394

RuleDocumentation/AvoidAssignmentToAutomaticVariable.md

-33
This file was deleted.

RuleDocumentation/AvoidGlobalAliases.md

-29
This file was deleted.

RuleDocumentation/AvoidGlobalVars.md

-41
This file was deleted.

RuleDocumentation/AvoidNullOrEmptyHelpMessageAttribute.md

-66
This file was deleted.

RuleDocumentation/AvoidOverwritingBuiltInCmdlets.md

-33
This file was deleted.

RuleDocumentation/AvoidTrailingWhitespace.md

-7
This file was deleted.

RuleDocumentation/AvoidUsingCmdletAliases.md

-49
This file was deleted.

RuleDocumentation/AvoidUsingDoubleQuotesForConstantString.md

-21
This file was deleted.

0 commit comments

Comments
 (0)