Skip to content

Commit

Permalink
Update format and grammar of AvoidUsingAllowUnencryptedAuthentication (
Browse files Browse the repository at this point in the history
…PowerShell#1974)

* Update format and grammar of AvoidUsingAllowUnencryptedAuthentication

* Syncing docs changes to all rules

* Update rules to match docs and improve wording
  • Loading branch information
sdwheeler authored Mar 13, 2024
1 parent b4365ad commit 03b655c
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 22 deletions.
13 changes: 8 additions & 5 deletions docs/Rules/AvoidExclaimOperator.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
description: Avoid exclaim operator
ms.custom: PSSA v1.22.0
ms.date: 06/14/2023
ms.date: 02/13/2024
ms.topic: reference
title: AvoidExclaimOperator
---
Expand All @@ -10,20 +10,23 @@ title: AvoidExclaimOperator

## Description

The negation operator `!` should not be used for readability purposes. Use `-not` instead.
Avoid using the negation operator (`!`). Use `-not` for improved readability.

**Note**: This rule is not enabled by default. The user needs to enable it through settings.
> [!NOTE]
> This rule is not enabled by default. The user needs to enable it through settings.
## How to Fix

## Example

### Wrong:
```PowerShell

```powershell
$MyVar = !$true
```

### Correct:
```PowerShell
```powershell
$MyVar = -not $true
```

Expand Down
13 changes: 7 additions & 6 deletions docs/Rules/AvoidUsingAllowUnencryptedAuthentication.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
description: Avoid sending credentials and secrets over unencrypted connections
ms.custom: PSSA v1.22.0
ms.date: 11/06/2022
ms.date: 02/28/2024
ms.topic: reference
title: AvoidUsingAllowUnencryptedAuthentication
---
Expand All @@ -11,14 +11,15 @@ title: AvoidUsingAllowUnencryptedAuthentication

## Description

Avoid using the `AllowUnencryptedAuthentication` switch on `Invoke-WebRequest`, `Invoke-RestMethod`, and other webrequest cmdlets, which sends credentials and secrets over unencrypted connections.
This should be avoided except for compatability with legacy systems.
Avoid using the **AllowUnencryptedAuthentication** parameter of `Invoke-WebRequest` and
`Invoke-RestMethod`. When using this parameter, the cmdlets send credentials and secrets over
unencrypted connections. This should be avoided except for compatibility with legacy systems.

For more details, see the documentation warning [here](https://learn.microsoft.com/powershell/module/microsoft.powershell.utility/invoke-webrequest#-allowunencryptedauthentication).
For more details, see [Invoke-RestMethod](xref:Microsoft.PowerShell.Utility.Invoke-RestMethod).

## How

Avoid using the `AllowUnencryptedAuthentication` switch.
Avoid using the **AllowUnencryptedAuthentication** parameter.

## Example 1

Expand All @@ -32,4 +33,4 @@ Invoke-WebRequest foo -AllowUnencryptedAuthentication

```powershell
Invoke-WebRequest foo
```
```
2 changes: 1 addition & 1 deletion docs/Rules/AvoidUsingPositionalParameters.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
description: Avoid Using Positional Parameters
ms.custom: PSSA v1.22.0
ms.date: 06/28/2023
ms.date: 02/13/2024
ms.topic: reference
title: AvoidUsingPositionalParameters
---
Expand Down
2 changes: 1 addition & 1 deletion docs/Rules/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
description: List of PSScriptAnalyzer rules
ms.custom: PSSA v1.22.0
ms.date: 06/28/2023
ms.date: 02/13/2024
ms.topic: reference
title: List of PSScriptAnalyzer rules
---
Expand Down
10 changes: 6 additions & 4 deletions docs/Rules/ReservedParams.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
description: Reserved Parameters
ms.custom: PSSA v1.22.0
ms.date: 06/28/2023
ms.date: 03/06/2024
ms.topic: reference
title: ReservedParams
---
Expand All @@ -11,9 +11,9 @@ title: ReservedParams

## Description

You cannot use [reserved common parameters][01] in an advanced function.

[01]: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_commonparameters
You can't redefine [common parameters][01] in an advanced function. Using the `CmdletBinding` or
`Parameter` attributes creates an advanced function. The common parameters are are automatically
available in advanced functions, so you can't redefine them.

## How

Expand Down Expand Up @@ -48,3 +48,5 @@ function Test
)
}
```

[01]: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_commonparameters
19 changes: 15 additions & 4 deletions docs/Rules/UseDeclaredVarsMoreThanAssignments.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
description: Extra Variables
ms.custom: PSSA v1.22.0
ms.date: 06/28/2023
ms.date: 03/06/2024
ms.topic: reference
title: UseDeclaredVarsMoreThanAssignments
---
Expand Down Expand Up @@ -44,10 +44,13 @@ function Test
}
```

### Special case
### Special cases

The following example triggers the **PSUseDeclaredVarsMoreThanAssignments** warning because `$bar`
is not used within the scriptblock where it was defined.
The following examples trigger the **PSUseDeclaredVarsMoreThanAssignments** warning. This behavior
is a limitation of the rule. There is no way to avoid these false positive warnings.

In this case, the warning is triggered because `$bar` is not used within the scriptblock where it
was defined.

```powershell
$foo | ForEach-Object {
Expand All @@ -60,3 +63,11 @@ if($bar){
Write-Host 'Collection contained a false case.'
}
```

In the next example, the warning is triggered because `$errResult` isn't recognized as being used in
the `Write-Host` command.

```powershell
$errResult = $null
Write-Host 'Ugh:' -ErrorVariable errResult
```
2 changes: 1 addition & 1 deletion docs/Rules/UseSingularNouns.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
description: Cmdlet Singular Noun
ms.custom: PSSA v1.22.0
ms.date: 06/28/2023
ms.date: 02/13/2024
ms.topic: reference
title: UseSingularNouns
---
Expand Down

0 comments on commit 03b655c

Please sign in to comment.