Skip to content

Commit 3d3f81c

Browse files
committed
Fix PSScriptAnalyzer issues
1 parent 603646d commit 3d3f81c

15 files changed

Lines changed: 157 additions & 72 deletions

Terminal-Icons/Private/Get-ThemeStoragePath.ps1

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
function Get-ThemeStoragePath {
2+
[OutputType([string])]
23
[CmdletBinding()]
34
param()
45

56
if ($IsLinux -or $IsMacOs) {
6-
if (-not ($path = @($env:XDG_CONFIG_DIRS -split ([IO.Path]::PathSeparator))[0])) {
7+
$path = @($env:XDG_CONFIG_DIRS -split ([IO.Path]::PathSeparator))[0]
8+
if (-not $path) {
79
$path = [IO.Path]::Combine($HOME, '.local', 'share')
810
}
911
} else {
10-
if (-not ($path = $env:APPDATA)) {
12+
$path = $env:APPDATA
13+
if (-not $path) {
1114
$path = [Environment]::GetFolderPath('ApplicationData')
1215
}
1316
}

Terminal-Icons/Private/Import-ColorTheme.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
function Import-ColorTheme {
2+
[OutputType([hashtable])]
23
[cmdletbinding()]
34
param()
45

Terminal-Icons/Private/Import-IconTheme.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
function Import-IconTheme {
2+
[OutputType([hashtable])]
23
[cmdletbinding()]
34
param()
45

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
function Import-Preferences {
2+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '')]
3+
[OutputType([hashtable])]
24
[cmdletbinding()]
35
param(
46
[parameter(ValueFromPipeline)]
@@ -7,12 +9,14 @@ function Import-Preferences {
79
[string]$DefaultThemeName = $script:defaultTheme
810
)
911

10-
if (Test-Path $Path) {
11-
Import-Clixml -Path $Path
12-
} else {
13-
@{
14-
CurrentColorTheme = $DefaultThemeName
15-
CurrentIconTheme = $DefaultThemeName
12+
process {
13+
if (Test-Path $Path) {
14+
Import-Clixml -Path $Path
15+
} else {
16+
@{
17+
CurrentColorTheme = $DefaultThemeName
18+
CurrentIconTheme = $DefaultThemeName
19+
}
1620
}
1721
}
1822
}

Terminal-Icons/Private/New-EmptyColorTheme.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
function New-EmptyColorTheme {
2+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '')]
23
[OutputType([hashtable])]
34
[cmdletbinding()]
45
param()

Terminal-Icons/Private/Save-Preferences.ps1

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ function Save-Preferences {
77
[string]$Path = (Join-Path (Get-ThemeStoragePath) 'prefs.xml')
88
)
99

10-
Write-Debug ('Saving preferendces to [{0}]' -f $Path)
11-
$Preferences | Export-CliXml -Path $Path -Force
10+
process {
11+
Write-Debug ('Saving preferendces to [{0}]' -f $Path)
12+
$Preferences | Export-CliXml -Path $Path -Force
13+
}
1214
}

Terminal-Icons/Public/Format-TerminalIcons.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ function Format-TerminalIcons {
2424
2525
Outputs a colorized string with an icon prepended.
2626
#>
27+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '')]
2728
[OutputType([string])]
2829
[CmdletBinding()]
2930
param(

Terminal-Icons/Public/Remove-TerminalIconsTheme.ps1

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ function Remove-TerminalIconsTheme {
88
The icon theme to remove.
99
.PARAMETER ColorTheme
1010
The color theme to remove.
11+
.PARAMETER Force
12+
Bypass confirmation messages.
1113
.EXAMPLE
1214
PS> Remove-TerminalIconsTheme -IconTheme MyAwesomeTheme
1315
@@ -33,19 +35,19 @@ function Remove-TerminalIconsTheme {
3335
.NOTES
3436
A theme must not be active in order to be removed.
3537
#>
36-
[cmdletbinding()]
38+
[cmdletbinding(SupportsShouldProcess)]
3739
param(
3840
[ArgumentCompleter({
39-
param($Command, $Parameter, $WordToComplete, $CommandAst, $FakeBoundParams)
4041
(Get-TerminalIconsIconTheme).Keys | Sort-Object
4142
})]
4243
[string]$IconTheme,
4344

4445
[ArgumentCompleter({
45-
param($Command, $Parameter, $WordToComplete, $CommandAst, $FakeBoundParams)
4646
(Get-TerminalIconsColorTheme).Keys | Sort-Object
4747
})]
48-
[string]$ColorTheme
48+
[string]$ColorTheme,
49+
50+
[switch]$Force
4951
)
5052

5153
$currentTheme = Get-TerminalIconsTheme
@@ -57,13 +59,15 @@ function Remove-TerminalIconsTheme {
5759
if (-not (Test-Path $themePath)) {
5860
Write-Error "Could not find theme file [$themePath]"
5961
} else {
60-
if ($userThemeData.Themes.Color.ContainsKey($ColorTheme)) {
61-
$userThemeData.Themes.Color.Remove($ColorTheme)
62-
} else {
63-
# We shouldn't be here
64-
Write-Error "Color theme [$ColorTheme] is not registered."
62+
if ($Force -or $PSCmdlet.ShouldProcess($ColorTheme, 'Remove color theme')) {
63+
if ($userThemeData.Themes.Color.ContainsKey($ColorTheme)) {
64+
$userThemeData.Themes.Color.Remove($ColorTheme)
65+
} else {
66+
# We shouldn't be here
67+
Write-Error "Color theme [$ColorTheme] is not registered."
68+
}
69+
Remove-Item $themePath -Force
6570
}
66-
Remove-Item $themePath -Force
6771
}
6872
} else {
6973
Write-Error ("Color theme [{0}] is active. Please select another theme before removing this it." -f $ColorTheme)
@@ -76,13 +80,15 @@ function Remove-TerminalIconsTheme {
7680
if (-not (Test-Path $themePath)) {
7781
Write-Error "Could not find theme file [$themePath]"
7882
} else {
79-
if ($userThemeData.Themes.Icon.ContainsKey($IconTheme)) {
80-
$userThemeData.Themes.Icon.Remove($IconTheme)
81-
} else {
82-
# We shouldn't be here
83-
Write-Error "Icon theme [$IconTheme] is not registered."
83+
if ($Force -or $PSCmdlet.ShouldProcess($ColorTheme, 'Remove icon theme')) {
84+
if ($userThemeData.Themes.Icon.ContainsKey($IconTheme)) {
85+
$userThemeData.Themes.Icon.Remove($IconTheme)
86+
} else {
87+
# We shouldn't be here
88+
Write-Error "Icon theme [$IconTheme] is not registered."
89+
}
90+
Remove-Item $themePath -Force
8491
}
85-
Remove-Item $themePath -Force
8692
}
8793
} else {
8894
Write-Error ("Icon theme [{0}] is active. Please select another theme before removing this it." -f $IconTheme)

Terminal-Icons/Public/Set-TerminalIconsColorTheme.ps1

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ function Set-TerminalIconsColorTheme {
2828
param(
2929
[Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)]
3030
[ArgumentCompleter({
31-
param($Command, $Parameter, $WordToComplete, $CommandAst, $FakeBoundParams)
3231
(Get-TerminalIconsColorTheme).Keys | Sort-Object
3332
})]
3433
[string]$Name

Terminal-Icons/Public/Set-TerminalIconsIconTheme.ps1

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ function Set-TerminalIconsIconTheme {
2828
param(
2929
[Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)]
3030
[ArgumentCompleter({
31-
param($Command, $Parameter, $WordToComplete, $CommandAst, $FakeBoundParams)
3231
(Get-TerminalIconsIconTheme).Keys | Sort-Object
3332
})]
3433
[string]$Name

0 commit comments

Comments
 (0)