forked from Azure/azure-libraries-for-net
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CheckSourceFiles.ps1
45 lines (35 loc) · 1.48 KB
/
CheckSourceFiles.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
function Check-SyncMethods()
{
$retValue = $false
$TextPattern=[regex]'\/\/\/ <summary>*([\r\n][ \t]+\/\/\/.*)+[\r\n][ \t]+public static.*\)[\r\n][ \t]+\{[\r\n].*\.GetAwaiter\(\)\.GetResult\(\);[\r\n][ \t]+\}[\r\n][\r\n][ \t]+'
Get-ChildItem -Recurse -Filter "*.cs" | Where-Object { $_.Attributes -ne "Directory"} | ForEach-Object {
$text = (Get-Content $_.FullName) -join "`n"
if($text -match $TextPattern) {
Write-Host "[ERROR]: Found Sync Method in file: $($_.FullName)"
$retValue = $true
}
}
return $retValue;
}
function Check-LicenseHeader()
{
$retValue = $false
$licenseHeader = "// Copyright (c) Microsoft Corporation. All rights reserved."
$licenseHeaderAutoGen = "// <auto-generated> // Copyright (c) Microsoft Corporation. All rights reserved."
Get-ChildItem -Recurse -Filter "*.cs" | Where-Object { $_.Attributes -ne "Directory"} | ForEach-Object {
$text = (Get-Content $_.FullName -First 2) -join " "
if((-Not $text.StartsWith($licenseHeader)) -And (-Not $text.StartsWith($licenseHeaderAutoGen))) {
Write-Host "[ERROR]: File does not contain valid License Header: $($_.FullName)"
$retValue = $true
}
}
return $retValue;
}
$syncMethods = Check-SyncMethods
$licenseHeaders = Check-LicenseHeader
if($syncMethods -Or $licenseHeaders) {
Write-Host "[FAILED]: Style Check failed..."
exit(-1)
}
Write-Host "[SUCCESS]: Style Check passed..."
exit(0)