Skip to content

Commit 65131fd

Browse files
committedMay 15, 2024
Updating static-code-analysis to use the OSOE-833 issue branch and fixing PSAvoidExclaimOperator violations
1 parent 9f8ecce commit 65131fd

File tree

13 files changed

+32
-32
lines changed

13 files changed

+32
-32
lines changed
 

‎.github/workflows/static-code-analysis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ on:
99

1010
jobs:
1111
powershell-static-code-analysis:
12-
uses: Lombiq/PowerShell-Analyzers/.github/workflows/static-code-analysis.yml@dev
12+
uses: Lombiq/PowerShell-Analyzers/.github/workflows/static-code-analysis.yml@issue/OSOE-833

‎AddPathToPSModulePath.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Param
1919

2020
$paths = [Environment]::GetEnvironmentVariable('PSModulePath', 'Machine').Split(';', [System.StringSplitOptions]::RemoveEmptyEntries)
2121

22-
if (!$paths.Contains($Path))
22+
if (-not $paths.Contains($Path))
2323
{
2424
[System.Environment]::SetEnvironmentVariable('PSModulePath', [string]::Join(';', $paths + $Path), 'Machine')
2525
Write-Verbose "The path `"$Path`" was successfully added to the PSModulePath environment variable."

‎Azure/Copy-ToAzureDevelopmentStorage/Copy-ToAzureDevelopmentStorage.psm1

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function Copy-ToAzureDevelopmentStorage
2424

2525
Process
2626
{
27-
if (!(Test-Path $Path))
27+
if (-not (Test-Path $Path))
2828
{
2929
throw ('The path specified is not valid!')
3030
}
@@ -38,7 +38,7 @@ function Copy-ToAzureDevelopmentStorage
3838

3939
foreach ($folder in Get-ChildItem $Path | Where-Object { $PSItem.PSIsContainer })
4040
{
41-
if ($null -eq $containers -or $containers.Count -eq 0 -or !($containers | Select-Object -ExpandProperty 'Name').Contains($folder.Name))
41+
if ($null -eq $containers -or $containers.Count -eq 0 -or -not ($containers | Select-Object -ExpandProperty 'Name').Contains($folder.Name))
4242
{
4343
New-AzStorageContainer -Context $storageContext -Name $folder.Name -Permission Blob
4444
}

‎Ftp/Get-FtpDirectory/Get-FtpDirectory.psm1

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function Get-FtpDirectory
4949
$listStream = $listResponse.GetResponseStream()
5050
$listReader = New-Object System.IO.StreamReader($listStream)
5151

52-
while (!$listReader.EndOfStream)
52+
while (-not $listReader.EndOfStream)
5353
{
5454
$line = $listReader.ReadLine()
5555
$lines.Add($line) | Out-Null
@@ -73,7 +73,7 @@ function Get-FtpDirectory
7373

7474
if ($isDirectory)
7575
{
76-
if (!(Test-Path $localFilePath -PathType container))
76+
if (-not (Test-Path $localFilePath -PathType container))
7777
{
7878
Write-Verbose "Creating directory $localFilePath"
7979
New-Item $localFilePath -Type directory | Out-Null

‎Ftp/New-FtpDirectory/New-FtpDirectory.psm1

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function New-FtpDirectory
3838

3939
$srcEntries = Get-ChildItem $LocalFolderPath -Recurse
4040
$srcFolders = $srcEntries | Where-Object { $PSItem.PSIsContainer }
41-
$srcFiles = $srcEntries | Where-Object { !$PSItem.PSIsContainer }
41+
$srcFiles = $srcEntries | Where-Object { -not $PSItem.PSIsContainer }
4242

4343
# Create folder.
4444
try

‎Ftp/Remove-FtpDirectory/Remove-FtpDirectory.psm1

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function Remove-FtpDirectory
4545
$listStream = $listResponse.GetResponseStream()
4646
$listReader = New-Object System.IO.StreamReader($listStream)
4747

48-
while (!$listReader.EndOfStream)
48+
while (-not $listReader.EndOfStream)
4949
{
5050
$line = $listReader.ReadLine()
5151
$lines.Add($line) | Out-Null

‎Ftp/Rename-FtpDirectory/Rename-FtpDirectory.psm1

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ function Rename-FtpDirectory
8888
$listStream = $listResponse.GetResponseStream()
8989
$listReader = New-Object System.IO.StreamReader($listStream)
9090

91-
while (!$listReader.EndOfStream)
91+
while (-not $listReader.EndOfStream)
9292
{
9393
$file = $listReader.ReadLine()
9494
$files.Add($file) | Out-Null

‎Orchard1/Restart-Site/Restart-Site.psm1

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function Restart-Site
2626
Process
2727
{
2828
# If the path is invalid, then return an error.
29-
if (!(Test-Path ($Path)))
29+
if (-not (Test-Path ($Path)))
3030
{
3131
Write-Error ('File or folder not found!')
3232
return
@@ -50,7 +50,7 @@ function Restart-Site
5050
{
5151
Get-ChildItem -Path $PSItem.FullName -Recurse -File |
5252
ForEach-Object {
53-
if (!$whiteList.Contains($PSItem.FullName.Substring($Path.Length)))
53+
if (-not $whiteList.Contains($PSItem.FullName.Substring($Path.Length)))
5454
{
5555
Remove-Item $PSItem.FullName -Force
5656
}

‎OrchardCore/Initialize-OrchardCoreSolution/Initialize-OrchardCoreSolution.psm1

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ function Initialize-OrchardCoreSolution
4747
dotnet new sln -o "$Path" -n "$Name"
4848
dotnet sln "$Path/$Name.sln" add "$Path/src/$Name.Web/$Name.Web.csproj"
4949

50-
if (![string]::IsNullOrEmpty($ModuleName))
50+
if (-not [string]::IsNullOrEmpty($ModuleName))
5151
{
5252
dotnet new ocmodulecms -n "$ModuleName" -o "$Path/src/Modules/$ModuleName"
5353
dotnet add "$Path/src/$Name.Web/$Name.Web.csproj" reference "$Path/src/Modules/$ModuleName/$ModuleName.csproj"
5454
dotnet sln "$Path/$Name.sln" add "$Path/src/Modules/$ModuleName/$ModuleName.csproj"
5555
}
5656

57-
if (![string]::IsNullOrEmpty($ThemeName))
57+
if (-not [string]::IsNullOrEmpty($ThemeName))
5858
{
5959
dotnet new octheme -n "$ThemeName" -o "$Path/src/Themes/$ThemeName"
6060
dotnet add "$Path/src/$Name.Web/$Name.Web.csproj" reference "$Path/src/Themes/$ThemeName/$ThemeName.csproj"

‎SqlServer/Import-BacpacToSqlServer/Import-BacpacToSqlServer.psm1

+10-10
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ function Import-BacpacToSqlServer
8383
{
8484
# Setting up SQL Package executable path.
8585
$sqlPackageExecutablePath = ''
86-
if (![string]::IsNullOrEmpty($SqlPackageExecutablePath) -and (Test-Path $SqlPackageExecutablePath))
86+
if (-not [string]::IsNullOrEmpty($SqlPackageExecutablePath) -and (Test-Path $SqlPackageExecutablePath))
8787
{
8888
$sqlPackageExecutablePath = $SqlPackageExecutablePath
8989
}
@@ -122,7 +122,7 @@ function Import-BacpacToSqlServer
122122

123123
# Checking the validity of the bacpac file.
124124
$bacpacFile = Get-Item $BacpacPath
125-
if ($null -eq $bacpacFile -or !($bacpacFile -is [System.IO.FileInfo]) -or !($bacpacFile.Extension -eq '.bacpac'))
125+
if ($null -eq $bacpacFile -or -not ($bacpacFile -is [System.IO.FileInfo]) -or -not ($bacpacFile.Extension -eq '.bacpac'))
126126
{
127127
throw "The .bacpac file is not found at '$BacpacPath'!"
128128
}
@@ -137,27 +137,27 @@ function Import-BacpacToSqlServer
137137
$serverSegment = $connectionStringSegments | Where-Object {
138138
$PSItem.StartsWith('Data Source=') -or $PSItem.StartsWith('Server=')
139139
}
140-
if (!([string]::IsNullOrEmpty($serverSegment)))
140+
if (-not [string]::IsNullOrEmpty($serverSegment))
141141
{
142142
$SqlServerName = $serverSegment.Split('=', 2, [System.StringSplitOptions]::RemoveEmptyEntries)[1]
143143
}
144144

145145
$databaseSegment = $connectionStringSegments | Where-Object {
146146
$PSItem.StartsWith('Initial Catalog=') -or $PSItem.StartsWith('Database=')
147147
}
148-
if (!([string]::IsNullOrEmpty($databaseSegment)))
148+
if (-not [string]::IsNullOrEmpty($databaseSegment))
149149
{
150150
$DatabaseName = $databaseSegment.Split('=', 2, [System.StringSplitOptions]::RemoveEmptyEntries)[1]
151151
}
152152

153153
$UsernameSegment = $connectionStringSegments | Where-Object { $PSItem.StartsWith('User Id=') }
154-
if (!([string]::IsNullOrEmpty($UsernameSegment)))
154+
if (-not [string]::IsNullOrEmpty($UsernameSegment))
155155
{
156156
$Username = $UsernameSegment.Split('=', 2, [System.StringSplitOptions]::RemoveEmptyEntries)[1]
157157
}
158158

159159
$PasswordSegment = $connectionStringSegments | Where-Object { $PSItem.StartsWith('Password=') }
160-
if (!([string]::IsNullOrEmpty($PasswordSegment)))
160+
if (-not [string]::IsNullOrEmpty($PasswordSegment))
161161
{
162162
$Password = $PasswordSegment.Split('=', 2, [System.StringSplitOptions]::RemoveEmptyEntries)[1]
163163
}
@@ -189,16 +189,16 @@ function Import-BacpacToSqlServer
189189
}
190190

191191
$securePassword = $null
192-
if (![string]::IsNullOrEmpty($Password))
192+
if (-not [string]::IsNullOrEmpty($Password))
193193
{
194194
$securePassword = ConvertTo-SecureString $Password -AsPlainText -Force
195195
}
196-
if (!(Test-SqlServer $SqlServerName $Username $securePassword))
196+
if (-not (Test-SqlServer $SqlServerName $Username $securePassword))
197197
{
198198
Write-Warning "Could not find SQL Server at '$SqlServerName'!"
199199
$SqlServerName = 'localhost'
200200

201-
if (!(Test-SqlServer $SqlServerName))
201+
if (-not (Test-SqlServer $SqlServerName))
202202
{
203203
throw 'Could not find any SQL Server instances!'
204204
}
@@ -224,7 +224,7 @@ function Import-BacpacToSqlServer
224224
"/SourceFile:`"$BacpacPath`""
225225
)
226226

