added new linter

This commit is contained in:
Darii Nurgaleev
2020-10-13 21:32:58 +07:00
parent be8eba42a1
commit 955aec5bef

View File

@@ -9,17 +9,16 @@ function Validate-Scripts {
) )
$ScriptWithoutShebangLine = @() $ScriptWithoutShebangLine = @()
Get-ChildItem $path -Recurse -File -Filter "*.sh" | ForEach-Object { Get-ChildItem $path -Recurse -File -Filter "*.sh" | ForEach-Object {
$shebangLine = Get-Content -Path $($_.FullName)| Select-Object -First 1 $relativePath = Resolve-Path $_.FullName -Relative
$shebangLine = Get-Content -Path $.FullName | Select-Object -First 1
if ($shebangLine -eq $ExpectedShebang) { if ($shebangLine -eq $ExpectedShebang) {
Write-Host "[+] '$($_.FullName)'" Write-Host "[+] '$relativePath'"
} }
else { else {
Write-Host "[-] '$($_.FullName)'" Write-Host "[-] 'relativePath'"
$ScriptWithoutShebangLine += $($_.FullName) $ScriptWithoutShebangLine += $relativePath
} }
} }
return $ScriptWithoutShebangLine
}
$PathUbuntu = "./images/linux/scripts" $PathUbuntu = "./images/linux/scripts"
$PathMacOS = "./images/macos/provision" $PathMacOS = "./images/macos/provision"
@@ -29,11 +28,11 @@ $ScriptsWithBrokenShebang = @()
$ScriptsWithBrokenShebang += Validate-Scripts -Path $PathUbuntu -ExpectedShebang $PatternUbuntu $ScriptsWithBrokenShebang += Validate-Scripts -Path $PathUbuntu -ExpectedShebang $PatternUbuntu
$ScriptsWithBrokenShebang += Validate-Scripts -Path $PathMacOS -ExpectedShebang $PatternMacOS $ScriptsWithBrokenShebang += Validate-Scripts -Path $PathMacOS -ExpectedShebang $PatternMacOS
if ($ScriptsWithBrokenShebang.Length -gt 0) { if ($ScriptsWithBrokenShebang.Length -gt 0) {
Write-Host "The following scripts have incorrect shebang:" Write-Host "`n`n`n##[error] The following scripts have incorrect shebang:"
$ScriptsWithBrokenShebang | ForEach-Object { $ScriptsWithBrokenShebang | ForEach-Object {
Write-Host "##[error] - '$_'" Write-Host "##[error] '$_'"
} }
Write-Host "##[error] Expected shebang for scripts in 'images/linux' folder is '$PatternUbuntu'" Write-Host "`n`n##[error] Expected shebang for scripts in 'images/linux' folder is '$PatternUbuntu'"
Write-Host "##[error] Expected shebang for scripts in 'images/macos' folder is '$PatternMacOS'" Write-Host "##[error] Expected shebang for scripts in 'images/macos' folder is '$PatternMacOS'"
exit 1 exit 1
else { else {