Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OSOE-580: Custom analyzer rule for parameter and variable name styling #47

Merged
merged 13 commits into from
Jun 30, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/static-code-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ on:

jobs:
powershell-static-code-analysis:
uses: Lombiq/PowerShell-Analyzers/.github/workflows/static-code-analysis.yml@dev
uses: Lombiq/PowerShell-Analyzers/.github/workflows/static-code-analysis.yml@issue/OSOE-580
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ function Get-VisualStudioProjectNuGetPackage
ForEach-Object { $PSItem.Trim() } |
Where-Object { $PSItem.StartsWith('>') } |
ForEach-Object {
($Name, $Requested, $Resolved) = $PSItem.TrimStart('>').Split(' ', [System.StringSplitOptions]::RemoveEmptyEntries)
($name, $requested, $resolved) = $PSItem.TrimStart('>').Split(' ', [System.StringSplitOptions]::RemoveEmptyEntries)

New-Object PSObject -Property @{ Name = $Name; Requested = $Requested; Resolved = $Resolved }
New-Object PSObject -Property @{ Name = $name; Requested = $requested; Resolved = $resolved }
}

if (-not [string]::IsNullOrEmpty($PackageNameFilter))
Expand Down
35 changes: 19 additions & 16 deletions Ftp/Get-FtpFile/Get-FtpFile.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,33 @@


# Session.FileTransferProgress event handler.
function FileTransferProgress
function Get-FtpFileTransferProgress
{
param
(
[System.Object] $transferEvent
[System.Object] $TransferEvent
)

if ($null -ne $script:lastFileName -and $script:lastFileName -ne $transferEvent.FileName)
Process
{
Write-Verbose "Next File: $($transferEvent.FileName)"
}
if ($null -ne $script:lastFileName -and $script:lastFileName -ne $TransferEvent.FileName)
{
Write-Verbose "Next File: $($TransferEvent.FileName)"
}

$currentFileName = $transferEvent.FileName
$currentFileProgress = $transferEvent.FileProgress
$currentFileName = $TransferEvent.FileName
$currentFileProgress = $TransferEvent.FileProgress

# If the progress changed compared to the previous state.
if ($currentFileName -ne $script:lastFileName -or $currentFileProgress -ne $script:lastFileProgress)
{
# Print transfer progress.
Write-Verbose ("$($transferEvent.FileName): $($transferEvent.FileProgress * 100)%, Overall: $($transferEvent.OverallProgress * 100)%")
# If the progress changed compared to the previous state.
if ($currentFileName -ne $script:lastFileName -or $currentFileProgress -ne $script:lastFileProgress)
{
# Print transfer progress.
Write-Verbose ("$($TransferEvent.FileName): $($TransferEvent.FileProgress * 100)%, Overall: $($TransferEvent.OverallProgress * 100)%")

# Remember the name of the last file reported.
$script:lastFileName = $transferEvent.FileName
$script:lastFileProgress = $transferEvent.FileProgress
# Remember the name of the last file reported.
$script:lastFileName = $TransferEvent.FileName
$script:lastFileProgress = $TransferEvent.FileProgress
}
}
}

Expand Down Expand Up @@ -82,7 +85,7 @@ function Get-FtpFile

try
{
$session.add_FileTransferProgress({ FileTransferProgress($PSItem) })
$session.add_FileTransferProgress({ Get-FtpFileTransferProgress($PSItem) })

$session.Open($sessionOptions)

Expand Down
14 changes: 7 additions & 7 deletions OrchardCore/Reset-OrchardCoreApp/Reset-OrchardCoreApp.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ function Reset-OrchardCoreApp

# Validating and setting up database server connection.

$SetupDatabaseConnectionString = ''
$setupDatabaseConnectionString = ''
if ($PSCmdlet.ParameterSetName -eq 'ServerDB')
{
if ($SuffixDatabaseNameWithFolderName.IsPresent)
Expand Down Expand Up @@ -209,7 +209,7 @@ function Reset-OrchardCoreApp
}
}

