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-482: Enforce parameter splatting instead of backtick in Lombiq.Analyzers.PowerShell #28

Merged
merged 10 commits into from
Dec 20, 2022
33 changes: 13 additions & 20 deletions .github/workflows/static-code-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ on:
branches:
- dev

defaults:
run:
shell: pwsh

jobs:
powershell-static-code-analysis:
Piedone marked this conversation as resolved.
Show resolved Hide resolved
name: PowerShell Static Code Analysis
Expand All @@ -20,19 +16,16 @@ jobs:
runs-on: ${{ matrix.machine-type }}

steps:
- uses: actions/checkout@v3
with:
submodules: 'recursive'

- name: Windows PowerShell Static Code Analysis
run: |
if ($Env:RUNNER_OS -ne 'Windows')
{
Write-Output "This step is only for Windows. The current runner is $Env:RUNNER_OS so it's skipped."
exit 0
}
powershell .\tools\Lombiq.Analyzers.PowerShell\Lombiq.Analyzers.PowerShell\Invoke-Analyzer.ps1 -ForGitHubActions

- name: PowerShell 7+ Static Code Analysis
if: always() # Even if the above fails, let's check both.
run: .\tools\Lombiq.Analyzers.PowerShell\Lombiq.Analyzers.PowerShell\Invoke-Analyzer.ps1 -ForGitHubActions
- uses: actions/checkout@v3
Piedone marked this conversation as resolved.
Show resolved Hide resolved
with:
submodules: "recursive"

- name: Windows PowerShell Static Code Analysis (Windows-only)
if: runner.os == 'Windows'
shell: powershell
run: .\tools\Lombiq.Analyzers.PowerShell\Lombiq.Analyzers.PowerShell\Invoke-Analyzer.ps1 -ForGitHubActions

- name: PowerShell 7+ Static Code Analysis
if: always() # Even if the above fails, let's check both.
shell: pwsh
run: .\tools\Lombiq.Analyzers.PowerShell\Lombiq.Analyzers.PowerShell\Invoke-Analyzer.ps1 -ForGitHubActions
22 changes: 11 additions & 11 deletions Ftp/Get-FtpDirectory/Get-FtpDirectory.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,23 @@ function Get-FtpDirectory
[CmdletBinding()]
Param
(
[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage = "Specify a valid FTP server path to a folder.")]
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true,
HelpMessage = "Specify a valid FTP server path to a folder.")]
[string] $Url,

[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage = "Provide username.")]
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true,
HelpMessage = "Provide username.")]
[string] $User,

[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage = "Provide password in SecureString format.")]
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true,
HelpMessage = "Provide password in SecureString format.")]
[securestring] $Password,

[Parameter(Mandatory=$true,
HelpMessage = "Specify path to local folder to download.")]
[Parameter(Mandatory = $true,
HelpMessage = "Specify path to local folder to download.")]
[string] $LocalPath
)

Expand Down
24 changes: 12 additions & 12 deletions Ftp/New-FtpDirectory/New-FtpDirectory.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,23 @@ function New-FtpDirectory
[CmdletBinding()]
Param
(
[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage = "Specify a valid FTP server path to a folder.")]
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true,
HelpMessage = "Specify a valid FTP server path to a folder.")]
[string] $Url,

[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage = "Provide username.")]
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true,
HelpMessage = "Provide username.")]
[string] $User,

[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage = "Provide password in SecureString format.")]
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true,
HelpMessage = "Provide password in SecureString format.")]
[securestring] $Password,

[Parameter(Mandatory=$true,
HelpMessage = "Specify path to local folder to upload.")]
[Parameter(Mandatory = $true,
HelpMessage = "Specify path to local folder to upload.")]
[string] $LocalFolderPath
)

Expand All @@ -44,7 +44,7 @@ function New-FtpDirectory
try
{
$makeDirectory = [System.Net.WebRequest]::Create($Url)
$makeDirectory.Credentials = $credentials
$makeDirectory.Credentials = $credentials
$makeDirectory.Method = [System.Net.WebRequestMethods+FTP]::MakeDirectory
$makeDirectory.EnableSsl = $true
$makeDirectory.GetResponse()
Expand Down
18 changes: 9 additions & 9 deletions Ftp/Remove-FtpDirectory/Remove-FtpDirectory.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ function Remove-FtpDirectory
[CmdletBinding()]
Param
(
[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage = "Specify a valid FTP server path to a folder.")]
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true,
HelpMessage = "Specify a valid FTP server path to a folder.")]
[string] $Url,

