Skip to content

Commit 13b2427

Browse files
Fix PSScriptAnalyzer linting issues
Co-authored-by: MariusStorhaug <17722253+MariusStorhaug@users.noreply.github.com>
1 parent 4b30595 commit 13b2427

6 files changed

Lines changed: 33 additions & 10 deletions

File tree

src/functions/private/Auth/Context/Remove-PowerShellGalleryContext.ps1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ function Remove-PowerShellGalleryContext {
3333
if ($script:PowerShellGallery.Config.DefaultContext -eq $ID) {
3434
Write-Verbose 'Clearing default context'
3535
$script:PowerShellGallery.Config.DefaultContext = $null
36-
$null = Set-Context -ID $script:PowerShellGallery.DefaultConfig.ID -Context $script:PowerShellGallery.Config -Vault $script:PowerShellGallery.ContextVault
36+
$configID = $script:PowerShellGallery.DefaultConfig.ID
37+
$vault = $script:PowerShellGallery.ContextVault
38+
$null = Set-Context -ID $configID -Context $script:PowerShellGallery.Config -Vault $vault
3739
}
3840
}
3941
}

src/functions/private/Auth/Context/Set-PowerShellGalleryContext.ps1

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,14 @@ function Set-PowerShellGalleryContext {
5050
$contextObj['ID'] = $ID
5151

5252
if ($PSCmdlet.ShouldProcess("Context [$ID]", 'Set')) {
53-
$result = Set-Context -ID $ID -Context $contextObj -Vault $script:PowerShellGallery.ContextVault -PassThru
53+
$vault = $script:PowerShellGallery.ContextVault
54+
$result = Set-Context -ID $ID -Context $contextObj -Vault $vault -PassThru
5455

5556
if ($Default) {
5657
Write-Debug "Setting [$ID] as default context"
5758
$script:PowerShellGallery.Config.DefaultContext = $ID
58-
$null = Set-Context -ID $script:PowerShellGallery.DefaultConfig.ID -Context $script:PowerShellGallery.Config -Vault $script:PowerShellGallery.ContextVault
59+
$configID = $script:PowerShellGallery.DefaultConfig.ID
60+
$null = Set-Context -ID $configID -Context $script:PowerShellGallery.Config -Vault $vault
5961
}
6062

6163
if ($PassThru) {

src/functions/public/Auth/Connect-PowerShellGallery.ps1

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ function Connect-PowerShellGallery {
2727
'PSAvoidUsingConvertToSecureStringWithPlainText', '',
2828
Justification = 'The API key is received as clear text from user input.'
2929
)]
30+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
31+
'PSAvoidUsingWriteHost', '',
32+
Justification = 'Is the CLI part of the module. Consistent with GitHub module pattern.'
33+
)]
3034
[CmdletBinding(DefaultParameterSetName = 'Interactive')]
3135
[OutputType([System.Object])]
3236
param(
@@ -59,9 +63,9 @@ function Connect-PowerShellGallery {
5963
if (-not $Silent) {
6064
Write-Host '🌐 Opening PowerShell Gallery API key management page...' -ForegroundColor Cyan
6165
}
62-
66+
6367
$apiKeyUrl = 'https://www.powershellgallery.com/account/apikeys'
64-
68+
6569
# Try to open browser
6670
try {
6771
if ($IsWindows -or $PSVersionTable.PSVersion.Major -le 5) {

src/functions/public/Auth/Context/Switch-PowerShellGalleryContext.ps1

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ function Switch-PowerShellGalleryContext {
1111
1212
Switches the default PowerShell Gallery context to 'MyAccount'.
1313
#>
14+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
15+
'PSAvoidUsingWriteHost', '',
16+
Justification = 'Is the CLI part of the module. Consistent with GitHub module pattern.'
17+
)]
1418
[OutputType([void])]
1519
[CmdletBinding(SupportsShouldProcess)]
1620
param(
@@ -28,14 +32,17 @@ function Switch-PowerShellGalleryContext {
2832
# Verify the context exists
2933
$context = Get-Context -ID $ID -Vault $script:PowerShellGallery.ContextVault
3034
if (-not $context) {
31-
Write-Error "Context [$ID] not found. Use 'Get-PowerShellGalleryContext -ListAvailable' to see available contexts."
35+
$msg = "Context [$ID] not found. Use 'Get-PowerShellGalleryContext -ListAvailable' to see available contexts."
36+
Write-Error $msg
3237
return
3338
}
3439

3540
if ($PSCmdlet.ShouldProcess("Default context to [$ID]", 'Switch')) {
3641
Write-Verbose "Switching default context to [$ID]"
3742
$script:PowerShellGallery.Config.DefaultContext = $ID
38-
$null = Set-Context -ID $script:PowerShellGallery.DefaultConfig.ID -Context $script:PowerShellGallery.Config -Vault $script:PowerShellGallery.ContextVault
43+
$configID = $script:PowerShellGallery.DefaultConfig.ID
44+
$vault = $script:PowerShellGallery.ContextVault
45+
$null = Set-Context -ID $configID -Context $script:PowerShellGallery.Config -Vault $vault
3946
Write-Host "✓ Switched to context [$ID]" -ForegroundColor Green
4047
}
4148
}

src/functions/public/Auth/Disconnect-PowerShellGallery.ps1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ function Disconnect-PowerShellGallery {
1717
Removes the default context.
1818
#>
1919
[CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'High')]
20+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
21+
'PSAvoidUsingWriteHost', '',
22+
Justification = 'Is the CLI part of the module. Consistent with GitHub module pattern.'
23+
)]
2024
[OutputType([void])]
2125
param(
2226
# The name of the context to remove. If not specified, removes the default context.

src/functions/public/Auth/Test-PowerShellGalleryAccess.ps1

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ function Test-PowerShellGalleryAccess {
1717
1818
Tests access using the 'MyAccount' context.
1919
#>
20+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
21+
'PSAvoidUsingWriteHost', '',
22+
Justification = 'Is the CLI part of the module. Consistent with GitHub module pattern.'
23+
)]
2024
[CmdletBinding()]
2125
[OutputType([System.Object])]
2226
param(
@@ -57,15 +61,15 @@ function Test-PowerShellGalleryAccess {
5761
# The API key validation can be done by attempting to access the API
5862
try {
5963
Write-Verbose 'Testing API connectivity...'
60-
64+
6165
# Try to access the API root to validate connectivity
6266
$apiUrl = $contextObj.ApiUrl
6367
$headers = @{
6468
'X-NuGet-ApiKey' = $apiKey
6569
}
6670

67-
# Test basic API access
68-
$response = Invoke-RestMethod -Uri $apiUrl -Method Get -Headers $headers -ErrorAction Stop
71+
# Test basic API access - just verify we can connect
72+
$null = Invoke-RestMethod -Uri $apiUrl -Method Get -Headers $headers -ErrorAction Stop
6973

7074
$result = [PSCustomObject]@{
7175
Success = $true

0 commit comments

Comments
 (0)