diff --git a/docs/docsite/rst/dev_guide/testing/sanity/pslint.rst b/docs/docsite/rst/dev_guide/testing/sanity/pslint.rst new file mode 100644 index 00000000000..0af0ab48922 --- /dev/null +++ b/docs/docsite/rst/dev_guide/testing/sanity/pslint.rst @@ -0,0 +1,4 @@ +Sanity Tests » pslint +===================== + +PowerShell static analysis for common programming errors using `PSScriptAnalyzer `_. diff --git a/test/runner/completion/docker.txt b/test/runner/completion/docker.txt index 698ae292f74..c667c3dcd43 100644 --- a/test/runner/completion/docker.txt +++ b/test/runner/completion/docker.txt @@ -1,6 +1,6 @@ centos6@sha256:41eb4b870ce400202945ccf572d45bf5f2f5ebb50e9dee244de73b9d0278db30 centos7@sha256:bd571611112cccefdaa951ea640177cbb77c8ee011f958d2562781d90594ea9c -default@sha256:aa1bd2899aa4c66b854d2f9b55b6ca33536dbffad3818082fe928b9d9da453df +default@sha256:b2206e28c3cf1e35cc7a4e3da13ee74eed15ceea162980ee5c97fa498d8cea46 fedora24@sha256:7b642c5d25b779a3a605fb8f70d9d92972f2004a5266fe364264809899fb1117 fedora25@sha256:828c71d87f1636f4d09916b8e2d87fc9a615d361a9afed22e8843ffb3d2729d2 opensuse42.2@sha256:3c59cd694fe69860d299a10afaa84f4e0b3db0c4139232431e9801e1a0775b0a diff --git a/test/runner/lib/sanity/pslint.py b/test/runner/lib/sanity/pslint.py new file mode 100644 index 00000000000..4a9655482a0 --- /dev/null +++ b/test/runner/lib/sanity/pslint.py @@ -0,0 +1,174 @@ +"""Sanity test using PSScriptAnalyzer.""" +from __future__ import absolute_import, print_function + +import collections +import json +import os +import re + +from lib.sanity import ( + SanitySingleVersion, + SanityMessage, + SanityFailure, + SanitySuccess, + SanitySkipped, +) + +from lib.util import ( + SubprocessError, + run_command, + find_executable, +) + +from lib.config import ( + SanityConfig, +) + +from lib.test import ( + calculate_confidence, + calculate_best_confidence, +) + +PSLINT_SKIP_PATH = 'test/sanity/pslint/skip.txt' +PSLINT_IGNORE_PATH = 'test/sanity/pslint/ignore.txt' + + +class PslintTest(SanitySingleVersion): + """Sanity test using PSScriptAnalyzer.""" + def test(self, args, targets): + """ + :type args: SanityConfig + :type targets: SanityTargets + :rtype: SanityResult + """ + with open(PSLINT_SKIP_PATH, 'r') as skip_fd: + skip_paths = skip_fd.read().splitlines() + + invalid_ignores = [] + + with open(PSLINT_IGNORE_PATH, 'r') as ignore_fd: + ignore_entries = ignore_fd.read().splitlines() + ignore = collections.defaultdict(dict) + line = 0 + + for ignore_entry in ignore_entries: + line += 1 + + if ' ' not in ignore_entry: + invalid_ignores.append((line, 'Invalid syntax')) + continue + + path, code = ignore_entry.split(' ', 1) + + if not os.path.exists(path): + invalid_ignores.append((line, 'Remove "%s" since it does not exist' % path)) + continue + + ignore[path][code] = line + + paths = sorted(i.path for i in targets.include if os.path.splitext(i.path)[1] in ('.ps1', '.psm1') and i.path not in skip_paths) + + if not paths: + return SanitySkipped(self.name) + + if not find_executable('pwsh', required='warning'): + return SanitySkipped(self.name) + + cmd = ['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 + + if stderr: + raise SubprocessError(cmd=cmd, status=status, stderr=stderr, stdout=stdout) + + if args.explain: + return SanitySuccess(self.name) + + severity = [ + 'Information', + 'Warning', + 'Error', + ] + + cwd = os.getcwd() + '/' + + # replace unicode smart quotes with ascii versions + stdout = re.sub(u'[\u2018\u2019]', "'", stdout) + stdout = re.sub(u'[\u201c\u201d]', '"', stdout) + + messages = json.loads(stdout) + + errors = [SanityMessage( + code=m['RuleName'], + message=m['Message'], + path=m['ScriptPath'].replace(cwd, ''), + line=m['Line'] or 0, + column=m['Column'] or 0, + level=severity[m['Severity']], + ) for m in messages] + + line = 0 + + filtered = [] + + for error in errors: + if error.code in ignore[error.path]: + ignore[error.path][error.code] = None # error ignored, clear line number of ignore entry to track usage + else: + filtered.append(error) # error not ignored + + errors = filtered + + for invalid_ignore in invalid_ignores: + errors.append(SanityMessage( + code='A201', + message=invalid_ignore[1], + path=PSLINT_IGNORE_PATH, + line=invalid_ignore[0], + column=1, + confidence=calculate_confidence(PSLINT_IGNORE_PATH, line, args.metadata) if args.metadata.changes else None, + )) + + for path in skip_paths: + line += 1 + + if not os.path.exists(path): + # Keep files out of the list which no longer exist in the repo. + errors.append(SanityMessage( + code='A101', + message='Remove "%s" since it does not exist' % path, + path=PSLINT_SKIP_PATH, + line=line, + column=1, + confidence=calculate_best_confidence(((PSLINT_SKIP_PATH, line), (path, 0)), args.metadata) if args.metadata.changes else None, + )) + + for path in paths: + if path not in ignore: + continue + + for code in ignore[path]: + line = ignore[path][code] + + if not line: + continue + + errors.append(SanityMessage( + code='A102', + message='Remove since "%s" passes "%s" test' % (path, code), + path=PSLINT_IGNORE_PATH, + line=line, + column=1, + confidence=calculate_best_confidence(((PSLINT_IGNORE_PATH, line), (path, 0)), args.metadata) if args.metadata.changes else None, + )) + + if errors: + return SanityFailure(self.name, messages=errors) + + return SanitySuccess(self.name) diff --git a/test/sanity/code-smell/no-smart-quotes.sh b/test/sanity/code-smell/no-smart-quotes.sh index de5f6c43bd8..ac31550ab0a 100755 --- a/test/sanity/code-smell/no-smart-quotes.sh +++ b/test/sanity/code-smell/no-smart-quotes.sh @@ -4,6 +4,7 @@ egrep -r '[‘’“”]' . \ --exclude-dir .git \ --exclude-dir .tox \ + --exclude-dir __pycache__ \ | grep -v \ -e './test/sanity/code-smell/no-smart-quotes.sh' \ -e './docs/docsite/rst/dev_guide/testing/sanity/no-smart-quotes.rst' \ diff --git a/test/sanity/pslint/ignore.txt b/test/sanity/pslint/ignore.txt new file mode 100644 index 00000000000..2597d15c1b5 --- /dev/null +++ b/test/sanity/pslint/ignore.txt @@ -0,0 +1,196 @@ +examples/scripts/ConfigureRemotingForAnsible.ps1 PSAvoidUsingCmdletAliases +examples/scripts/ConfigureRemotingForAnsible.ps1 PSUseBOMForUnicodeEncodedFile +examples/scripts/ConfigureRemotingForAnsible.ps1 PSUseShouldProcessForStateChangingFunctions +examples/scripts/upgrade_to_ps3.ps1 PSAvoidUsingWriteHost +examples/scripts/upgrade_to_ps3.ps1 PSUseApprovedVerbs +lib/ansible/module_utils/powershell/Ansible.ModuleUtils.ArgvParser.psm1 PSUseApprovedVerbs +lib/ansible/module_utils/powershell/Ansible.ModuleUtils.CommandUtil.psm1 PSPossibleIncorrectComparisonWithNull +lib/ansible/module_utils/powershell/Ansible.ModuleUtils.CommandUtil.psm1 PSUseApprovedVerbs +lib/ansible/module_utils/powershell/Ansible.ModuleUtils.FileUtil.psm1 PSProvideCommentHelp +lib/ansible/module_utils/powershell/Ansible.ModuleUtils.FileUtil.psm1 PSUseOutputTypeCorrectly +lib/ansible/module_utils/powershell/Ansible.ModuleUtils.Legacy.psm1 PSAvoidUsingCmdletAliases +lib/ansible/module_utils/powershell/Ansible.ModuleUtils.Legacy.psm1 PSAvoidUsingWMICmdlet +lib/ansible/module_utils/powershell/Ansible.ModuleUtils.Legacy.psm1 PSPossibleIncorrectComparisonWithNull +lib/ansible/module_utils/powershell/Ansible.ModuleUtils.Legacy.psm1 PSUseApprovedVerbs +lib/ansible/module_utils/powershell/Ansible.ModuleUtils.Legacy.psm1 PSUseShouldProcessForStateChangingFunctions +lib/ansible/module_utils/powershell/Ansible.ModuleUtils.LinkUtil.psm1 PSUseApprovedVerbs +lib/ansible/module_utils/powershell/Ansible.ModuleUtils.LinkUtil.psm1 PSUseShouldProcessForStateChangingFunctions +lib/ansible/modules/windows/setup.ps1 PSAvoidUsingCmdletAliases +lib/ansible/modules/windows/setup.ps1 PSAvoidUsingEmptyCatchBlock +lib/ansible/modules/windows/setup.ps1 PSPossibleIncorrectComparisonWithNull +lib/ansible/modules/windows/setup.ps1 PSUseDeclaredVarsMoreThanAssignments +lib/ansible/modules/windows/win_certificate_store.ps1 PSAvoidUsingPlainTextForPassword +lib/ansible/modules/windows/win_certificate_store.ps1 PSPossibleIncorrectComparisonWithNull +lib/ansible/modules/windows/win_certificate_store.ps1 PSUseShouldProcessForStateChangingFunctions +lib/ansible/modules/windows/win_chocolatey.ps1 PSAvoidUsingConvertToSecureStringWithPlainText +lib/ansible/modules/windows/win_chocolatey.ps1 PSAvoidUsingPlainTextForPassword +lib/ansible/modules/windows/win_chocolatey.ps1 PSAvoidUsingUserNameAndPassWordParams +lib/ansible/modules/windows/win_chocolatey.ps1 PSPossibleIncorrectComparisonWithNull +lib/ansible/modules/windows/win_chocolatey.ps1 PSUseApprovedVerbs +lib/ansible/modules/windows/win_chocolatey.ps1 PSUseDeclaredVarsMoreThanAssignments +lib/ansible/modules/windows/win_chocolatey.ps1 PSUseOutputTypeCorrectly +lib/ansible/modules/windows/win_copy.ps1 PSPossibleIncorrectComparisonWithNull +lib/ansible/modules/windows/win_copy.ps1 PSUseApprovedVerbs +lib/ansible/modules/windows/win_copy.ps1 PSUseDeclaredVarsMoreThanAssignments +lib/ansible/modules/windows/win_defrag.ps1 PSUseDeclaredVarsMoreThanAssignments +lib/ansible/modules/windows/win_dns_client.ps1 PSAvoidGlobalVars +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 PSPossibleIncorrectComparisonWithNull +lib/ansible/modules/windows/win_dns_client.ps1 PSUseApprovedVerbs +lib/ansible/modules/windows/win_dns_client.ps1 PSUseDeclaredVarsMoreThanAssignments +lib/ansible/modules/windows/win_dns_client.ps1 PSUseShouldProcessForStateChangingFunctions +lib/ansible/modules/windows/win_domain.ps1 PSAvoidUsingConvertToSecureStringWithPlainText +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 PSAvoidUsingConvertToSecureStringWithPlainText +lib/ansible/modules/windows/win_domain_controller.ps1 PSAvoidUsingPlainTextForPassword +lib/ansible/modules/windows/win_domain_controller.ps1 PSAvoidUsingUserNameAndPassWordParams +lib/ansible/modules/windows/win_domain_controller.ps1 PSAvoidUsingWMICmdlet +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 PSAvoidUsingConvertToSecureStringWithPlainText +lib/ansible/modules/windows/win_domain_group.ps1 PSPossibleIncorrectComparisonWithNull +lib/ansible/modules/windows/win_domain_membership.ps1 PSAvoidGlobalVars +lib/ansible/modules/windows/win_domain_membership.ps1 PSAvoidUsingConvertToSecureStringWithPlainText +lib/ansible/modules/windows/win_domain_membership.ps1 PSAvoidUsingPlainTextForPassword +lib/ansible/modules/windows/win_domain_membership.ps1 PSAvoidUsingUserNameAndPassWordParams +lib/ansible/modules/windows/win_domain_membership.ps1 PSAvoidUsingWMICmdlet +lib/ansible/modules/windows/win_domain_membership.ps1 PSPossibleIncorrectComparisonWithNull +lib/ansible/modules/windows/win_domain_membership.ps1 PSUseApprovedVerbs +lib/ansible/modules/windows/win_domain_membership.ps1 PSUseDeclaredVarsMoreThanAssignments +lib/ansible/modules/windows/win_domain_membership.ps1 PSUseShouldProcessForStateChangingFunctions +lib/ansible/modules/windows/win_domain_user.ps1 PSAvoidUsingConvertToSecureStringWithPlainText +lib/ansible/modules/windows/win_domain_user.ps1 PSPossibleIncorrectComparisonWithNull +lib/ansible/modules/windows/win_dsc.ps1 PSAvoidUsingCmdletAliases +lib/ansible/modules/windows/win_dsc.ps1 PSAvoidUsingConvertToSecureStringWithPlainText +lib/ansible/modules/windows/win_dsc.ps1 PSAvoidUsingEmptyCatchBlock +lib/ansible/modules/windows/win_dsc.ps1 PSPossibleIncorrectComparisonWithNull +lib/ansible/modules/windows/win_dsc.ps1 PSUseApprovedVerbs +lib/ansible/modules/windows/win_eventlog.ps1 PSUseDeclaredVarsMoreThanAssignments +lib/ansible/modules/windows/win_feature.ps1 PSAvoidUsingCmdletAliases +lib/ansible/modules/windows/win_feature.ps1 PSAvoidUsingInvokeExpression +lib/ansible/modules/windows/win_feature.ps1 PSUseDeclaredVarsMoreThanAssignments +lib/ansible/modules/windows/win_file.ps1 PSPossibleIncorrectComparisonWithNull +lib/ansible/modules/windows/win_file.ps1 PSUseShouldProcessForStateChangingFunctions +lib/ansible/modules/windows/win_file_version.ps1 PSUseBOMForUnicodeEncodedFile +lib/ansible/modules/windows/win_find.ps1 PSAvoidUsingEmptyCatchBlock +lib/ansible/modules/windows/win_find.ps1 PSAvoidUsingWMICmdlet +lib/ansible/modules/windows/win_find.ps1 PSPossibleIncorrectComparisonWithNull +lib/ansible/modules/windows/win_firewall_rule.ps1 PSAvoidUsingCmdletAliases +lib/ansible/modules/windows/win_firewall_rule.ps1 PSPossibleIncorrectComparisonWithNull +lib/ansible/modules/windows/win_firewall_rule.ps1 PSUseApprovedVerbs +lib/ansible/modules/windows/win_firewall_rule.ps1 PSUseShouldProcessForStateChangingFunctions +lib/ansible/modules/windows/win_get_url.ps1 PSAvoidUsingPlainTextForPassword +lib/ansible/modules/windows/win_get_url.ps1 PSPossibleIncorrectComparisonWithNull +lib/ansible/modules/windows/win_get_url.ps1 PSUseApprovedVerbs +lib/ansible/modules/windows/win_get_url.ps1 PSUseSupportsShouldProcess +lib/ansible/modules/windows/win_hotfix.ps1 PSPossibleIncorrectComparisonWithNull +lib/ansible/modules/windows/win_hotfix.ps1 PSUseApprovedVerbs +lib/ansible/modules/windows/win_iis_virtualdirectory.ps1 PSPossibleIncorrectComparisonWithNull +lib/ansible/modules/windows/win_iis_virtualdirectory.ps1 PSUseBOMForUnicodeEncodedFile +lib/ansible/modules/windows/win_iis_webapplication.ps1 PSPossibleIncorrectComparisonWithNull +lib/ansible/modules/windows/win_iis_webapplication.ps1 PSUseBOMForUnicodeEncodedFile +lib/ansible/modules/windows/win_iis_webapppool.ps1 PSPossibleIncorrectComparisonWithNull +lib/ansible/modules/windows/win_iis_webapppool.ps1 PSUseBOMForUnicodeEncodedFile +lib/ansible/modules/windows/win_iis_webbinding.ps1 PSUseApprovedVerbs +lib/ansible/modules/windows/win_iis_webbinding.ps1 PSUseBOMForUnicodeEncodedFile +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 PSPossibleIncorrectComparisonWithNull +lib/ansible/modules/windows/win_iis_website.ps1 PSUseBOMForUnicodeEncodedFile +lib/ansible/modules/windows/win_iis_website.ps1 PSUseDeclaredVarsMoreThanAssignments +lib/ansible/modules/windows/win_lineinfile.ps1 PSPossibleIncorrectComparisonWithNull +lib/ansible/modules/windows/win_mapped_drive.ps1 PSAvoidUsingConvertToSecureStringWithPlainText +lib/ansible/modules/windows/win_mapped_drive.ps1 PSPossibleIncorrectComparisonWithNull +lib/ansible/modules/windows/win_mapped_drive.ps1 PSUseShouldProcessForStateChangingFunctions +lib/ansible/modules/windows/win_nssm.ps1 PSAvoidUsingCmdletAliases +lib/ansible/modules/windows/win_nssm.ps1 PSAvoidUsingInvokeExpression +lib/ansible/modules/windows/win_nssm.ps1 PSAvoidUsingPlainTextForPassword +lib/ansible/modules/windows/win_nssm.ps1 PSAvoidUsingUserNameAndPassWordParams +lib/ansible/modules/windows/win_nssm.ps1 PSPossibleIncorrectComparisonWithNull +lib/ansible/modules/windows/win_nssm.ps1 PSUseApprovedVerbs +lib/ansible/modules/windows/win_nssm.ps1 PSUseDeclaredVarsMoreThanAssignments +lib/ansible/modules/windows/win_nssm.ps1 PSUseOutputTypeCorrectly +lib/ansible/modules/windows/win_package.ps1 PSAvoidUsingConvertToSecureStringWithPlainText +lib/ansible/modules/windows/win_package.ps1 PSAvoidUsingPlainTextForPassword +lib/ansible/modules/windows/win_package.ps1 PSPossibleIncorrectComparisonWithNull +lib/ansible/modules/windows/win_package.ps1 PSUseApprovedVerbs +lib/ansible/modules/windows/win_package.ps1 PSUsePSCredentialType +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 PSPossibleIncorrectComparisonWithNull +lib/ansible/modules/windows/win_pagefile.ps1 PSUseDeclaredVarsMoreThanAssignments +lib/ansible/modules/windows/win_pagefile.ps1 PSUseShouldProcessForStateChangingFunctions +lib/ansible/modules/windows/win_pagefile.ps1 PSUseSupportsShouldProcess +lib/ansible/modules/windows/win_path.ps1 PSUseShouldProcessForStateChangingFunctions +lib/ansible/modules/windows/win_power_plan.ps1 PSUseDeclaredVarsMoreThanAssignments +lib/ansible/modules/windows/win_product_facts.ps1 PSUseDeclaredVarsMoreThanAssignments +lib/ansible/modules/windows/win_psexec.ps1 PSPossibleIncorrectComparisonWithNull +lib/ansible/modules/windows/win_psexec.ps1 PSUseDeclaredVarsMoreThanAssignments +lib/ansible/modules/windows/win_psmodule.ps1 PSAvoidUsingCmdletAliases +lib/ansible/modules/windows/win_psmodule.ps1 PSUseShouldProcessForStateChangingFunctions +lib/ansible/modules/windows/win_rabbitmq_plugin.ps1 PSAvoidUsingCmdletAliases +lib/ansible/modules/windows/win_rabbitmq_plugin.ps1 PSAvoidUsingInvokeExpression +lib/ansible/modules/windows/win_reg_stat.ps1 PSPossibleIncorrectComparisonWithNull +lib/ansible/modules/windows/win_regedit.ps1 PSPossibleIncorrectComparisonWithNull +lib/ansible/modules/windows/win_region.ps1 PSAvoidUsingEmptyCatchBlock +lib/ansible/modules/windows/win_region.ps1 PSPossibleIncorrectComparisonWithNull +lib/ansible/modules/windows/win_region.ps1 PSUseShouldProcessForStateChangingFunctions +lib/ansible/modules/windows/win_robocopy.ps1 PSPossibleIncorrectComparisonWithNull +lib/ansible/modules/windows/win_route.ps1 PSAvoidUsingCmdletAliases +lib/ansible/modules/windows/win_route.ps1 PSUseShouldProcessForStateChangingFunctions +lib/ansible/modules/windows/win_scheduled_task.ps1 PSAvoidUsingCmdletAliases +lib/ansible/modules/windows/win_scheduled_task.ps1 PSPossibleIncorrectComparisonWithNull +lib/ansible/modules/windows/win_scheduled_task.ps1 PSUseShouldProcessForStateChangingFunctions +lib/ansible/modules/windows/win_scheduled_task_stat.ps1 PSAvoidUsingCmdletAliases +lib/ansible/modules/windows/win_scheduled_task_stat.ps1 PSPossibleIncorrectComparisonWithNull +lib/ansible/modules/windows/win_scheduled_task_stat.ps1 PSUseDeclaredVarsMoreThanAssignments +lib/ansible/modules/windows/win_security_policy.ps1 PSPossibleIncorrectComparisonWithNull +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 PSAvoidUsingPlainTextForPassword +lib/ansible/modules/windows/win_service.ps1 PSAvoidUsingUserNameAndPassWordParams +lib/ansible/modules/windows/win_service.ps1 PSAvoidUsingWMICmdlet +lib/ansible/modules/windows/win_service.ps1 PSPossibleIncorrectComparisonWithNull +lib/ansible/modules/windows/win_service.ps1 PSUseShouldProcessForStateChangingFunctions +lib/ansible/modules/windows/win_shell.ps1 PSAvoidUsingCmdletAliases +lib/ansible/modules/windows/win_shell.ps1 PSUseApprovedVerbs +lib/ansible/modules/windows/win_shortcut.ps1 PSPossibleIncorrectComparisonWithNull +lib/ansible/modules/windows/win_stat.ps1 PSAvoidUsingWMICmdlet +lib/ansible/modules/windows/win_stat.ps1 PSPossibleIncorrectComparisonWithNull +lib/ansible/modules/windows/win_stat.ps1 PSUseApprovedVerbs +lib/ansible/modules/windows/win_tempfile.ps1 PSPossibleIncorrectComparisonWithNull +lib/ansible/modules/windows/win_tempfile.ps1 PSUseShouldProcessForStateChangingFunctions +lib/ansible/modules/windows/win_unzip.ps1 PSAvoidUsingCmdletAliases +lib/ansible/modules/windows/win_unzip.ps1 PSUseApprovedVerbs +lib/ansible/modules/windows/win_updates.ps1 PSPossibleIncorrectComparisonWithNull +lib/ansible/modules/windows/win_uri.ps1 PSAvoidUsingConvertToSecureStringWithPlainText +lib/ansible/modules/windows/win_user.ps1 PSAvoidUsingCmdletAliases +lib/ansible/modules/windows/win_user.ps1 PSPossibleIncorrectComparisonWithNull +lib/ansible/modules/windows/win_user.ps1 PSUseShouldProcessForStateChangingFunctions +lib/ansible/modules/windows/win_wait_for.ps1 PSAvoidUsingEmptyCatchBlock +lib/ansible/modules/windows/win_wait_for.ps1 PSPossibleIncorrectComparisonWithNull +lib/ansible/modules/windows/win_wakeonlan.ps1 PSAvoidUsingCmdletAliases +lib/ansible/modules/windows/win_webpicmd.ps1 PSAvoidUsingInvokeExpression +lib/ansible/modules/windows/win_webpicmd.ps1 PSPossibleIncorrectComparisonWithNull +lib/ansible/modules/windows/win_webpicmd.ps1 PSUseOutputTypeCorrectly +test/integration/targets/uri/files/testserver.ps1 PSPossibleIncorrectComparisonWithNull +test/integration/targets/win_audit_rule/library/test_get_audit_rule.ps1 PSAvoidUsingCmdletAliases +test/integration/targets/win_dsc/library/test_win_dsc_iis_info.ps1 PSPossibleIncorrectComparisonWithNull +test/integration/targets/win_dsc/templates/ANSIBLE_xTestResource.psm1 PSAvoidDefaultValueForMandatoryParameter +test/integration/targets/win_dsc/templates/ANSIBLE_xTestResource.psm1 PSUseShouldProcessForStateChangingFunctions +test/integration/targets/win_iis_webbinding/library/test_get_webbindings.ps1 PSUseApprovedVerbs +test/integration/targets/win_module_utils/library/argv_parser_test.ps1 PSUseApprovedVerbs +test/integration/targets/win_module_utils/library/camel_conversion_test.ps1 PSUseDeclaredVarsMoreThanAssignments +test/integration/targets/win_module_utils/library/command_util_test.ps1 PSPossibleIncorrectComparisonWithNull +test/integration/targets/win_module_utils/library/sid_utils_test.ps1 PSPossibleIncorrectComparisonWithNull +test/integration/targets/win_module_utils/library/symbolic_link_test.ps1 PSPossibleIncorrectComparisonWithNull +test/integration/targets/win_ping/library/win_ping_strict_mode_error.ps1 PSUseDeclaredVarsMoreThanAssignments +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_with_args.ps1 PSAvoidUsingWriteHost +test/integration/targets/win_script/files/test_script_with_splatting.ps1 PSAvoidUsingWriteHost diff --git a/test/sanity/pslint/pslint.ps1 b/test/sanity/pslint/pslint.ps1 new file mode 100755 index 00000000000..00229476af3 --- /dev/null +++ b/test/sanity/pslint/pslint.ps1 @@ -0,0 +1,14 @@ +#!/usr/bin/env pwsh +#Requires -Version 6 +#Requires -Modules PSScriptAnalyzer + +Set-StrictMode -Version 2.0 +$ErrorActionPreference = "Stop" + +$Results = @() + +ForEach ($Path in $Args) { + $Results += Invoke-ScriptAnalyzer -Path $Path +} + +ConvertTo-Json -InputObject $Results diff --git a/test/sanity/pslint/skip.txt b/test/sanity/pslint/skip.txt new file mode 100644 index 00000000000..12e84739a89 --- /dev/null +++ b/test/sanity/pslint/skip.txt @@ -0,0 +1 @@ +test/integration/targets/win_ping/library/win_ping_syntax_error.ps1