[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage = "Provide username.")]
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true,
HelpMessage = "Provide username.")]
[string] $User,

[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage = "Provide password in SecureString format.")]
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true,
HelpMessage = "Provide password in SecureString format.")]
[securestring] $Password
)

Expand Down
26 changes: 13 additions & 13 deletions Ftp/Rename-FtpDirectory/Rename-FtpDirectory.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,28 @@ function Rename-FtpDirectory
[CmdletBinding()]
Param
(
[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage = "Specify a valid FTP server path to a folder that contains the directory which
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true,
HelpMessage = "Specify a valid FTP server path to a folder that contains the directory which
needs to be renamed.")]
[string] $Url,

[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage = "Provide username.")]
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true,
HelpMessage = "Provide username.")]
[string] $User,

[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage = "Provide password in SecureString format.")]
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true,
HelpMessage = "Provide password in SecureString format.")]
[securestring] $Password,

[Parameter(Mandatory=$true,
HelpMessage = "Specify folder to rename.")]
[Parameter(Mandatory = $true,
HelpMessage = "Specify folder to rename.")]
[string] $SourceFolder,

[Parameter(Mandatory=$true,
HelpMessage = "Specify new folder name.")]
[Parameter(Mandatory = $true,
HelpMessage = "Specify new folder name.")]
[string] $DestinationFolder
)

Expand Down
116 changes: 58 additions & 58 deletions Orchard1/Restart-Site/Restart-Site.psm1
Original file line number Diff line number Diff line change
@@ -1,77 +1,77 @@
<#
.Synopsis
Restarts an Orchard 1.x app in IIS.
Restarts an Orchard 1.x app in IIS.

.DESCRIPTION
For an Orchard 1.x app. Deletes the bin, obj App_Data folders and restarts the site in IIS.
For an Orchard 1.x app. Deletes the bin, obj App_Data folders and restarts the site in IIS.

.EXAMPLE
PS > Restart-Site -Path C:\pathToOrchardSource -SiteName siteNameInIIS
PS > Restart-Site -Path C:\pathToOrchardSource -SiteName siteNameInIIS

