-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ci] check PowerShell scripts with PSScriptAnalyzer (part 1) #6704
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! The script changes look great to me... I agree with the choice of rules and and verbs. Thanks for the links in the description... I was not familiar with this concept of "approved verbs" in powershell before.
I just left one small suggestion on test.sh
. Marking this "Approve", so you can merge without needing a new review from me if you agree with that suggestion.
.ci/test.sh
Outdated
@@ -110,6 +110,9 @@ if [[ $TASK == "lint" ]]; then | |||
'r-lintr>=3.1.2' | |||
# shellcheck disable=SC1091 | |||
source activate "${CONDA_ENV}" | |||
pwsh -command "Install-Module -Name PSScriptAnalyzer -Scope CurrentUser -SkipPublisherCheck" | |||
echo "Linting PowerShell code" | |||
pwsh -file "./.ci/lint-powershell.ps1" || exit 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because this doesn't require anything installed with conda
(we're relying on the pwsh
that comes pre-installed on the runner), I think we should move this up to before conda create
. Two reasons:
- prevents the case where we wait for
conda install
to complete (which can sometimes take a few minutes) and then find out that the job is going to fail because of issues found byPSScriptAnalyzer
. - prevents where
source activate "${CONDA ENV}"
modifies the environment in a way that causes issues forpwsh
(e.g. changesPATH
/LD_LIBRARY_PATH
and causes an incompatible mix of libraries to be loaded)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! Totally makes sense. Will push changes right now.
Linking full original PR: #6700.
This PR fixes all warnings about our own functions (
PSUseApprovedVerbs
,PSUseShouldProcessForStateChangingFunctions
,PSUseSingularNouns
).Also this PR makes params in our own functions mandatory where needed.
List of available rules: https://github.com/PowerShell/PSScriptAnalyzer/blob/main/docs/Rules/README.md.
List of Approved Verbs for PowerShell Commands: https://learn.microsoft.com/en-us/powershell/scripting/developer/cmdlet/approved-verbs-for-windows-powershell-commands?view=powershell-7.4.