$Security = if (-not $SetupDatabaseSqlPassword)
$security = if (-not $SetupDatabaseSqlPassword)
{
'Integrated Security=True'
}
Expand All @@ -219,7 +219,7 @@ function Reset-OrchardCoreApp
}

# MARS is necessary for Orchard.
$SetupDatabaseConnectionString = "Server=$SetupDatabaseServerName;Database=$SetupDatabaseName;$Security;MultipleActiveResultSets=True;"
$setupDatabaseConnectionString = "Server=$SetupDatabaseServerName;Database=$SetupDatabaseName;$security;MultipleActiveResultSets=True;"
}


Expand All @@ -241,7 +241,7 @@ function Reset-OrchardCoreApp
{
$launchSettings = Get-Content $launchSettingsFilePath | ConvertFrom-Json

$applicationUrlSetting = $launchSettings.profiles."$SiteName".applicationUrl
$applicationUrlSetting = $launchSettings.profiles."$siteName".applicationUrl

if (-not [string]::IsNullOrEmpty($applicationUrlSetting))
{
Expand All @@ -255,7 +255,7 @@ function Reset-OrchardCoreApp
}
}

$environmentSetting = $launchSettings.profiles."$SiteName".environmentVariables.ASPNETCORE_ENVIRONMENT
$environmentSetting = $launchSettings.profiles."$siteName".environmentVariables.ASPNETCORE_ENVIRONMENT

