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

Fix formatting in all files #1949

Merged
merged 2 commits into from
May 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 0 additions & 3 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,15 @@
"VARIANT": "3.1"
}
},

// Set *default* container specific settings.json values on container create.
"settings": {
"terminal.integrated.shell.linux": "/bin/bash"
},

// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"ms-vscode.powershell",
"ms-dotnettools.csharp"
],

// Use 'postCreateCommand' to run commands after the container is created.
// Restoring the c# projects
"postCreateCommand": "dotnet restore src/csharp"
Expand Down
12 changes: 6 additions & 6 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
contact_links:
- name: Need help?
url: https://pester.dev/docs/contributing/introduction#where-to-get-support
about: Join our online communities to get help with "How to do _____ with Pester?" questions.
- name: Documentation issue beyond Command Reference?
url: https://github.com/pester/docs/issues/new
about: Please report non-command documentation issue for https://pester.dev in the docs repo
- name: Need help?
url: https://pester.dev/docs/contributing/introduction#where-to-get-support
about: Join our online communities to get help with "How to do _____ with Pester?" questions.
- name: Documentation issue beyond Command Reference?
url: https://github.com/pester/docs/issues/new
about: Please report non-command documentation issue for https://pester.dev in the docs repo
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ Test.xml
vendor/packages/
.DS_Store
.vscode/
# But don't exclude settings.json
!.vscode/settings.json

coverage.xml
testResults.xml

Expand Down Expand Up @@ -359,3 +362,4 @@ MigrationBackup/
.ionide/

tmp/

8 changes: 4 additions & 4 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"powershell.codeFormatting.preset": "Stroustrup",

"files.trimTrailingWhitespace": true,
"files.insertFinalNewline": true,

