-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConfirm-TextFormat.ps1
67 lines (62 loc) · 1.28 KB
/
Confirm-TextFormat.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
[CmdletBinding()]
Param()
End
{
$txt = @(
'.git',
'.gitmodules',
'.gitattributes',
'.gitignore',
'.md',
'.editorconfig',
'.sln',
'.csproj',
'.ps1',
'.cs',
'.tt',
'.json',
'.ps1xml'
);
$bin = @('.user', '.tmp');
$dir = @('.git', '.vs', 'bin', 'obj', 'deps');
$recursiveCheck = {
If ($_.PSIsContainer)
{
If ($_.Name.ToLowerInvariant() -in $dir)
{
Write-Verbose "Ignored folder: $($_.FullName)";
Return;
}
Get-ChildItem -LiteralPath $_.FullName -Force |
ForEach-Object $recursiveCheck;
Return;
}
$ext = $_.Extension.ToLowerInvariant();
If ($ext -in $txt)
{
$content = [System.IO.File]::ReadAllBytes($_.FullName);
If ($content.Count -ge 3 -and
$content[0] -eq 0xEF -and
$content[1] -eq 0xBB -and
$content[2] -eq 0xBF)
{
Write-Warning " BOM in UTF8: $($_.FullName)";
}
ElseIf (0 -in $content)
{
Write-Warning "\0 or UTF16/32: $($_.FullName)";
}
ElseIf (13 -in $content)
{
Write-Warning " with CR (\r): $($_.FullName)";
}
}
ElseIf ($ext -notin $bin)
{
Write-Warning " Unknown type: $($_.FullName)";
}
};
Get-ChildItem -LiteralPath $PSScriptRoot -Force |
ForEach-Object $recursiveCheck;
Write-Verbose 'Confirm-TextFormat.ps1 completed.';
}