Add PSCustomUseLiteralPath and update PSSA for pslint (#54080)

This commit is contained in:
Jordan Borean 2019-03-20 16:26:12 +10:00 committed by GitHub
parent ac6ff8fe05
commit 0bf14d61d0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 140 additions and 16 deletions

View file

@ -76,18 +76,23 @@ class PslintTest(SanitySingleVersion):
if not find_executable('pwsh', required='warning'):
return SanitySkipped(self.name)
cmd = ['test/sanity/pslint/pslint.ps1'] + paths
# Make sure requirements are installed before running sanity checks
cmds = [
['test/runner/requirements/sanity.ps1'],
['test/sanity/pslint/pslint.ps1'] + paths
]
try:
stdout, stderr = run_command(args, cmd, capture=True)
status = 0
except SubprocessError as ex:
stdout = ex.stdout
stderr = ex.stderr
status = ex.status
for cmd in cmds:
try:
stdout, stderr = run_command(args, cmd, capture=True)
status = 0
except SubprocessError as ex:
stdout = ex.stdout
stderr = ex.stderr
status = ex.status
if stderr:
raise SubprocessError(cmd=cmd, status=status, stderr=stderr, stdout=stdout)
if stderr:
raise SubprocessError(cmd=cmd, status=status, stderr=stderr, stdout=stdout)
if args.explain:
return SanitySuccess(self.name)

View file

@ -5,4 +5,7 @@ Set-StrictMode -Version 2.0
$ErrorActionPreference = "Stop"
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
Install-Module -Name PSScriptAnalyzer
Install-Module -Name PSScriptAnalyzer -RequiredVersion 1.17.1
# Installed the PSCustomUseLiteralPath rule
Install-Module -Name PSSA-PSCustomUseLiteralPath -RequiredVersion 0.1.1

View file

@ -5,5 +5,6 @@ paramiko
ntlm-auth
requests-ntlm
requests-credssp
pypsrp
pywinrm[credssp]
pyyaml

View file

@ -1,80 +1,186 @@
examples/scripts/ConfigureRemotingForAnsible.ps1 PSAvoidTrailingWhitespace
examples/scripts/ConfigureRemotingForAnsible.ps1 PSAvoidUsingCmdletAliases
examples/scripts/ConfigureRemotingForAnsible.ps1 PSCustomUseLiteralPath
examples/scripts/upgrade_to_ps3.ps1 PSAvoidTrailingWhitespace
examples/scripts/upgrade_to_ps3.ps1 PSAvoidUsingWriteHost
examples/scripts/upgrade_to_ps3.ps1 PSCustomUseLiteralPath
examples/scripts/upgrade_to_ps3.ps1 PSUseApprovedVerbs
lib/ansible/executor/powershell/async_watchdog.ps1 PSCustomUseLiteralPath
lib/ansible/executor/powershell/async_wrapper.ps1 PSCustomUseLiteralPath
lib/ansible/executor/powershell/exec_wrapper.ps1 PSCustomUseLiteralPath
lib/ansible/module_utils/powershell/Ansible.ModuleUtils.ArgvParser.psm1 PSUseApprovedVerbs
lib/ansible/module_utils/powershell/Ansible.ModuleUtils.CamelConversion.psm1 PSAvoidTrailingWhitespace
lib/ansible/module_utils/powershell/Ansible.ModuleUtils.CommandUtil.psm1 PSProvideCommentHelp # need to agree on best format for comment location
lib/ansible/module_utils/powershell/Ansible.ModuleUtils.CommandUtil.psm1 PSUseApprovedVerbs
lib/ansible/module_utils/powershell/Ansible.ModuleUtils.FileUtil.psm1 PSCustomUseLiteralPath
lib/ansible/module_utils/powershell/Ansible.ModuleUtils.FileUtil.psm1 PSProvideCommentHelp
lib/ansible/module_utils/powershell/Ansible.ModuleUtils.Legacy.psm1 PSAvoidUsingWMICmdlet
lib/ansible/module_utils/powershell/Ansible.ModuleUtils.Legacy.psm1 PSCustomUseLiteralPath
lib/ansible/module_utils/powershell/Ansible.ModuleUtils.Legacy.psm1 PSUseApprovedVerbs
lib/ansible/module_utils/powershell/Ansible.ModuleUtils.LinkUtil.psm1 PSAvoidTrailingWhitespace
lib/ansible/module_utils/powershell/Ansible.ModuleUtils.LinkUtil.psm1 PSUseApprovedVerbs
lib/ansible/module_utils/powershell/Ansible.ModuleUtils.SID.psm1 PSAvoidTrailingWhitespace
lib/ansible/modules/windows/async_status.ps1 PSCustomUseLiteralPath
lib/ansible/modules/windows/setup.ps1 PSAvoidTrailingWhitespace
lib/ansible/modules/windows/setup.ps1 PSAvoidUsingCmdletAliases
lib/ansible/modules/windows/setup.ps1 PSAvoidUsingEmptyCatchBlock
lib/ansible/modules/windows/setup.ps1 PSCustomUseLiteralPath
lib/ansible/modules/windows/setup.ps1 PSUseDeclaredVarsMoreThanAssignments
lib/ansible/modules/windows/win_acl_inheritance.ps1 PSAvoidTrailingWhitespace
lib/ansible/modules/windows/win_audit_rule.ps1 PSCustomUseLiteralPath
lib/ansible/modules/windows/win_chocolatey.ps1 PSCustomUseLiteralPath
lib/ansible/modules/windows/win_chocolatey_config.ps1 PSCustomUseLiteralPath
lib/ansible/modules/windows/win_chocolatey_facts.ps1 PSAvoidTrailingWhitespace
lib/ansible/modules/windows/win_chocolatey_facts.ps1 PSCustomUseLiteralPath
lib/ansible/modules/windows/win_chocolatey_source.ps1 PSCustomUseLiteralPath
lib/ansible/modules/windows/win_copy.ps1 PSUseApprovedVerbs
lib/ansible/modules/windows/win_copy.ps1 PSUseDeclaredVarsMoreThanAssignments
lib/ansible/modules/windows/win_credential.ps1 PSAvoidTrailingWhitespace
lib/ansible/modules/windows/win_credential.ps1 PSCustomUseLiteralPath
lib/ansible/modules/windows/win_credential.ps1 PSUsePSCredentialType # The Credential parameter is a custom .NET type
lib/ansible/modules/windows/win_disk_facts.ps1 PSUseDeclaredVarsMoreThanAssignments
lib/ansible/modules/windows/win_dns_client.ps1 PSAvoidGlobalVars
lib/ansible/modules/windows/win_dns_client.ps1 PSAvoidTrailingWhitespace
lib/ansible/modules/windows/win_dns_client.ps1 PSAvoidUsingCmdletAliases
lib/ansible/modules/windows/win_dns_client.ps1 PSAvoidUsingWMICmdlet
lib/ansible/modules/windows/win_dns_client.ps1 PSCustomUseLiteralPath
lib/ansible/modules/windows/win_dns_client.ps1 PSUseApprovedVerbs
lib/ansible/modules/windows/win_dns_client.ps1 PSUseDeclaredVarsMoreThanAssignments
lib/ansible/modules/windows/win_domain.ps1 PSAvoidUsingEmptyCatchBlock
lib/ansible/modules/windows/win_domain.ps1 PSUseApprovedVerbs
lib/ansible/modules/windows/win_domain.ps1 PSUseDeclaredVarsMoreThanAssignments
lib/ansible/modules/windows/win_domain_controller.ps1 PSAvoidGlobalVars
lib/ansible/modules/windows/win_domain_controller.ps1 PSAvoidTrailingWhitespace
lib/ansible/modules/windows/win_domain_controller.ps1 PSAvoidUsingWMICmdlet
lib/ansible/modules/windows/win_domain_controller.ps1 PSCustomUseLiteralPath
lib/ansible/modules/windows/win_domain_controller.ps1 PSUseApprovedVerbs
lib/ansible/modules/windows/win_domain_controller.ps1 PSUseDeclaredVarsMoreThanAssignments
lib/ansible/modules/windows/win_domain_group.ps1 PSAvoidTrailingWhitespace
lib/ansible/modules/windows/win_domain_membership.ps1 PSAvoidGlobalVars
lib/ansible/modules/windows/win_domain_membership.ps1 PSAvoidTrailingWhitespace
lib/ansible/modules/windows/win_domain_membership.ps1 PSAvoidUsingWMICmdlet
lib/ansible/modules/windows/win_domain_membership.ps1 PSCustomUseLiteralPath
lib/ansible/modules/windows/win_domain_membership.ps1 PSUseApprovedVerbs
lib/ansible/modules/windows/win_domain_membership.ps1 PSUseDeclaredVarsMoreThanAssignments
lib/ansible/modules/windows/win_domain_user.ps1 PSAvoidTrailingWhitespace
lib/ansible/modules/windows/win_dotnet_ngen.ps1 PSCustomUseLiteralPath
lib/ansible/modules/windows/win_dsc.ps1 PSAvoidUsingEmptyCatchBlock
lib/ansible/modules/windows/win_eventlog.ps1 PSUseDeclaredVarsMoreThanAssignments
lib/ansible/modules/windows/win_dsc.ps1 PSCustomUseLiteralPath
lib/ansible/modules/windows/win_eventlog.ps1 PSCustomUseLiteralPath
lib/ansible/modules/windows/win_feature.ps1 PSCustomUseLiteralPath
lib/ansible/modules/windows/win_file_version.ps1 PSCustomUseLiteralPath
lib/ansible/modules/windows/win_find.ps1 PSAvoidTrailingWhitespace
lib/ansible/modules/windows/win_find.ps1 PSAvoidUsingEmptyCatchBlock
lib/ansible/modules/windows/win_find.ps1 PSAvoidUsingWMICmdlet
lib/ansible/modules/windows/win_firewall_rule.ps1 PSAvoidUsingCmdletAliases
lib/ansible/modules/windows/win_firewall_rule.ps1 PSUseApprovedVerbs
lib/ansible/modules/windows/win_get_url.ps1 PSUsePSCredentialType # Credential param can take a base64 encoded string as well as a PSCredential
lib/ansible/modules/windows/win_hotfix.ps1 PSAvoidTrailingWhitespace
lib/ansible/modules/windows/win_hotfix.ps1 PSCustomUseLiteralPath
lib/ansible/modules/windows/win_hotfix.ps1 PSUseApprovedVerbs
lib/ansible/modules/windows/win_iis_virtualdirectory.ps1 PSCustomUseLiteralPath
lib/ansible/modules/windows/win_iis_webapplication.ps1 PSCustomUseLiteralPath
lib/ansible/modules/windows/win_iis_webapppool.ps1 PSAvoidTrailingWhitespace
lib/ansible/modules/windows/win_iis_webapppool.ps1 PSCustomUseLiteralPath
lib/ansible/modules/windows/win_iis_webbinding.ps1 PSAvoidTrailingWhitespace
lib/ansible/modules/windows/win_iis_webbinding.ps1 PSCustomUseLiteralPath
lib/ansible/modules/windows/win_iis_webbinding.ps1 PSUseApprovedVerbs
lib/ansible/modules/windows/win_iis_website.ps1 PSAvoidUsingCmdletAliases
lib/ansible/modules/windows/win_iis_website.ps1 PSAvoidUsingPositionalParameters
lib/ansible/modules/windows/win_iis_website.ps1 PSCustomUseLiteralPath
lib/ansible/modules/windows/win_iis_website.ps1 PSUseDeclaredVarsMoreThanAssignments
lib/ansible/modules/windows/win_lineinfile.ps1 PSCustomUseLiteralPath
lib/ansible/modules/windows/win_mapped_drive.ps1 PSCustomUseLiteralPath
lib/ansible/modules/windows/win_msg.ps1 PSAvoidTrailingWhitespace
lib/ansible/modules/windows/win_nssm.ps1 PSAvoidUsingCmdletAliases
lib/ansible/modules/windows/win_nssm.ps1 PSCustomUseLiteralPath
lib/ansible/modules/windows/win_nssm.ps1 PSUseApprovedVerbs
lib/ansible/modules/windows/win_nssm.ps1 PSUseDeclaredVarsMoreThanAssignments
lib/ansible/modules/windows/win_package.ps1 PSAvoidTrailingWhitespace
lib/ansible/modules/windows/win_package.ps1 PSCustomUseLiteralPath
lib/ansible/modules/windows/win_package.ps1 PSUseApprovedVerbs
lib/ansible/modules/windows/win_package.ps1 PSUsePSCredentialType
lib/ansible/modules/windows/win_pagefile.ps1 PSAvoidTrailingWhitespace
lib/ansible/modules/windows/win_pagefile.ps1 PSAvoidUsingCmdletAliases
lib/ansible/modules/windows/win_pagefile.ps1 PSAvoidUsingPositionalParameters
lib/ansible/modules/windows/win_pagefile.ps1 PSAvoidUsingWMICmdlet
lib/ansible/modules/windows/win_pagefile.ps1 PSCustomUseLiteralPath
lib/ansible/modules/windows/win_pagefile.ps1 PSUseDeclaredVarsMoreThanAssignments
lib/ansible/modules/windows/win_pagefile.ps1 PSUseSupportsShouldProcess
lib/ansible/modules/windows/win_pester.ps1 PSCustomUseLiteralPath
lib/ansible/modules/windows/win_product_facts.ps1 PSAvoidTrailingWhitespace
lib/ansible/modules/windows/win_product_facts.ps1 PSCustomUseLiteralPath
lib/ansible/modules/windows/win_rabbitmq_plugin.ps1 PSAvoidUsingCmdletAliases
lib/ansible/modules/windows/win_rabbitmq_plugin.ps1 PSAvoidUsingInvokeExpression
lib/ansible/modules/windows/win_rabbitmq_plugin.ps1 PSCustomUseLiteralPath
lib/ansible/modules/windows/win_rds_cap.ps1 PSAvoidTrailingWhitespace
lib/ansible/modules/windows/win_rds_cap.ps1 PSCustomUseLiteralPath
lib/ansible/modules/windows/win_rds_rap.ps1 PSAvoidTrailingWhitespace
lib/ansible/modules/windows/win_rds_rap.ps1 PSCustomUseLiteralPath
lib/ansible/modules/windows/win_rds_settings.ps1 PSCustomUseLiteralPath
lib/ansible/modules/windows/win_regedit.ps1 PSCustomUseLiteralPath
lib/ansible/modules/windows/win_region.ps1 PSAvoidUsingEmptyCatchBlock
lib/ansible/modules/windows/win_region.ps1 PSCustomUseLiteralPath
lib/ansible/modules/windows/win_regmerge.ps1 PSAvoidTrailingWhitespace
lib/ansible/modules/windows/win_regmerge.ps1 PSCustomUseLiteralPath
lib/ansible/modules/windows/win_robocopy.ps1 PSCustomUseLiteralPath
lib/ansible/modules/windows/win_route.ps1 PSAvoidTrailingWhitespace
lib/ansible/modules/windows/win_route.ps1 PSAvoidUsingCmdletAliases
lib/ansible/modules/windows/win_scheduled_task.ps1 PSAvoidTrailingWhitespace
lib/ansible/modules/windows/win_scheduled_task_stat.ps1 PSAvoidTrailingWhitespace
lib/ansible/modules/windows/win_scheduled_task_stat.ps1 PSAvoidUsingCmdletAliases
lib/ansible/modules/windows/win_scheduled_task_stat.ps1 PSUseDeclaredVarsMoreThanAssignments
lib/ansible/modules/windows/win_security_policy.ps1 PSAvoidTrailingWhitespace
lib/ansible/modules/windows/win_security_policy.ps1 PSCustomUseLiteralPath
lib/ansible/modules/windows/win_security_policy.ps1 PSUseApprovedVerbs
lib/ansible/modules/windows/win_security_policy.ps1 PSUseDeclaredVarsMoreThanAssignments
lib/ansible/modules/windows/win_service.ps1 PSAvoidTrailingWhitespace
lib/ansible/modules/windows/win_share.ps1 PSCustomUseLiteralPath
lib/ansible/modules/windows/win_shell.ps1 PSAvoidTrailingWhitespace
lib/ansible/modules/windows/win_shell.ps1 PSAvoidUsingCmdletAliases
lib/ansible/modules/windows/win_shell.ps1 PSUseApprovedVerbs
lib/ansible/modules/windows/win_shortcut.ps1 PSCustomUseLiteralPath
lib/ansible/modules/windows/win_snmp.ps1 PSCustomUseLiteralPath
lib/ansible/modules/windows/win_stat.ps1 PSAvoidTrailingWhitespace
lib/ansible/modules/windows/win_say.ps1 PSAvoidTrailingWhitespace
lib/ansible/modules/windows/win_say.ps1 PSCustomUseLiteralPath
lib/ansible/modules/windows/win_tempfile.ps1 PSAvoidAssignmentToAutomaticVariable
lib/ansible/modules/windows/win_toast.ps1 PSAvoidTrailingWhitespace
lib/ansible/modules/windows/win_unzip.ps1 PSAvoidUsingCmdletAliases
lib/ansible/modules/windows/win_unzip.ps1 PSCustomUseLiteralPath
lib/ansible/modules/windows/win_unzip.ps1 PSUseApprovedVerbs
lib/ansible/modules/windows/win_updates.ps1 PSCustomUseLiteralPath
lib/ansible/modules/windows/win_uri.ps1 PSAvoidUsingEmptyCatchBlock
lib/ansible/modules/windows/win_user.ps1 PSAvoidTrailingWhitespace
lib/ansible/modules/windows/win_user.ps1 PSAvoidUsingCmdletAliases
lib/ansible/modules/windows/win_user_profile.ps1 PSCustomUseLiteralPath
lib/ansible/modules/windows/win_user_right.ps1 PSAvoidTrailingWhitespace
lib/ansible/modules/windows/win_wait_for.ps1 PSAvoidUsingEmptyCatchBlock
lib/ansible/modules/windows/win_wait_for.ps1 PSCustomUseLiteralPath
lib/ansible/modules/windows/win_webpicmd.ps1 PSAvoidUsingInvokeExpression
lib/ansible/modules/windows/win_xml.ps1 PSCustomUseLiteralPath
test/integration/targets/win_audit_rule/library/test_get_audit_rule.ps1 PSAvoidUsingCmdletAliases
test/integration/targets/win_audit_rule/library/test_get_audit_rule.ps1 PSCustomUseLiteralPath
test/integration/targets/win_chocolatey/files/tools/chocolateyUninstall.ps1 PSCustomUseLiteralPath
test/integration/targets/win_chocolatey_source/library/choco_source.ps1 PSCustomUseLiteralPath
test/integration/targets/win_csharp_utils/library/ansible_basic_tests.ps1 PSAvoidTrailingWhitespace
test/integration/targets/win_csharp_utils/library/ansible_basic_tests.ps1 PSCustomUseLiteralPath
test/integration/targets/win_csharp_utils/library/ansible_basic_tests.ps1 PSUseDeclaredVarsMoreThanAssignments # test setup requires vars to be set globally and not referenced in the same scope
test/integration/targets/win_csharp_utils/library/ansible_become_tests.ps1 PSCustomUseLiteralPath
test/integration/targets/win_exec_wrapper/library/test_fail.ps1 PSCustomUseLiteralPath
test/integration/targets/win_iis_webbinding/library/test_get_webbindings.ps1 PSUseApprovedVerbs
test/integration/targets/win_module_utils/library/argv_parser_test.ps1 PSAvoidTrailingWhitespace
test/integration/targets/win_module_utils/library/argv_parser_test.ps1 PSUseApprovedVerbs
test/integration/targets/win_module_utils/library/backup_file_test.ps1 PSCustomUseLiteralPath
test/integration/targets/win_module_utils/library/camel_conversion_test.ps1 PSUseDeclaredVarsMoreThanAssignments
test/integration/targets/win_module_utils/library/command_util_test.ps1 PSCustomUseLiteralPath
test/integration/targets/win_psmodule/files/setup_modules.ps1 PSCustomUseLiteralPath
test/integration/targets/win_ping/library/win_ping_strict_mode_error.ps1 PSUseDeclaredVarsMoreThanAssignments
test/integration/targets/win_reboot/templates/post_reboot.ps1 PSCustomUseLiteralPath
test/integration/targets/win_script/files/test_script.ps1 PSAvoidUsingWriteHost
test/integration/targets/win_script/files/test_script_creates_file.ps1 PSAvoidUsingCmdletAliases
test/integration/targets/win_script/files/test_script_removes_file.ps1 PSCustomUseLiteralPath
test/integration/targets/win_script/files/test_script_with_args.ps1 PSAvoidUsingWriteHost
test/integration/targets/win_script/files/test_script_with_splatting.ps1 PSAvoidUsingWriteHost
test/integration/targets/win_csharp_utils/library/ansible_basic_tests.ps1 PSUseDeclaredVarsMoreThanAssignments # test setup requires vars to be set globally and not referenced in the same scope
test/integration/targets/win_stat/library/test_symlink_file.ps1 PSCustomUseLiteralPath
test/integration/targets/win_user_right/library/test_get_right.ps1 PSCustomUseLiteralPath
test/runner/setup/windows-httptester.ps1 PSCustomUseLiteralPath

View file

@ -1,11 +1,20 @@
#!/usr/bin/env pwsh
#Requires -Version 6
#Requires -Modules PSScriptAnalyzer
#Requires -Modules PSScriptAnalyzer, PSSA-PSCustomUseLiteralPath
Set-StrictMode -Version 2.0
$ErrorActionPreference = "Stop"
$WarningPreference = "Stop"
$LiteralPathRule = Import-Module -Name PSSA-PSCustomUseLiteralPath -PassThru
$LiteralPathRulePath = Join-Path -Path $LiteralPathRule.ModuleBase -ChildPath $LiteralPathRule.RootModule
$PSSAParams = @{
CustomRulePath = @($LiteralPathRulePath)
IncludeDefaultRules = $true
Setting = (Join-Path -Path $PSScriptRoot -ChildPath "settings.psd1")
}
$Results = @()
ForEach ($Path in $Args) {
@ -13,7 +22,7 @@ ForEach ($Path in $Args) {
Do {
Try {
$Results += Invoke-ScriptAnalyzer -Path $Path -Setting $PSScriptRoot/settings.psd1 3> $null
$Results += Invoke-ScriptAnalyzer -Path $Path @PSSAParams 3> $null
$Retries = 0
}
Catch {