Skip to content

Commit bc00f56

Browse files
committed
Added Run-PSScriptAnalyzer for checking code quality
excluded Run-PSScriptAnalyzer.ps1 from module fixed problems in existing files.
1 parent a6e2f07 commit bc00f56

File tree

8 files changed

+56
-19
lines changed

8 files changed

+56
-19
lines changed

NullKit.psm1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
$Public = Get-ChildItem -Path $PSScriptRoot -Recurse -Filter "*.ps1" | ? { $_.Name[0].Equals($_.Name.ToUpper()[0]) }
1+
$Public = Get-ChildItem -Path $PSScriptRoot -Recurse -Filter "*.ps1" -Exclude "Run-PSScriptAnalyzer.ps1" | ? { $_.Name[0].Equals($_.Name.ToUpper()[0]) }
22

33
Foreach ($import in $Public) {
44
try {

Run-PSScriptAnalyzer.ps1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Import-Module "$env:USERPROFILE\.vscode\extensions\ms-vscode.powershell-*\modules\PSScriptAnalyzer\*\PSScriptAnalyzer.psm1"
2+
3+
$Public = Get-ChildItem -Path $PSScriptRoot -Recurse -Filter "*.ps1" | ? { $_.Name[0].Equals($_.Name.ToUpper()[0]) }
4+
5+
$Public | % { Invoke-ScriptAnalyzer -Path $_.fullname -Settings .\PSScriptAnalyzerSettings.psd1 }

dir/New-FolderJunction.ps1

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Creates a junction for "c:\repo\serialization" folder in "c:\sites\website1\Data
1616
Serialization data from the repository will be available in the website.
1717
#>
1818

19-
[CmdletBinding()]
19+
[CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'Medium')]
2020
param (
2121
[parameter(Mandatory = $true, Position = 0)]
2222
[string]$Source,
@@ -25,6 +25,8 @@ Serialization data from the repository will be available in the website.
2525
)
2626

2727
process {
28-
New-Item -Path $Destination -ItemType SymbolicLink -Value $Source
28+
if ($PSCmdlet.ShouldProcess("$Source")) {
29+
New-Item -Path $Destination -ItemType SymbolicLink -Value $Source
30+
}
2931
}
3032
}

git/Remove-MergedBranches.ps1

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,18 @@ Removes all merged branches except default branches: master, develop
1818
Removes all merged branches except specified branches: master, feature1
1919
#>
2020

21-
[CmdletBinding()]
21+
[CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'Medium')]
2222
param(
2323
[Parameter(Mandatory = $false)]
2424
[string[]]$Branches = @("master", "develop")
2525
)
2626

2727
process {
2828
. $PSScriptRoot\Get-MergedBranchces.ps1 $Branches | % {
29-
git branch -d $_
29+
$branch = $_
30+
if ($PSCmdlet.ShouldProcess($branch)) {
31+
git branch -d $branch
32+
}
3033
}
3134
}
3235
}

git/Remove-MergedRemoteBranches.ps1

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Removes all merged remote branches except default branches: master, develop, HEA
1818
Removes all merged remote branches except specified branches: master, feature1
1919
#>
2020

21-
[CmdletBinding()]
21+
[CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'Medium')]
2222
param(
2323
[Parameter(Mandatory = $false)]
2424
[string[]]$Branches = @("master", "develop", "HEAD")
@@ -30,7 +30,9 @@ Removes all merged remote branches except specified branches: master, feature1
3030
$origin = $_.Substring(0, $i)
3131
$branch = $_.Substring($i + 1)
3232
Write-Host "$origin -> $branch"
33-
git push $origin --delete $branch
33+
if ($PSCmdlet.ShouldProcess($branch)) {
34+
git push $origin --delete $branch
35+
}
3436
}
3537
}
3638
}

git/Test-GitStatus.ps1

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ Iterates through folders from a 'c:\repo' directory and displays git status of e
6565
}
6666
}
6767
}
68-
catch { }
6968
finally {
7069
Set-Location $revertPath
7170
}

strings/Remove-Comments.ps1

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
function Remove-Comments {
2-
[CmdletBinding()]
2+
[CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'Medium')]
33
param(
44
[Parameter(Mandatory = $true, Position = 0 )]
55
[System.IO.FileInfo]$File
@@ -27,7 +27,9 @@ function Remove-Comments {
2727
$stop = $false
2828
}
2929
}
30-
Set-Content -Value $contentWithoutComments -Path $file.FullName
30+
if ($PSCmdlet.ShouldProcess("$($file.FullName)")) {
31+
Set-Content -Value $contentWithoutComments -Path $file.FullName
32+
}
3133
}
3234

3335
end {
Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,37 @@
11
function Restart-WiFi {
2-
$ssid = netsh wlan show interfaces | ? { $_.Contains(" SSID ") }
2+
<#
3+
.SYNOPSIS
4+
Restats WiFi connection
35
4-
$connectionProfile = Get-NetConnectionProfile -IPv4Connectivity Internet | ? { $ssid.Contains($_.Name) } | Select-Object -First 1
5-
$ssid = $connectionProfile.Name
6-
$interface = $connectionProfile.InterfaceAlias
6+
.DESCRIPTION
7+
Check if there is any active wlan interface and restarts its connection.
78
8-
Write-Host "Disconnecting interface: $interface" -ForegroundColor Green
9-
netsh wlan disconnect
10-
Start-Sleep -Seconds 2
11-
Write-Host "Connecting to SSID: $ssid on interface: $interface" -ForegroundColor Green
12-
netsh wlan connect interface=$interface name=$ssid
9+
.EXAMPLE
10+
Restart-WiFi
11+
Restat WiFi interface if there is any currently active.
12+
13+
#>
14+
15+
[CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'Medium')]
16+
param()
17+
18+
process {
19+
$ssid = netsh wlan show interfaces | ? { $_.Contains(" SSID ") }
20+
if ($ssid) {
21+
$connectionProfile = Get-NetConnectionProfile -IPv4Connectivity Internet | ? { $ssid.Contains($_.Name) } | Select-Object -First 1
22+
$ssid = $connectionProfile.Name
23+
$interface = $connectionProfile.InterfaceAlias
24+
25+
if ($PSCmdlet.ShouldProcess("$interface")) {
26+
Write-Host "Disconnecting interface: $interface" -ForegroundColor Green
27+
netsh wlan disconnect
28+
Start-Sleep -Seconds 2
29+
Write-Host "Connecting to SSID: $ssid on interface: $interface" -ForegroundColor Green
30+
netsh wlan connect interface=$interface name=$ssid
31+
}
32+
}
33+
else {
34+
Write-Host "Couldn't find active wlan itnerface" -ForegroundColor Red
35+
}
36+
}
1337
}

0 commit comments

Comments
 (0)