Skip to content

Commit 47f1080

Browse files
authored
fix(): Fix linter warnings (#28)
Update `Invoke-Linter.ps1` to use a file for settings options. Fix all the PSAvoidUsingWriteHost issues by using `Write-Information` instead. Fix PSAvoidAssignmentToAutomaticVariable in `Install-FromMsi.ps1` by renaming a variable. Fix a PSAvoidTrailingWhitespace lint in the documentation for `Install-AhemFont.ps1`. Fix a PSAvoidDefaultValueForMandatoryParameter lint in `Invoke-CmakeBuild.ps1`. Fix a PSUseDeclaredVarsMoreThanAssignments lint in `Invoke-WebFileRequest.ps1`.
1 parent 4759b5e commit 47f1080

19 files changed

+84
-77
lines changed

Invoke-Linter.ps1

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,9 @@ foreach ($script in $psScripts) {
5151
$files++;
5252
$scriptPath = $script.FullName;
5353

54-
$records = Invoke-ScriptAnalyzer -Path $scriptPath `
55-
-Exclude PSUseSingularNouns,PSAvoidUsingInvokeExpression,PSUseShouldProcessForStateChangingFunctions `
56-
5754
Write-Information -MessageData ('Analyzing {0}' -f $scriptPath) -InformationAction Continue;
5855

56+
$records = Invoke-ScriptAnalyzer -Path $scriptPath -Settings (Join-Path $PSScriptRoot 'ScriptAnalyzerSettings.txt');
5957
if ($records) {
6058
foreach ($record in $records) {
6159
$issues++;

ScriptAnalyzerSettings.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@{
2+
Severity = @('Error','Warning','Information')
3+
IncludeRules = '*'
4+
ExcludeRules = @(
5+
'PSUseSingularNouns',
6+
'PSAvoidUsingInvokeExpression',
7+
'PSUseShouldProcessForStateChangingFunctions',
8+
'PSReviewUnusedParameter'
9+
)
10+
}

WebKitDev/Functions/Get-SourceCodeRelease.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,17 @@ function Get-SourceCodeRelease {
2525
[string]$destinationPath
2626
)
2727

28-
Write-Host ('Downloading {0} source code from {1} ...' -f $name,$url);
28+
Write-Information -MessageData ('Downloading {0} source code from {1} ...' -f $name,$url) -InformationAction Continue;
2929
$extension = [System.IO.Path]::GetExtension($url);
3030
$fileName = [System.IO.Path]::GetTempFileName() | Rename-Item -NewName { $_ -replace '.tmp$',$extension } -Passthru;
3131
Invoke-WebFileRequest -url $url -DestinationPath $fileName;
32-
Write-Host ('Downloaded {0} bytes' -f (Get-Item $fileName).Length);
32+
Write-Information -MessageData ('Downloaded {0} bytes' -f (Get-Item $fileName).Length) -InformationAction Continue;
3333

34-
Write-Host ('Unzipping {0} source code to {1} ...' -f $name,$destinationPath);
34+
Write-Information -MessageData ('Unzipping {0} source code to {1} ...' -f $name,$destinationPath) -InformationAction Continue;
3535
Expand-SourceArchive -Path $fileName -DestinationPath $destinationPath;
3636

3737
# Clean up temporary files
3838
Remove-Item $fileName -Force;
3939

40-
Write-Host 'Complete';
40+
Write-Information -MessageData 'Complete' -InformationAction Continue;
4141
}

WebKitDev/Functions/Install-AhemFont.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
.Description
1010
Downloads the AHEM font and installs it into the system fonts.
1111
12-
The AHEM font is used for layout tests in WebKit and is retrieved from
12+
The AHEM font is used for layout tests in WebKit and is retrieved from
1313
https://github.com/w3c/web-platform-tests.
1414
#>
1515
function Install-AhemFont {

WebKitDev/Functions/Install-Font.ps1

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ function Install-Font {
1818
$filename = [System.IO.Path]::GetFilename($url);
1919
$fontPath = Join-Path ([System.IO.Path]::GetTempPath()) $filename;
2020

21-
Write-Host ('Downloading {0} font from {1} ..' -f $name,$url);
21+
Write-Information -MessageData ('Downloading {0} font from {1} ..' -f $name,$url) -InformationAction Continue;
2222
Invoke-WebFileRequest -url $url -DestinationPath $fontPath;
23-
Write-Host ('Downloaded {0} bytes' -f (Get-Item $fontPath).Length);
23+
Write-Information -MessageData ('Downloaded {0} bytes' -f (Get-Item $fontPath).Length) -InformationAction Continue;
2424

2525
# Retrieve the font's name
2626
if (-not ('System.Drawing.Text.PrivateFontCollection' -as [type])) {
@@ -31,14 +31,14 @@ function Install-Font {
3131
$fontCollection.AddFontFile($fontPath);
3232
$fontName = $fontCollection.Families.Name;
3333

34-
Write-Host ('Installing font {0} from {1}' -f $fontName,$filename);
34+
Write-Information -MessageData ('Installing font {0} from {1}' -f $fontName,$filename) -InformationAction Continue;
3535

3636
# Move the file to the correct location
3737
$shell = New-Object -ComObject Shell.Application;
3838
$fonts = $shell.Namespace(0x14);
3939
$installationPath = $fonts.Self.Path;
4040

41-
Write-Host ('Installing at {0}' -f $installationPath);
41+
Write-Information -MessageData ('Installing at {0}' -f $installationPath) -InformationAction Continue;
4242

4343
$fonts.CopyHere($fontPath);
4444

@@ -57,12 +57,12 @@ function Install-Font {
5757
$registryTest = Get-ItemProperty -Path $registryPath -Name $registryKey -ErrorAction SilentlyContinue;
5858

5959
if (-not ($registryTest)) {
60-
Write-Host ('Writing {0} : {1} at ${2}' -f $registryKey,$filename,$registryPath);
60+
Write-Information -MessageData ('Writing {0} : {1} at ${2}' -f $registryKey,$filename,$registryPath) -InformationAction Continue;
6161
New-ItemProperty -Path $registryPath -Name $registryKey -PropertyType String -Value $filename | Out-Null;
6262
}
6363
else {
64-
Write-Host 'Font already present in registry';
65-
Write-Host ('Value {0} : {1} at ${2}' -f $registryKey,$registryTest.$registryKey,$registryPath);
64+
Write-Information -MessageData 'Font already present in registry' -InformationAction Continue;
65+
Write-Information -MessageData ('Value {0} : {1} at ${2}' -f $registryKey,$registryTest.$registryKey,$registryPath) -InformationAction Continue;
6666
}
6767

6868
# Verify that the font is present

WebKitDev/Functions/Install-FromArchive.ps1

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ function Install-FromArchive {
4343
$extension = [System.IO.Path]::GetExtension($url);
4444
$archivePath = Join-Path ([System.IO.Path]::GetTempPath()) ('{0}.{1}' -f $name,$extension);
4545

46-
Write-Host ('Downloading {0} package from {1} ..' -f $name,$url);
46+
Write-Information -MessageData ('Downloading {0} package from {1} ..' -f $name,$url) -InformationAction Continue;
4747
Invoke-WebFileRequest -url $url -DestinationPath $archivePath;
48-
Write-Host ('Downloaded {0} bytes' -f (Get-Item $archivePath).Length);
49-
Write-Host ('Unzipping {0} package ...' -f $name);
48+
Write-Information -MessageData ('Downloaded {0} bytes' -f (Get-Item $archivePath).Length) -InformationAction Continue;
49+
Write-Information -MessageData ('Unzipping {0} package ...' -f $name) -InformationAction Continue;
5050

5151
# Determine where to expand the archive to
5252
#
@@ -68,16 +68,16 @@ function Install-FromArchive {
6868
}
6969

7070
if (!$noVerify) {
71-
Write-Host ('Verifying {0} install ...' -f $name);
71+
Write-Information -MessageData ('Verifying {0} install ...' -f $name) -InformationAction Continue;
7272
$verifyCommand = (' {0} --version' -f $name);
73-
Write-Host $verifyCommand;
73+
Write-Information -MessageData $verifyCommand -InformationAction Continue;
7474
Invoke-Expression $verifyCommand;
7575
}
7676

77-
Write-Host ('Removing {0} package ...' -f $name);
77+
Write-Information -MessageData ('Removing {0} package ...' -f $name) -InformationAction Continue;
7878
Remove-Item $archivePath -Force;
7979

80-
Write-Host ('{0} install complete.' -f $name);
80+
Write-Information -MessageData ('{0} install complete.' -f $name) -InformationAction Continue;
8181
}
8282

8383
function Move-DirectoryStructure {

WebKitDev/Functions/Install-FromExe.ps1

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,28 +39,28 @@ function Install-FromExe {
3939

4040
$installerPath = Join-Path ([System.IO.Path]::GetTempPath()) ('{0}.exe' -f $name);
4141

42-
Write-Host ('Downloading {0} installer from {1} ..' -f $name,$url);
42+
Write-Information -MessageData ('Downloading {0} installer from {1} ..' -f $name,$url) -InformationAction Continue;
4343
Invoke-WebFileRequest -url $url -DestinationPath $installerPath;
44-
Write-Host ('Downloaded {0} bytes' -f (Get-Item $installerPath).Length);
44+
Write-Information -MessageData ('Downloaded {0} bytes' -f (Get-Item $installerPath).Length) -InformationAction Continue;
4545

46-
Write-Host ('Installing {0} ...' -f $name);
47-
Write-Host ('{0} {1}' -f $installerPath,($options -join ' '));
46+
Write-Information -MessageData ('Installing {0} ...' -f $name) -InformationAction Continue;
47+
Write-Information -MessageData ('{0} {1}' -f $installerPath,($options -join ' ')) -InformationAction Continue;
4848

4949
Start-Process $installerPath -Wait -ArgumentList $options;
5050

5151
# Update path
5252
Update-ScriptPath;
5353

5454
if (!$noVerify) {
55-
Write-Host ('Verifying {0} install ...' -f $name);
55+
Write-Information -MessageData ('Verifying {0} install ...' -f $name) -InformationAction Continue;
5656
$verifyCommand = (' {0} --version' -f $name);
57-
Write-Host $verifyCommand;
57+
Write-Information -MessageData $verifyCommand -InformationAction Continue;
5858
Invoke-Expression $verifyCommand;
5959
}
6060

61-
Write-Host ('Removing {0} installer ...' -f $name);
61+
Write-Information -MessageData ('Removing {0} installer ...' -f $name) -InformationAction Continue;
6262
Remove-Item $installerPath -Force;
6363
Remove-TempFiles;
6464

65-
Write-Host ('{0} install complete.' -f $name);
65+
Write-Information -MessageData ('{0} install complete.' -f $name) -InformationAction Continue;
6666
}

WebKitDev/Functions/Install-FromExeDownload.ps1

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,19 @@ function Install-FromExeDownload {
4545
}
4646

4747
$exePath = Join-Path $installationPath ('{0}.exe' -f $name);
48-
Write-Host ('Downloading {0} executable from {1} ...' -f $name,$url);
48+
Write-Information -MessageData ('Downloading {0} executable from {1} ...' -f $name,$url) -InformationAction Continue;
4949
Invoke-WebFileRequest -url $url -DestinationPath $exePath;
50-
Write-Host ('Downloaded {0} bytes' -f (Get-Item $exePath).Length);
50+
Write-Information -MessageData ('Downloaded {0} bytes' -f (Get-Item $exePath).Length) -InformationAction Continue;
5151

5252
# Update path
5353
Update-ScriptPath;
5454

5555
if (!$noVerify) {
56-
Write-Host ('Verifying {0} install ...' -f $name);
56+
Write-Information -MessageData ('Verifying {0} install ...' -f $name) -InformationAction Continue;
5757
$verifyCommand = (' {0} {1}' -f $name,(' ' -join $versionOptions));
58-
Write-Host $verifyCommand;
58+
Write-Information -MessageData $verifyCommand -InformationAction Continue;
5959
Invoke-Expression $verifyCommand;
6060
}
6161

62-
Write-Host ('{0} install complete.' -f $name);
62+
Write-Information -MessageData ('{0} install complete.' -f $name) -InformationAction Continue;
6363
}

WebKitDev/Functions/Install-FromMsi.ps1

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,31 +39,31 @@ function Install-FromMsi {
3939

4040
$installerPath = Join-Path ([System.IO.Path]::GetTempPath()) ('{0}.msi' -f $name);
4141

42-
Write-Host ('Downloading {0} installer from {1} ..' -f $name,$url);
42+
Write-Information -MessageData ('Downloading {0} installer from {1} ..' -f $name,$url) -InformationAction Continue;
4343
Invoke-WebFileRequest -url $url -DestinationPath $installerPath;
44-
Write-Host ('Downloaded {0} bytes' -f (Get-Item $installerPath).Length);
44+
Write-Information -MessageData ('Downloaded {0} bytes' -f (Get-Item $installerPath).Length) -InformationAction Continue;
4545

46-
$args = @('/i',$installerPath,'/quiet','/qn');
47-
$args += $options;
46+
$msiArgs = @('/i',$installerPath,'/quiet','/qn');
47+
$msiArgs += $options;
4848

49-
Write-Host ('Installing {0} ...' -f $name);
50-
Write-Host ('msiexec {0}' -f ($args -join ' '));
49+
Write-Information -MessageData ('Installing {0} ...' -f $name) -InformationAction Continue;
50+
Write-Information -MessageData ('msiexec {0}' -f ($msiArgs -join ' ')) -InformationAction Continue;
5151

52-
Start-Process msiexec -Wait -ArgumentList $args;
52+
Start-Process msiexec -Wait -ArgumentList $msiArgs;
5353

5454
# Update path
5555
Update-ScriptPath;
5656

5757
if (!$noVerify) {
58-
Write-Host ('Verifying {0} install ...' -f $name);
58+
Write-Information -MessageData ('Verifying {0} install ...' -f $name) -InformationAction Continue;
5959
$verifyCommand = (' {0} --version' -f $name);
60-
Write-Host $verifyCommand;
60+
Write-Information -MessageData $verifyCommand -InformationAction Continue;
6161
Invoke-Expression $verifyCommand;
6262
}
6363

64-
Write-Host ('Removing {0} installer ...' -f $name);
64+
Write-Information -MessageData ('Removing {0} installer ...' -f $name) -InformationAction Continue;
6565
Remove-Item $installerPath -Force;
6666
Remove-TempFiles;
6767

68-
Write-Host ('{0} install complete.' -f $name);
68+
Write-Information -MessageData ('{0} install complete.' -f $name) -InformationAction Continue;
6969
}

WebKitDev/Functions/Install-FromPacman.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function Install-FromPacman {
2929
[switch]$noVerify = $false
3030
)
3131
$bash = Get-Command 'bash' -ErrorAction 'SilentlyContinue';
32-
if ($bash -eq $null) {
32+
if ($null -eq $bash) {
3333
Write-Error ('Could not find bash to use to install {0}' -f $name);
3434
return
3535
}
@@ -42,17 +42,17 @@ function Install-FromPacman {
4242

4343
$bashCmd = ('pacman --noconfirm -S {0}' -f $name);
4444
$bashExpression = ("bash -lc '{0}'" -f $bashCmd);
45-
Write-Host $bashCmd;
45+
Write-Information -MessageData $bashCmd -InformationAction Continue;
4646
Invoke-Expression $bashExpression > $outFile;
4747
Get-Content $outFile;
4848

4949
if (!$noVerify) {
5050
if ($verifyExe -eq '') {
5151
$verifyExe = $name;
5252
}
53-
Write-Host ('Verifying {0} install ...' -f $name);
53+
Write-Information -MessageData ('Verifying {0} install ...' -f $name) -InformationAction Continue;
5454
$verifyCommand = (' {0} --version' -f $verifyExe);
55-
Write-Host $verifyCommand;
55+
Write-Information -MessageData $verifyCommand -InformationAction Continue;
5656
Invoke-Expression $verifyCommand > $outFile;
5757
Get-Content $outFile;
5858
}

0 commit comments

Comments
 (0)