Skip to content

Commit

Permalink
Added PSScriptAnalyzerSettings.psd1 and code formatting fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
RobFaie committed Feb 20, 2020
1 parent 55dc3f9 commit 822af5d
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 16 deletions.
68 changes: 68 additions & 0 deletions PSScriptAnalyzerSettings.psd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
@{
IncludeRules = @(
'PSAlignAssignmentStatement',
'PSAvoid*',
'PSDSC*',
'PSMisleadingBacktick',
'PSMissingModuleManifestField',
'PSPlaceCloseBrace',
'PSPlaceOpenBrace',
'PSPossibleIncorrectComparisonWithNull',
'PSPossibleIncorrectUsageOfAssignmentOperator',
'PSPossibleIncorrectUsageOfRedirectionOperator',
'PSProvideCommentHelp',
'PSReservedCmdletChar',
'PSReservedParams',
'PSShouldProcess',
'PSUse*'
)

Rules = @{
PSPlaceOpenBrace = @{
Enable = $true
OnSameLine = $true
NewLineAfter = $true
IgnoreOneLineBlock = $true
}

PSPlaceCloseBrace = @{
Enable = $true
NewLineAfter = $false
IgnoreOneLineBlock = $true
NoEmptyLineBefore = $false
}

PSUseConsistentIndentation = @{
Enable = $true
Kind = 'space'
PipelineIndentation = 'IncreaseIndentationForFirstPipeline'
IndentationSize = 4
}

PSUseConsistentWhitespace = @{
Enable = $true
CheckInnerBrace = $true
CheckOpenBrace = $false # incorrectly flags all `Should -Throw` Pester assertions
CheckOpenParen = $true
CheckOperator = $false # conflicts with `PSAlignAssignmentStatement`
CheckPipe = $true
CheckSeparator = $true
CheckParameter = $true
}

PSAlignAssignmentStatement = @{
Enable = $true
CheckHashtable = $true
}

PSUseCorrectCasing = @{
Enable = $true
}
}

Severity = @(
'Error'
'Warning'
'Information'
)
}
8 changes: 4 additions & 4 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ stages:
- pwsh: |
Save-Module -Name PSScriptAnalyzer -Path '.' -Repository PSGallery -Confirm:$false
Import-Module -Name './PSScriptAnalyzer/'
Invoke-ScriptAnalyzer -Path '$(Pipeline.Workspace)' -Recurse -EnableExit -ReportSummary | Format-Table -Autosize
Get-ChildItem -Path '$(Pipeline.Workspace)' -Directory | Invoke-ScriptAnalyzer -EnableExit | Format-Table -AutoSize
displayName: Script Analyzer
- pwsh: |
Save-Module -Name Pester -Path '.' -Repository PSGallery -Confirm:$false
Expand All @@ -90,7 +90,7 @@ stages:
- pwsh: |
Save-Module -Name PSScriptAnalyzer -Path '.' -Repository PSGallery -Confirm:$false
Import-Module -Name './PSScriptAnalyzer/'
Invoke-ScriptAnalyzer -Path '$(Pipeline.Workspace)' -Recurse -EnableExit -ReportSummary | Format-Table -Autosize
Get-ChildItem -Path '$(Pipeline.Workspace)' -Directory | Invoke-ScriptAnalyzer -EnableExit | Format-Table -AutoSize
displayName: Script Analyzer
- pwsh: |
Save-Module -Name Pester -Path '.' -Repository PSGallery -Confirm:$false
Expand All @@ -111,7 +111,7 @@ stages:
- pwsh: |
Save-Module -Name PSScriptAnalyzer -Path '.' -Repository PSGallery -Confirm:$false
Import-Module -Name './PSScriptAnalyzer/'
Invoke-ScriptAnalyzer -Path '$(Pipeline.Workspace)' -Recurse -EnableExit -ReportSummary | Format-Table -Autosize
Get-ChildItem -Path '$(Pipeline.Workspace)' -Directory | Invoke-ScriptAnalyzer -EnableExit | Format-Table -AutoSize
displayName: Script Analyzer
- pwsh: |
Save-Module -Name Pester -Path '.' -Repository PSGallery -Confirm:$false
Expand All @@ -132,7 +132,7 @@ stages:
- powershell: |
Save-Module -Name PSScriptAnalyzer -Path '.' -Repository PSGallery -Confirm:$false
Resolve-Path -Path './PSScriptAnalyzer/*/PSScriptAnalyzer.psd1' | Import-Module
Invoke-ScriptAnalyzer -Path '$(Pipeline.Workspace)' -Recurse -EnableExit -ReportSummary | Format-Table -Autosize
Get-ChildItem -Path '$(Pipeline.Workspace)' -Directory | Invoke-ScriptAnalyzer -EnableExit | Format-Table -AutoSize
displayName: Script Analyzer
- powershell: |
Save-Module -Name Pester -Path '.' -Repository PSGallery -Confirm:$false
Expand Down
2 changes: 1 addition & 1 deletion functions/New-Ticket.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ function New-Ticket {
$path = "/api/v2/tickets.json"

$body = @{
ticket = @{}
ticket = @{ }
}

$map = @{
Expand Down
2 changes: 1 addition & 1 deletion functions/Update-Ticket.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ function Update-Ticket {
}

$body = @{
ticket = @{}
ticket = @{ }
}

$map = @{
Expand Down
5 changes: 3 additions & 2 deletions tests/Invoke-Method.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,14 @@ Describe 'Invoke-Method' {
}

It 'Throws with no invalid connection type' {
{
$block = {
Invoke-Method -Path '/' -Context [PSCustomObject]@{
Organization = 'company'
BaseUrl = 'https://company.testdesk.com'
Credential = $null
}
} | Should -Throw
}
$block | Should -Throw
}

It 'Converts Body to JSON by default' {
Expand Down
4 changes: 2 additions & 2 deletions tests/New-UserIdentity.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ Describe 'New-UserIdentity' {
throw 'Please run test in non-interactive mode'
}

{ New-UserIdentity -Context $context -UserId -1 -Value '[email protected]'} | Should -Throw
{ New-UserIdentity -Context $context -UserId -1 -Value '[email protected]' } | Should -Throw
}

It 'Requires Type to be a string' {
{ New-UserIdentity -Context $context -UserId -1 -Type @{ A = 1 } -Value '[email protected]'} | Should -Throw
{ New-UserIdentity -Context $context -UserId -1 -Type @{ A = 1 } -Value '[email protected]' } | Should -Throw
}

It 'Accepts Type: <Type>' -TestCases @(
Expand Down
2 changes: 1 addition & 1 deletion tests/Routes-GroupMemberships.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ Describe 'Group Memberships Routes' {
} # agent GET /api/v2/users/{user_id}/group_memberships/{id}.json

Context 'Create Membership' {
$member = [PSCustomObject]@{ user_id = 1; group_id = 2}
$member = [PSCustomObject]@{ user_id = 1; group_id = 2 }

It 'Matches the endpoint' {
if ($IsInteractive) {
Expand Down
8 changes: 4 additions & 4 deletions tests/Routes-Tags.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -368,26 +368,26 @@ Describe 'Tags Routes' {

$context.User.role = 'admin'

{ Remove-Tag -Context $context -OrganizationId 1 -Tag 'Delivery' -Confirm:$false} | Should -Not -Throw
{ Remove-Tag -Context $context -OrganizationId 1 -Tag 'Delivery' -Confirm:$false } | Should -Not -Throw
Assert-MockCalled Invoke-RestMethod -Exactly 1 -ParameterFilter { $Method -eq 'Delete' -and $Uri -match '/api/v2/organizations/\d+/tags.json' } -Scope It
}

It 'Does not allow end users to call' {
$context.User.role = 'end-user'

{ Remove-Tag -Context $context -OrganizationId 1 -Tag 'Delivery' -Confirm:$false} | Should -Throw 'Authenticated user must have role'
{ Remove-Tag -Context $context -OrganizationId 1 -Tag 'Delivery' -Confirm:$false } | Should -Throw 'Authenticated user must have role'
}

It 'Allows agents to call' {
$context.User.role = 'agent'

{ Remove-Tag -Context $context -OrganizationId 1 -Tag 'Delivery' -Confirm:$false} | Should -Not -Throw
{ Remove-Tag -Context $context -OrganizationId 1 -Tag 'Delivery' -Confirm:$false } | Should -Not -Throw
}

It 'Allows admins to call' {
$context.User.role = 'admin'

{ Remove-Tag -Context $context -OrganizationId 1 -Tag 'Delivery' -Confirm:$false} | Should -Not -Throw
{ Remove-Tag -Context $context -OrganizationId 1 -Tag 'Delivery' -Confirm:$false } | Should -Not -Throw
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Routes-Users.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ Describe 'Users Routes' {

}

Context 'Merge Self With Another User' {} # end-user PUT /api/v2/users/me/merge.json
Context 'Merge Self With Another User' { } # end-user PUT /api/v2/users/me/merge.json

Context 'Merge End Users' {

Expand Down

0 comments on commit 822af5d

Please sign in to comment.