forked from ScoopInstaller/Scoop
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Pending] Finally we add the code linting and its tests! (ScoopInstal…
…ler#2108) * Lint: PSPossibleIncorrectComparisonWithNull * Lint: PSUseLiteralInitializerForHashtable * Lint: PSUseBOMForUnicodeEncodedFile * Lint: PSUseApprovedVerbs * Lint: PSAvoidGlobalVars * Lint: PSAvoidUsingEmptyCatchBlock * Lint: PSUseShouldProcessForStateChangingFunctions * Lint helper: Add PSScriptAnalyzer integration for vscode * Fix lint: PSUseBOMForUnicodeEncodedFile * Tests: ignore previous TestResults.xml * Tests: add PowerShell script linting into tests! * Add PSScriptAnalyzer into appveyor ci * Update Scoop-Linting.Tests.ps1
- Loading branch information
Showing
20 changed files
with
131 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ scoop.sublime-workspace | |
test/installer/tmp/* | ||
test/tmp/* | ||
*~ | ||
TestResults.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// Configure PSScriptAnalyzer settings | ||
{ | ||
"powershell.scriptAnalysis.settingsPath": "PSScriptAnalyzerSettings.psd1" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# The PowerShell Script Analyzer will generate a warning | ||
# diagnostic record for this file due to a bug - | ||
# https://github.com/PowerShell/PSScriptAnalyzer/issues/472 | ||
@{ | ||
# Only diagnostic records of the specified severity will be generated. | ||
# Uncomment the following line if you only want Errors and Warnings but | ||
# not Information diagnostic records. | ||
Severity = @('Error','Warning') | ||
|
||
# Analyze **only** the following rules. Use IncludeRules when you want | ||
# to invoke only a small subset of the defualt rules. | ||
# IncludeRules = @('PSAvoidDefaultValueSwitchParameter', | ||
# 'PSMisleadingBacktick', | ||
# 'PSMissingModuleManifestField', | ||
# 'PSReservedCmdletChar', | ||
# 'PSReservedParams', | ||
# 'PSShouldProcess', | ||
# 'PSUseApprovedVerbs', | ||
# 'PSAvoidUsingCmdletAliases', | ||
# 'PSUseDeclaredVarsMoreThanAssignments') | ||
|
||
# Do not analyze the following rules. Use ExcludeRules when you have | ||
# commented out the IncludeRules settings above and want to include all | ||
# the default rules except for those you exclude below. | ||
# Note: if a rule is in both IncludeRules and ExcludeRules, the rule | ||
# will be excluded. | ||
ExcludeRules = @( | ||
# Currently Scoop widely uses Write-Host to output colored text. | ||
'PSAvoidUsingWriteHost', | ||
# Temporarily allow uses of Invoke-Expression, | ||
# this command is used by some core functions and hard to be removed. | ||
'PSAvoidUsingInvokeExpression', | ||
# PSUseDeclaredVarsMoreThanAssignments doesn't currently work due to: | ||
# https://github.com/PowerShell/PSScriptAnalyzer/issues/636 | ||
'PSUseDeclaredVarsMoreThanAssignments' | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
$repo_dir = (Get-Item $MyInvocation.MyCommand.Path).directory.parent.FullName | ||
|
||
Describe "PSScriptAnalyzer" { | ||
$scoop_modules = Get-ChildItem $repo_dir -Recurse -Include *.psd1, *.psm1, *.ps1 | ||
$scoop_modules = $scoop_modules | Where-Object { $_.DirectoryName -notlike '*\supporting*' -and $_.DirectoryName -notlike '*\test*' } | ||
$scoop_modules = $scoop_modules | Select-Object -ExpandProperty Directory -Unique | ||
|
||
Context "Checking ScriptAnalyzer" { | ||
It "Invoke-ScriptAnalyzer Cmdlet should exist" { | ||
{ Get-Command Invoke-ScriptAnalyzer -ErrorAction Stop } | Should Not Throw | ||
} | ||
It "PSScriptAnalyzerSettings.ps1 should exist" { | ||
Test-Path "$repo_dir\PSScriptAnalyzerSettings.psd1" | Should Be $true | ||
} | ||
It "There should be files to test" { | ||
$scoop_modules.Count | Should Not Be 0 | ||
} | ||
} | ||
|
||
$linting_settings = Get-Item -Path "$repo_dir\PSScriptAnalyzerSettings.psd1" | ||
|
||
Context "Linting all *.psd1, *.psm1 and *.ps1 files" { | ||
foreach($directory in $scoop_modules) { | ||
$analysis = Invoke-ScriptAnalyzer -Path $directory.FullName -Settings $linting_settings.FullName | ||
It "Should pass: $directory" { | ||
$analysis.Count | Should Be 0 | ||
} | ||
if($analysis) { | ||
foreach($result in $analysis) { | ||
switch -wildCard ($result.ScriptName) { | ||
'*.psm1' { $type = 'Module' } | ||
'*.ps1' { $type = 'Script' } | ||
'*.psd1' { $type = 'Manifest' } | ||
} | ||
Write-Host -f Yellow " [*] $($result.Severity): $($result.Message)" | ||
Write-Host -f Yellow " $($result.RuleName) in $type`: $directory\$($result.ScriptName):$($result.Line)" | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters