forked from circuitdiagram/components
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlint.ps1
65 lines (53 loc) · 1.52 KB
/
lint.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
$script:exit = 0
Get-ChildItem . -Recurse -Filter *.xml | Foreach-Object {
$content = Get-Content $_.FullName
if ($content -match "\t") {
$script:exit = 1
Write-Output "[ERROR] Indented with tabs: $($_.FullName)"
}
}
[xml]$manifest = Get-Content "Build/manifest.xml"
$inputs = @()
foreach ($component in $manifest.components.component)
{
$inputs += [Tuple]::Create($component.input, $component.guid)
foreach ($configuration in $component.configuration)
{
if ($configuration.guid)
{
$inputs += [Tuple]::Create($configuration.input, $configuration.guid)
}
}
}
# Check for duplicate GUIDs
$duplicateGuids = $inputs | Group-Object -Property Item2 | Where-Object{$_.count -gt 1}
if ($duplicateGuids)
{
foreach ($duplicate in $duplicateGuids)
{
Write-Output "[ERROR] Duplicate GUID $($duplicate.name) found in:"
foreach ($input in $duplicate.Group)
{
Write-Output " $($input.Item1)"
}
Write-Output ""
}
$script:exit = 1
}
# Check file names
$invalidFileNames = $inputs | Where-Object{$_.Item1 -cnotmatch "^[a-z0-9\/\._]+$"}
if ($invalidFileNames)
{
Write-Output "File names must be lowercase alphanumeric with underscores."
foreach ($invalidFileName in $invalidFileNames)
{
Write-Output "[ERROR] Invalid file name: $($invalidFileName.Item1)"
}
Write-Output ""
$script:exit = 1
}
if (!$script:exit)
{
Write-Output "All components pass linting."
}
exit $script:exit