"editor.tabSize": 4,
"editor.formatOnSave": false,
"powershell.codeFormatting.addWhitespaceAroundPipe": true
"editor.formatOnSave": true,
"powershell.codeFormatting.addWhitespaceAroundPipe": true,
"powershell.codeFormatting.pipelineIndentationStyle": "IncreaseIndentationForFirstPipeline",
"yaml.format.singleQuote": true
}
6 changes: 3 additions & 3 deletions PSScriptAnalyzerSettings.psd1
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
@{
Severity = @('Error','Warning')
Severity = @('Error', 'Warning')
IncludeDefaultRules = $true
CustomRulePath = './Pester.BuildAnalyzerRules'
ExcludeRules=@(
CustomRulePath = './Pester.BuildAnalyzerRules'
ExcludeRules = @(
'PSUseShouldProcessForStateChangingFunctions'
'PSUseApprovedVerbs'
'Measure-SafeCommands'
Comment on lines 1 to 8
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. PSD1 formatting sucks.

Expand Down
2 changes: 1 addition & 1 deletion Pester.BuildAnalyzerRules/Pester.BuildAnalyzerRules.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function Measure-SafeCommands {
if ($null -ne $commandName -and $commandName -in $SafeCommands.Keys -and $commandName -notin $IgnoreUnsafeCommands) {
foreach ($cmd in $CommandAst.CommandElements) {
# Find extent for command name only
if(($cmd -is [System.Management.Automation.Language.StringConstantExpressionAst]) -and $cmd.Value -eq $commandName) {
if (($cmd -is [System.Management.Automation.Language.StringConstantExpressionAst]) -and $cmd.Value -eq $commandName) {

#Define fix-action
[int]$startLineNumber = $cmd.Extent.StartLineNumber
Expand Down
18 changes: 9 additions & 9 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@

Any issues with Pester are generally fixed in the latest releases. There has been no specific security patches to this date.

| Version | Supported |Notes
| ------- | ------------------ |-----------------------
| 5.1.x | :white_check_mark: |Actively maintained
| 5.0.x | :x: |Critical issues fixed.
| 4.0.x | :white_check_mark: |Critical issues fixed.
| < 4.0 | :x: |Critical issues fixed.
| 3.x.x | :x: |Not actively maintaned
| Version | Supported | Notes |
| ------- | ------------------ | ---------------------- |
| 5.1.x | :white_check_mark: | Actively maintained |
| 5.0.x | :x: | Critical issues fixed. |
| 4.0.x | :white_check_mark: | Critical issues fixed. |
| < 4.0 | :x: | Critical issues fixed. |
| 3.x.x | :x: | Not actively maintaned |

## Reporting a Vulnerability

Pester uses a small library of C# code that depends on the .NET Framework. There are currently no known security vulnerabilities with the Pester Powershell framework.
Pester uses a small library of C# code that depends on the .NET Framework. There are currently no known security vulnerabilities with the Pester Powershell framework.

To report security vulnerabilities in Powershell, .NET, Windows, or other Microsoft Products & Services, visit the following links:
To report security vulnerabilities in Powershell, .NET, Windows, or other Microsoft Products & Services, visit the following links:
<https://www.microsoft.com/en-us/msrc/faqs-report-an-issue>
<https://www.microsoft.com/en-us/msrc/bounty>

Expand Down
8 changes: 4 additions & 4 deletions SUPPORT.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Support

Please review the contribution documentation located at following links before submitting an issue:
Please review the contribution documentation located at following links before submitting an issue:

[Reporting Issues](https://pester.dev/docs/contributing/reporting-issues)
[Feature Requests](https://pester.dev/docs/contributing/feature-requests)
[Reporting Issues](https://pester.dev/docs/contributing/reporting-issues)
[Feature Requests](https://pester.dev/docs/contributing/feature-requests)

Feature Requests & Issues are reported using Github issues.

[Feature Requests and Issues](https://github.com/pester/Pester/issues).
[Feature Requests and Issues](https://github.com/pester/Pester/issues).
17 changes: 10 additions & 7 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,23 @@
Used to build and import the Pester module during Pester development.

The code that should be excluded from the build is wrapped in this if:
# PESTER_BUILD
if (-not (Get-Variable -Name "PESTER_BUILD" -ValueOnly -ErrorAction Ignore)) {
...Your code here...
} # endif
}
# end PESTER_BUILD

This will exclude the code from execution when dot-sourcing, but keep it when running the
file directly. When inlining into single file, the regex below will omit the wrapped code.
The # endif comment is significant, because it allows the regex to identify the correct end }.

You can also include the code in build. Which will run the code only when dot-sources into Pester.psm1.

# PESTER_BUILD
if ((Get-Variable -Name "PESTER_BUILD" -ValueOnly -ErrorAction Ignore)) {
...Your code here...
} # endif
}
# end PESTER_BUILD

Or any other if that uses the variable.

Expand Down Expand Up @@ -231,10 +235,9 @@ foreach ($f in $files) {
$null = $sb.AppendLine("# file $relativePath")
$noBuild = $false
foreach ($l in $lines) {
# when inlining the code skip everything wrapped in this if
# if (something with PESTER_BUILD) {
# } # endif
if ($l -match '^\s*if.*PESTER_BUILD') {
# when inlining the code skip everything wrapped in # PESTER_BUILD, # end PESTER_BUILD
#
if ($l -match '^.*#\s*PESTER_BUILD') {
# start skipping lines
$noBuild = $true
}
Expand All @@ -244,7 +247,7 @@ foreach ($f in $files) {
$null = $sb.AppendLine($l)
}

if ($l -match "\s*}\s*#\s*end\s*if\s*$") {
if ($l -match '^.*#\s*end\s*PESTER_BUILD') {
# stop skipping lines
$noBuild = $false
}
Expand Down
10 changes: 5 additions & 5 deletions docs/Examples/Planets/Get-Planet.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
function Get-Planet ([string]$Name = '*') {
$planets = @(
@{ Name = 'Mercury' }
@{ Name = 'Venus' }
@{ Name = 'Earth' }
@{ Name = 'Mars' }
@{ Name = 'Venus' }
@{ Name = 'Earth' }
@{ Name = 'Mars' }
@{ Name = 'Jupiter' }
@{ Name = 'Saturn' }
@{ Name = 'Uranus' }
@{ Name = 'Saturn' }
@{ Name = 'Uranus' }
@{ Name = 'Neptune' }
) | ForEach-Object { [PSCustomObject] $_ }

Expand Down
31 changes: 15 additions & 16 deletions publish/release.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ if ($LASTEXITCODE -ne 0) {
}

$m = Test-ModuleManifest $bin/Pester.psd1
$version = if ($m.PrivateData -and $m.PrivateData.PSData -and $m.PrivateData.PSData.PreRelease)
{
$version = if ($m.PrivateData -and $m.PrivateData.PSData -and $m.PrivateData.PSData.PreRelease) {
"$($m.Version)-$($m.PrivateData.PSData.PreRelease)"
}
else {
Expand Down Expand Up @@ -57,20 +56,20 @@ if ((Get-Item $bin/Pester.psm1).Length -lt 50KB) {


$files = @(
"nunit_schema_2.5.xsd"
"junit_schema_4.xsd"
"Pester.psd1"
"Pester.psm1"
"report.dtd"
"bin\net452\Pester.dll"
"bin\net452\Pester.pdb"
"bin\netstandard2.0\Pester.dll"
"bin\netstandard2.0\Pester.pdb"
"en-US\about_BeforeEach_AfterEach.help.txt"
"en-US\about_Mocking.help.txt"
"en-US\about_Pester.help.txt"
"en-US\about_Should.help.txt"
"en-US\about_TestDrive.help.txt"
"nunit_schema_2.5.xsd"
"junit_schema_4.xsd"
"Pester.psd1"
"Pester.psm1"
"report.dtd"
"bin\net452\Pester.dll"
"bin\net452\Pester.pdb"
"bin\netstandard2.0\Pester.dll"
"bin\netstandard2.0\Pester.pdb"
"en-US\about_BeforeEach_AfterEach.help.txt"
"en-US\about_Mocking.help.txt"
"en-US\about_Pester.help.txt"
"en-US\about_Should.help.txt"
"en-US\about_TestDrive.help.txt"
)

$notFound = @()
Expand Down
12 changes: 6 additions & 6 deletions publish/signModule.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ param($Thumbprint, $Path)
$ErrorActionPreference = 'Stop'

$cert = Get-ChildItem Cert:\CurrentUser\My |
Where-Object Thumbprint -eq $Thumbprint
Where-Object Thumbprint -eq $Thumbprint

if ($null -eq $cert) {
throw "No certificate was found."
Expand All @@ -29,11 +29,11 @@ if (-not @($filesToSign)) {
}

$results = $filesToSign |
ForEach-Object {
$r = Set-AuthenticodeSignature $_ -Certificate $cert -TimestampServer 'http://timestamp.digicert.com' -ErrorAction Stop
$r | Out-String | Write-Host
$r
}
ForEach-Object {
$r = Set-AuthenticodeSignature $_ -Certificate $cert -TimestampServer 'http://timestamp.digicert.com' -ErrorAction Stop
$r | Out-String | Write-Host
$r
}

$failed = $results | Where-Object { $_.Status -ne "Valid" }

Expand Down
10 changes: 6 additions & 4 deletions src/Format.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# PESTER_BUILD
if (-not (Get-Variable -Name "PESTER_BUILD" -ValueOnly -ErrorAction Ignore)) {
. "$PSScriptRoot/functions/Pester.SafeCommands.ps1"
. "$PSScriptRoot/TypeClass.ps1"
} # endif
}
# end PESTER_BUILD

function Format-Collection ($Value, [switch]$Pretty) {
$Limit = 10
Expand All @@ -10,8 +12,8 @@ function Format-Collection ($Value, [switch]$Pretty) {
$separator = ",`n"
}
$count = $Value.Count
$trimmed = $count -gt $Limit
'@(' + (($Value | & $SafeCommands['Select-Object'] -First $Limit | & $SafeCommands['ForEach-Object'] { Format-Nicely -Value $_ -Pretty:$Pretty }) -join $separator) + $(if ($trimmed) {', ...'}) + ')'
$trimmed = $count -gt $Limit
'@(' + (($Value | & $SafeCommands['Select-Object'] -First $Limit | & $SafeCommands['ForEach-Object'] { Format-Nicely -Value $_ -Pretty:$Pretty }) -join $separator) + $(if ($trimmed) { ', ...' }) + ')'
}

function Format-Object ($Value, $Property, [switch]$Pretty) {
Expand Down Expand Up @@ -140,7 +142,7 @@ function Format-Nicely ($Value, [switch]$Pretty) {
function Sort-Property ($InputObject, [string[]]$SignificantProperties, $Limit = 4) {

$properties = @($InputObject.PSObject.Properties |
& $SafeCommands['Where-Object'] { $_.Name -notlike "_*"} |
& $SafeCommands['Where-Object'] { $_.Name -notlike "_*" } |
& $SafeCommands['Select-Object'] -expand Name |
& $SafeCommands['Sort-Object'])
$significant = @()
Expand Down