if ([string]::IsNullOrEmpty($environmentSetting))
{
Expand Down Expand Up @@ -321,7 +321,7 @@ function Reset-OrchardCoreApp
SiteName = $SetupSiteName
DatabaseProvider = $SetupDatabaseProvider
TablePrefix = $SetupDatabaseTablePrefix
ConnectionString = $SetupDatabaseConnectionString
ConnectionString = $setupDatabaseConnectionString
RecipeName = $SetupRecipeName
UserName = $SetupUserName
Password = $SetupPassword
Expand Down Expand Up @@ -369,7 +369,7 @@ function Reset-OrchardCoreApp
function GetWebProjectDllPath([string] $WebProjectPath)
{
$siteName = Split-Path $WebProjectPath -Leaf
$webProjectDllPathPattern = "$WebProjectPath\bin\Debug\netcoreapp*\$SiteName.dll"
$webProjectDllPathPattern = "$WebProjectPath\bin\Debug\netcoreapp*\$siteName.dll"

# To avoid Resolve-Path from throwing exception if no path matches the pattern.
if (Test-Path $webProjectDllPathPattern)
Expand Down
26 changes: 13 additions & 13 deletions SqlServer/Import-BacpacToSqlServer/Import-BacpacToSqlServer.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ function Import-BacpacToSqlServer
Process
{
# Setting up SQL Package executable path.
$sqlPackageExecutablePath = ''
$finalSqlPackageExecutablePath = ''
if (-not [string]::IsNullOrEmpty($SqlPackageExecutablePath) -and (Test-Path $SqlPackageExecutablePath))
{
$sqlPackageExecutablePath = $SqlPackageExecutablePath
$finalSqlPackageExecutablePath = $SqlPackageExecutablePath
}
else
{
Expand All @@ -107,12 +107,12 @@ function Import-BacpacToSqlServer

if ([string]::IsNullOrWhiteSpace($locatedPath))
{
$sqlPackageExecutablePath = $defaultSqlPackageExecutablePath
Write-Verbose "SQL Package executable for importing the database found at '$sqlPackageExecutablePath'!"
$finalSqlPackageExecutablePath = $defaultSqlPackageExecutablePath
Write-Verbose "SQL Package executable for importing the database found at '$finalSqlPackageExecutablePath'!"
}
}

if ([string]::IsNullOrEmpty($sqlPackageExecutablePath))
if ([string]::IsNullOrEmpty($finalSqlPackageExecutablePath))
{
throw ('No SQL Package executable found for importing the database! You can download it from' +
' "https://learn.microsoft.com/en-us/sql/tools/sqlpackage/sqlpackage-download"!')
Expand Down Expand Up @@ -150,16 +150,16 @@ function Import-BacpacToSqlServer
$DatabaseName = $databaseSegment.Split('=', 2, [System.StringSplitOptions]::RemoveEmptyEntries)[1]
}

$UsernameSegment = $connectionStringSegments | Where-Object { $PSItem.StartsWith('User Id=') }
if (-not [string]::IsNullOrEmpty($UsernameSegment))
$usernameSegment = $connectionStringSegments | Where-Object { $PSItem.StartsWith('User Id=') }
if (-not [string]::IsNullOrEmpty($usernameSegment))
{
$Username = $UsernameSegment.Split('=', 2, [System.StringSplitOptions]::RemoveEmptyEntries)[1]
$Username = $usernameSegment.Split('=', 2, [System.StringSplitOptions]::RemoveEmptyEntries)[1]
}

$PasswordSegment = $connectionStringSegments | Where-Object { $PSItem.StartsWith('Password=') }
if (-not [string]::IsNullOrEmpty($PasswordSegment))
$passwordSegment = $connectionStringSegments | Where-Object { $PSItem.StartsWith('Password=') }
if (-not [string]::IsNullOrEmpty($passwordSegment))
{
$Password = $PasswordSegment.Split('=', 2, [System.StringSplitOptions]::RemoveEmptyEntries)[1]
$Password = $passwordSegment.Split('=', 2, [System.StringSplitOptions]::RemoveEmptyEntries)[1]
}
}

Expand Down Expand Up @@ -231,7 +231,7 @@ function Import-BacpacToSqlServer
}

# And now we get to actually importing the database after setting up all the necessary parameters.
& "$sqlPackageExecutablePath" @parameters
& "$finalSqlPackageExecutablePath" @parameters



Expand All @@ -242,7 +242,7 @@ function Import-BacpacToSqlServer
# imported.
if ($databaseExists)
{
$server = New-Object ('Microsoft.SqlServer.Management.Smo.Server') (New-SqlServerConnection $SqlServerName $UserName $securePassword)
$server = New-Object ('Microsoft.SqlServer.Management.Smo.Server') (New-SqlServerConnection $SqlServerName $Username $securePassword)
$server.KillAllProcesses($originalDatabaseName)
$server.Databases[$originalDatabaseName].Drop()
$server.Databases[$DatabaseName].Rename($originalDatabaseName)
Expand Down
4 changes: 2 additions & 2 deletions SqlServer/Test-SqlServer/Test-SqlServer.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ function Test-SqlServer

Process
{
$Connection = New-SqlServerConnection $ServerName $UserName $Password
$connection = New-SqlServerConnection $ServerName $UserName $Password

return $null -ne (New-Object ('Microsoft.SqlServer.Management.Smo.Server') $Connection).InstanceName
return $null -ne (New-Object ('Microsoft.SqlServer.Management.Smo.Server') $connection).InstanceName
}
}
4 changes: 2 additions & 2 deletions Utilities/Get-ProcessId/Get-ProcessId.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ function Get-ProcessId

if (-not $CommandLine) { return $processes | ForEach-Object { $PSItem.Id } }

[hashtable[]] $processes = $(if ($host.Version.Major -ge 7)
[hashtable[]] $processes = $(if ($Host.Version.Major -ge 7)
{
$processes | ForEach-Object { @{ Id = $PSItem.Id; CommandLine = $PSItem.CommandLine } }
}
else
{
Get-CimInstance Win32_Process -Filter "name = '${Name}.exe'" |
Get-CimInstance Win32_Process -Filter "name = '$Name.exe'" |
ForEach-Object { @{ Id = $PSItem.Handle; CommandLine = $PSItem.CommandLine } }
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
}
}

function Get-AsciiName([string] $name)
function Get-AsciiName([string] $Name)
{
return [System.Text.Encoding]::ASCII.GetString([System.Text.Encoding]::ASCII.GetBytes($name)).Replace('?', '_')
return [System.Text.Encoding]::ASCII.GetString([System.Text.Encoding]::ASCII.GetBytes($Name)).Replace('?', '_')
}
Loading