#>
function Restart-Site
{
[CmdletBinding()]
Param
(
# The path to a folder or a Visual Studio project file to check. The default path is the current execution path.
[string]
$Path,
[CmdletBinding()]
Param
(
# The path to a folder or a Visual Studio project file to check. The default path is the current execution path.
[string]
$Path,

# The name of the IIS site.
[string]
$SiteName
)
# The name of the IIS site.
[string]
$SiteName
)

Process
{
# If the path is invalid, then return an error.
if (!(Test-Path ($Path)))
{
Write-Error ("File or folder not found!")
return
}
Process
{
# If the path is invalid, then return an error.
if (!(Test-Path ($Path)))
{
Write-Error ("File or folder not found!")
return
}

# Stopping IIS site and app pool.
Stop-IISSite $SiteName -confirm:$false
Stop-WebAppPool $SiteName
# Stopping IIS site and app pool.
Stop-IISSite $SiteName -confirm:$false
Stop-WebAppPool $SiteName

# Deleting bin and obj folders.
# Add relative file paths here what you want to keep.
$whiteList = @("\src\Orchard.Azure\Orchard.Azure.CloudService\Orchard.Azure.WebContent\Bin\Startup\SetIdleTimeout.cmd")
# Also add the bin/obj folder's path of the paths in the whiteList here. This is needed for performance reasons, the script will run faster this way.
$whiteListFolders = @("\src\Orchard.Azure\Orchard.Azure.CloudService\Orchard.Azure.WebContent\Bin")
# Deleting bin and obj folders.
# Add relative file paths here what you want to keep.
$whiteList = @("\src\Orchard.Azure\Orchard.Azure.CloudService\Orchard.Azure.WebContent\Bin\Startup\SetIdleTimeout.cmd")
# Also add the bin/obj folder's path of the paths in the whiteList here. This is needed for performance reasons, the script will run faster this way.
$whiteListFolders = @("\src\Orchard.Azure\Orchard.Azure.CloudService\Orchard.Azure.WebContent\Bin")

Get-ChildItem -Path ($Path + "\src\") -Recurse |
Where-Object { $PSItem.PSIsContainer -and ( $PSItem.Name -eq "bin" -or $PSItem.Name -eq "obj") } |
ForEach-Object {
if($whiteListFolders.Contains($PSItem.FullName.Substring($Path.Length)))
{
Get-ChildItem -Path $PSItem.FullName -Recurse -File |
ForEach-Object {
if(!$whiteList.Contains($PSItem.FullName.Substring($Path.Length)))
{
Remove-Item $PSItem.FullName -Force
}
}
}
else
{
Remove-Item $PSItem.FullName -Recurse -Force
}
}
Get-ChildItem -Path ($Path + "\src\") -Recurse |
Where-Object { $PSItem.PSIsContainer -and ( $PSItem.Name -eq "bin" -or $PSItem.Name -eq "obj") } |
ForEach-Object {
if ($whiteListFolders.Contains($PSItem.FullName.Substring($Path.Length)))
{
Get-ChildItem -Path $PSItem.FullName -Recurse -File |
ForEach-Object {
if (!$whiteList.Contains($PSItem.FullName.Substring($Path.Length)))
{
Remove-Item $PSItem.FullName -Force
}
}
}
else
{
Remove-Item $PSItem.FullName -Recurse -Force
}
}

# Deleting App_Data
$appDataPath = $Path + "\src\Orchard.Web\App_Data\"
if(Test-Path ($appDataPath))
{
Remove-Item -Path ($appDataPath) -Recurse -Force
}
# Deleting App_Data
$appDataPath = $Path + "\src\Orchard.Web\App_Data\"
if (Test-Path ($appDataPath))
{
Remove-Item -Path ($appDataPath) -Recurse -Force
}

# Starting IIS site and app pool.
Start-IISSite $SiteName
Start-WebAppPool $SiteName
# Starting IIS site and app pool.
Start-IISSite $SiteName
Start-WebAppPool $SiteName

return
}
return
}
}
12 changes: 9 additions & 3 deletions OrchardCore/Initialize-OrchardCore/Initialize-OrchardCore.psm1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<#
.Synopsis
Initializes an Orchard Core solution for a git repository. Deprecated, use Initialize-OrchardCoreSolution instead.
Initializes an Orchard Core solution for a git repository. Deprecated, use Initialize-OrchardCoreSolution instead.
#>


Expand All @@ -12,7 +12,7 @@ function Initialize-OrchardCore
(
[string] $Path = (Get-Location).Path,

[Parameter(Mandatory=$true)]
[Parameter(Mandatory = $true)]
[string] $Name,

[string] $ModuleName,
Expand All @@ -22,6 +22,12 @@ function Initialize-OrchardCore

Process
{
Initialize-OrchardCoreSolution -Name $Name -Path $Path -ModuleName $ModuleName -ThemeName $ThemeName -NuGetSource $NuGetSource
Initialize-OrchardCoreSolution @{
Name = $Name
Path = $Path
ModuleName = $ModuleName
ThemeName = $ThemeName
NuGetSource = $NuGetSource
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function Initialize-OrchardCoreSolution
(
[string] $Path = (Get-Location).Path,

[Parameter(Mandatory=$true)]
[Parameter(Mandatory = $true)]
[string] $Name,

[string] $ModuleName,
Expand Down
4 changes: 2 additions & 2 deletions OrchardCore/Reset-OrchardCoreApp/Reset-OrchardCoreApp.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ function Reset-OrchardCoreApp

if ($LASTEXITCODE -ne 0)
{
pause
Pause

exit $LASTEXITCODE
}
Expand Down Expand Up @@ -354,7 +354,7 @@ function Reset-OrchardCoreApp

if ($Pause.IsPresent)
{
pause
Pause
}

exit 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ function Import-BacpacToSqlServer
Sort-Object -Descending |
Select-Object -First 1

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