Skip to content

Commit

Permalink
Merge pull request #2211 from microsoft/dpaul-CodeFormatterCheck
Browse files Browse the repository at this point in the history
CodeFormatter Rule Update - Include Operator to be lowercase
  • Loading branch information
dpaulson45 authored Oct 24, 2024
2 parents 2262289 + 8f4a09b commit a6be221
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 26 deletions.
7 changes: 4 additions & 3 deletions .build/CodeFormatter.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ Set-StrictMode -Version Latest
. $PSScriptRoot\CodeFormatterChecks\CheckMultipleEmptyLines.ps1
. $PSScriptRoot\CodeFormatterChecks\CheckScriptFileHasBOM.ps1
. $PSScriptRoot\CodeFormatterChecks\CheckScriptFileHasComplianceHeader.ps1
. $PSScriptRoot\CodeFormatterChecks\CheckKeywordCasing.ps1
. $PSScriptRoot\CodeFormatterChecks\CheckScriptFormat.ps1
. $PSScriptRoot\CodeFormatterChecks\CheckTokenTypeCasing.ps1
. $PSScriptRoot\HelpFunctions\Get-CommitFilesOnBranch.ps1

if (-not (Load-Module -Name PSScriptAnalyzer -MinimumVersion "1.21")) {
if (-not (Load-Module -Name PSScriptAnalyzer -MinimumVersion "1.23")) {
throw "PSScriptAnalyzer module could not be loaded"
}

Expand Down Expand Up @@ -68,7 +68,8 @@ foreach ($fileInfo in $filesToCheck) {
$errorCount += (CheckMarkdownFileHasNoBOM $fileInfo $Save) ? 1 : 0
$errorCount += (CheckScriptFileHasBOM $fileInfo $Save) ? 1 : 0
$errorCount += (CheckScriptFileHasComplianceHeader $fileInfo $Save) ? 1 : 0
$errorCount += (CheckKeywordCasing $fileInfo $Save) ? 1 : 0
$errorCount += (CheckTokenTypeCasing $fileInfo $Save "Keyword") ? 1 : 0
$errorCount += (CheckTokenTypeCasing $fileInfo $Save "Operator") ? 1 : 0
$errorCount += (CheckMultipleEmptyLines $fileInfo $Save) ? 1 : 0
$errorCount += (CheckContainsCurlyQuotes $fileInfo $Save) ? 1 : 0

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

function CheckKeywordCasing {
function CheckTokenTypeCasing {
[CmdletBinding()]
[OutputType([boolean])]
param (
Expand All @@ -11,7 +11,12 @@ function CheckKeywordCasing {

[Parameter()]
[boolean]
$Save
$Save,

[Parameter()]
[ValidateSet("Operator", "Keyword")]
[string]
$Type
)

if ($FileInfo.Extension -eq ".ps1" -or $FileInfo.Extension -eq ".psm1") {
Expand All @@ -25,15 +30,15 @@ function CheckKeywordCasing {

$keywordWrongCase = @()
foreach ($t in $tokens) {
if ($t.Type -eq "Keyword") {
if ($t.Type -eq $Type) {
if (-not $t.Content.Equals($t.Content.ToLower(), "Ordinal")) {
$keywordWrongCase += $t

if ($Save) {
$content = $content.Remove($t.Start, $t.Length).Insert($t.Start, $t.Content.ToLower())
Write-Host "Corrected case of keyword: $($t.Content) at position $($t.Start) in $($FileInfo.FullName)"
Write-Host "Corrected case of $Type`: $($t.Content) at position $($t.Start) in $($FileInfo.FullName)"
} else {
Write-Warning "Keyword $($t.Content) at position $($t.Start) in $($FileInfo.FullName) is not lowercase."
Write-Warning "$Type $($t.Content) at position $($t.Start) in $($FileInfo.FullName) is not lowercase."
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function Get-ExchangeAuthCertificateStatus {
$allMailboxServers = Get-ExchangeServer | Where-Object {
((($_.IsMailboxServer) -or
($_.IsClientAccessServer)) -and
($_.AdminDisplayVersion -Match "^Version 15"))
($_.AdminDisplayVersion -match "^Version 15"))
}

$multipleExchangeSites = (($allMailboxServers.Site.Name | Sort-Object -Unique).Count -gt 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function Test-IsServerValidForAuthCertificateGeneration {
$exchangeServerDetails = Get-ExchangeServer -Identity $ComputerName -ErrorAction Stop

if (($exchangeServerDetails.IsMailboxServer) -and
(($exchangeServerDetails.AdminDisplayVersion -Match "^Version 15"))) {
(($exchangeServerDetails.AdminDisplayVersion -match "^Version 15"))) {
Write-Verbose ("Exchange Server role and version is VALID to renew the Auth Certificate")
$isValid = $true
} else {
Expand Down
16 changes: 8 additions & 8 deletions Calendar/Get-RBASummary.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -539,8 +539,8 @@ function RBALogSummary {
$LastDate = "[Unknown]"

if ($starts.count -gt 1) {
$LastDate = ($Starts[0] -Split ",")[0].Trim()
$FirstDate = ($starts[$($Starts.count) -1 ] -Split ",")[0].Trim()
$LastDate = ($Starts[0] -split ",")[0].Trim()
$FirstDate = ($starts[$($Starts.count) -1 ] -split ",")[0].Trim()
Write-Host "`tThe RBA Log for [$Identity] shows the following:"
Write-Host "`t $($starts.count) Processed events times between $FirstDate and $LastDate"
}
Expand All @@ -555,19 +555,19 @@ function RBALogSummary {
$Cancellations = $RBALog | Select-String -Pattern "It's a meeting cancellation."

if ($AcceptLogs.count -ne 0) {
$LastAccept = ($AcceptLogs[0] -Split ",")[0].Trim()
$LastAccept = ($AcceptLogs[0] -split ",")[0].Trim()
Write-Host "`t $($AcceptLogs.count) were Accepted between $FirstDate and $LastDate"
Write-Host "`t`t with the last meeting Accepted on $LastAccept"
}

if ($TentativeLogs.count -ne 0) {
$LastTentative = ($TentativeLogs[0] -Split ",")[0].Trim()
$LastTentative = ($TentativeLogs[0] -split ",")[0].Trim()
Write-Host "`t $($TentativeLogs.count) Tentatively Accepted meetings between $FirstDate and $LastDate"
Write-Host "`t`t with the last meeting Tentatively Accepted on $LastTentative"
}

if ($DeclineLogs.count -ne 0) {
$LastDecline = ($DeclineLogs[0] -Split ",")[0].Trim()
$LastDecline = ($DeclineLogs[0] -split ",")[0].Trim()
Write-Host "`t $($DeclineLogs.count) Declined meetings between $FirstDate and $LastDate"
Write-Host "`t`t with the last meeting Declined on $LastDecline"
}
Expand All @@ -577,7 +577,7 @@ function RBALogSummary {
}

if ($UpdatedLogs.count -ne 0) {
$LastUpdated = ($UpdatedLogs[0] -Split ",")[0].Trim()
$LastUpdated = ($UpdatedLogs[0] -split ",")[0].Trim()
Write-Host "`t $($UpdatedLogs.count) Updates to meetings between $FirstDate and $LastDate"
Write-Host "`t`t with the last meeting updated on $LastUpdated"
} else {
Expand All @@ -591,15 +591,15 @@ function RBALogSummary {
}

if ($DelegateReferrals.count -ne 0) {
$LastDelegateReferral = ($DelegateReferrals[0] -Split ",")[0].Trim()
$LastDelegateReferral = ($DelegateReferrals[0] -split ",")[0].Trim()
Write-Host "`t $($DelegateReferrals.count) Delegate Referrals were sent between $FirstDate and $LastDate"
Write-Host "`t`t with the last Delegate Referral sent on $LastDelegateReferral"
} else {
Write-Host "`t No Delegate Referrals were sent in the RBA Log."
}

if ($NonMeetingRequests.count -ne 0) {
$LastNonMeetingRequest = ($NonMeetingRequests[0] -Split ",")[0].Trim()
$LastNonMeetingRequest = ($NonMeetingRequests[0] -split ",")[0].Trim()
Write-Host "`t $($NonMeetingRequests.count) Non Meeting Requests were skipped between $FirstDate and $LastDate"
Write-Host "`t`t with the last Non Meeting Request skipped on $LastNonMeetingRequest"
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ function Get-LoadBalancingReport {
Write-Grey("Site filtering ON. Only Exchange 2013+ CAS servers in {0} will be used in the report." -f $SiteName)
$CASServers = $getExchangeServer | Where-Object {
($_.IsClientAccessServer -eq $true) -and
($_.AdminDisplayVersion -Match "^Version 15") -and
($_.AdminDisplayVersion -match "^Version 15") -and
([System.Convert]::ToString($_.Site).Split("/")[-1] -eq $SiteName) } | Select-Object Name, Site | Sort-Object Name
Write-Grey("Site filtering ON. Only Exchange 2013+ MBX servers in {0} will be used in the report." -f $SiteName)
$MBXServers = $getExchangeServer | Where-Object {
($_.IsMailboxServer -eq $true) -and
($_.AdminDisplayVersion -Match "^Version 15") -and
($_.AdminDisplayVersion -match "^Version 15") -and
([System.Convert]::ToString($_.Site).Split("/")[-1] -eq $SiteName) } | Select-Object Name, Site | Sort-Object Name
} else {
if ( ($null -eq $ServerList) ) {
Write-Grey("Filtering OFF. All Exchange 2013+ servers will be used in the report.")
$CASServers = $getExchangeServer | Where-Object { ($_.IsClientAccessServer -eq $true) -and ($_.AdminDisplayVersion -Match "^Version 15") } | Select-Object Name, Site | Sort-Object Name
$MBXServers = $getExchangeServer | Where-Object { ($_.IsMailboxServer -eq $true) -and ($_.AdminDisplayVersion -Match "^Version 15") } | Select-Object Name, Site | Sort-Object Name
$CASServers = $getExchangeServer | Where-Object { ($_.IsClientAccessServer -eq $true) -and ($_.AdminDisplayVersion -match "^Version 15") } | Select-Object Name, Site | Sort-Object Name
$MBXServers = $getExchangeServer | Where-Object { ($_.IsMailboxServer -eq $true) -and ($_.AdminDisplayVersion -match "^Version 15") } | Select-Object Name, Site | Sort-Object Name
} else {
Write-Grey("Custom server list is being used. Only servers specified after the -ServerList parameter will be used in the report.")
$CASServers = $getExchangeServer | Where-Object { ($_.IsClientAccessServer -eq $true) -and ( ($_.Name -in $ServerList) -or ($_.FQDN -in $ServerList) ) } | Select-Object Name, Site | Sort-Object Name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ function InvestigateProbe {
param([String]$ProbeToInvestigate , [String]$MonitorToInvestigate , [String]$ResponderToInvestigate , [String]$ResourceNameToInvestigate , [String]$ResponderTargetResource )

TestFileOrCmd $ProbeDefinitionEventCmd
if (-Not ($ResponderTargetResource) -and ($ProbeToInvestigate.split("/").Count -gt 1)) {
if (-not ($ResponderTargetResource) -and ($ProbeToInvestigate.split("/").Count -gt 1)) {
$ResponderTargetResource = $ProbeToInvestigate.split("/")[1]
}
$ProbeDetailsCmd = '(' + $ProbeDefinitionEventCmd + '| % {[XML]$_.toXml()}).event.userData.eventXml| ? {$_.Name -like "' + $ProbeToInvestigate.split("/")[0] + '*" }'
Expand Down
2 changes: 1 addition & 1 deletion PublicFolders/Update-PublicFolderPermissions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ function FindFoldersToUpdate([string[]]$includeFolders, [bool]$recurseOnFolders,
continue
}

if ($folderToSkip -notContains $foundFolder.EntryId) {
if ($folderToSkip -notcontains $foundFolder.EntryId) {
Write-Verbose "$($MyInvocation.MyCommand): Returning found folder $($foundFolder.Identity) with EntryId $($foundFolder.EntryID)"
#Return found folder
$foundFolder
Expand Down
4 changes: 2 additions & 2 deletions Security/src/Test-ProxyLogon.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ begin {
[Void]$allResults.FileList.Add( $files[$i] )

Import-Csv -Path $files[$i] -ErrorAction SilentlyContinue |
Where-Object { $_.AnchorMailbox -Like 'ServerInfo~*/*' -and $_.AnchorMailbox -notlike 'ServerInfo~*/autodiscover*' -and $_.AnchorMailbox -notlike 'ServerInfo~localhost*/*' } |
Where-Object { $_.AnchorMailbox -like 'ServerInfo~*/*' -and $_.AnchorMailbox -notlike 'ServerInfo~*/autodiscover*' -and $_.AnchorMailbox -notlike 'ServerInfo~localhost*/*' } |
Select-Object -Property $outProps |
ForEach-Object {
[Void]$allResults.Hits.Add( $_ )
Expand Down Expand Up @@ -219,7 +219,7 @@ begin {

if ((Get-ChildItem $files[$i] -ErrorAction SilentlyContinue | Select-String -Pattern "ServerInfo~").Count -gt 0) {

$hits = @(Import-Csv -Path $files[$i] -ErrorAction SilentlyContinue | Where-Object { $_.AnchorMailbox -Like 'ServerInfo~*/*Reset*VirtualDirectory#' -and $_.HttpStatus -eq 200 } |
$hits = @(Import-Csv -Path $files[$i] -ErrorAction SilentlyContinue | Where-Object { $_.AnchorMailbox -like 'ServerInfo~*/*Reset*VirtualDirectory#' -and $_.HttpStatus -eq 200 } |
Select-Object -Property $outProps)
if ($hits.Count -gt 0) {
$hits | ForEach-Object {
Expand Down

0 comments on commit a6be221

Please sign in to comment.