227-
if (![string]::IsNullOrEmpty($Username) -and ![string]::IsNullOrEmpty($Password))
227+
if (-not [string]::IsNullOrEmpty($Username) -and -not [string]::IsNullOrEmpty($Password))
228228
{
229229
$parameters += "/TargetUser:`"$Username`""
230230
$parameters += "/TargetPassword:`"$Password`""

‎SqlServer/Test-SqlServerDatabase/Test-SqlServerDatabase.psm1

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function Test-SqlServerDatabase
2626

2727
Process
2828
{
29-
if (!(Test-SqlServer $SqlServerName $UserName $Password))
29+
if (-not (Test-SqlServer $SqlServerName $UserName $Password))
3030
{
3131
throw ("Could not find SQL Server at `"$SqlServerName`"!")
3232
}

‎Utilities/Test-Url/Test-Url.psm1

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ function Test-Url
6161
Start-Sleep -Seconds $Interval
6262
}
6363
}
64-
while (!$success)
64+
while (-not $success)
6565

6666
return $true
6767
}

‎Utilities/Test-VSProjectConsistency/Test-VSProjectConsistency.psm1

+7-7
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function Test-VSProjectConsistency
7272
Process
7373
{
7474
# If the path is invalid, then return an error.
75-
if (!(Test-Path $Path))
75+
if (-not (Test-Path $Path))
7676
{
7777
Write-Error ('File or folder not found!')
7878
return
@@ -131,7 +131,7 @@ function Test-VSProjectConsistency
131131
# Adding additional whitelisted extensions to the whitelist.
132132
foreach ($extension in $AdditionalFileExtensions)
133133
{
134-
if (!$extension.StartsWith('.'))
134+
if (-not $extension.StartsWith('.'))
135135
{
136136
$extension = '.' + $extension
137137
}
@@ -214,7 +214,7 @@ function Test-VSProjectConsistency
214214
$projectFoldersInTheProjectFolder = @()
215215
Get-ChildItem -Path $projectFolder -Recurse |
216216
Where-Object { (PathNotContainsAnyFolder -FullFolderPath $PSItem.FullName -Folders $directoriesToSkip) -and
217-
!$PSItem.FullName.Substring($projectFolder.Length).StartsWith('.') -and
217+
-not $PSItem.FullName.Substring($projectFolder.Length).StartsWith('.') -and
218218
(FolderContainsCsproj $PSItem.FullName)
219219
} |
220220
ForEach-Object { $projectFoldersInTheProjectFolder += $PSItem }
@@ -239,7 +239,7 @@ function Test-VSProjectConsistency
239239
continue
240240
}
241241

242-
if (!$matchingFilesInProjectFile.ToLower().Contains($file.ToLower()))
242+
if (-not $matchingFilesInProjectFile.ToLower().Contains($file.ToLower()))
243243
{
244244
$missingFilesFromProject += $file
245245
}
@@ -267,7 +267,7 @@ function Test-VSProjectConsistency
267267
$helperListForDuplicatedFiles = @()
268268
foreach ($file in $matchingFilesInProjectFile)
269269
{
270-
if (!$matchingFilesInFolder.ToLower().Contains($file.ToLower()))
270+
if (-not $matchingFilesInFolder.ToLower().Contains($file.ToLower()))
271271
{
272272
$missingFilesFromFolder += $file
273273
}
@@ -313,15 +313,15 @@ function Test-VSProjectConsistency
313313
$mapAndMinFilesWithoutParent = @()
314314
foreach ($mapFile in $matchingFilesInProjectFile | Where-Object { $PSItem -match '\.map$' })
315315
{
316-
if (!$matchingFilesInProjectFile.Contains($mapFile.Substring(0, $mapFile.Length - 4)))
316+
if (-not $matchingFilesInProjectFile.Contains($mapFile.Substring(0, $mapFile.Length - 4)))
317317
{
318318
$mapAndMinFilesWithoutParent += $mapFile
319319
}
320320
}
321321
foreach ($minFile in $matchingFilesInProjectFile | Where-Object { $PSItem -match '\.min\.' })
322322
{
323323
$minFileWithoutMin = $minFile -replace '\.min\.', '.'
324-
if (!($matchingFilesInProjectFile.Contains(($minFileWithoutMin)) -or
324+
if (-not ($matchingFilesInProjectFile.Contains(($minFileWithoutMin)) -or
325325
$matchingFilesInProjectFile.Contains(($minFileWithoutMin -replace '\.map', ''))))
326326
{
327327
$mapAndMinFilesWithoutParent += $minFile

0 commit comments

Comments
 (0)
Please sign in to comment.