From 23931ced51d4fabc0509be9a22141a739e39cbc6 Mon Sep 17 00:00:00 2001 From: Tyler Leonhardt Date: Sat, 6 Jun 2020 15:20:48 -0700 Subject: [PATCH 1/2] PSScriptAnalyzer and VS Code tooling --- .vscode/launch.json | 17 +++++++++++++++++ PSScriptAnalyzerSettings.psd1 | 19 +++++++++++++++++++ .../templates/run-staticAnalysis.yaml | 2 +- 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 .vscode/launch.json create mode 100644 PSScriptAnalyzerSettings.psd1 diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 00000000..7820daf8 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,17 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + // Run this launch config and then set breakpoints in your module. + // Then you can `Import-Module -Force ./PowerShellForGitHub.psd1` + // and run a function that will hit the breakpoint. + "name": "PowerShell: Interactive Session", + "type": "PowerShell", + "request": "launch", + "cwd": "" + } + ] +} diff --git a/PSScriptAnalyzerSettings.psd1 b/PSScriptAnalyzerSettings.psd1 new file mode 100644 index 00000000..c7fa4bf3 --- /dev/null +++ b/PSScriptAnalyzerSettings.psd1 @@ -0,0 +1,19 @@ +# PSScriptAnalyzerSettings.psd1 +# Settings for PSScriptAnalyzer invocation. +# All default rules are also enabled. +@{ + Rules = @{ + PSUseCompatibleSyntax = @{ + # This turns the rule on (setting it to false will turn it off) + Enable = $true + + # Simply list the targeted versions of PowerShell here + TargetVersions = @( + '4.0', + '5.1', + '6.2', + '7.0' + ) + } + } +} diff --git a/build/pipelines/templates/run-staticAnalysis.yaml b/build/pipelines/templates/run-staticAnalysis.yaml index feddaa9b..f18eb19b 100644 --- a/build/pipelines/templates/run-staticAnalysis.yaml +++ b/build/pipelines/templates/run-staticAnalysis.yaml @@ -9,7 +9,7 @@ steps: displayName: 'Install PSScriptAnalyzer' - powershell: | - $results = Invoke-ScriptAnalyzer -Path ./ –Recurse + $results = Invoke-ScriptAnalyzer -Settings ./PSScriptAnalyzerSettings.psd1 -Path ./ –Recurse $results | ForEach-Object { Write-Host "##vso[task.logissue type=$($_.Severity);sourcepath=$($_.ScriptPath);linenumber=$($_.Line);columnnumber=$($_.Column);]$($_.Message)" } $null = New-Item -Path ..\ -Name ScriptAnalyzer -ItemType Directory -Force From 287924fcb20dcbb9404c378b1458ae0c19fac8a9 Mon Sep 17 00:00:00 2001 From: Tyler Leonhardt Date: Sun, 14 Jun 2020 19:15:31 -0700 Subject: [PATCH 2/2] add setting parameter --- CONTRIBUTING.md | 2 +- build/scripts/ConvertTo-NUnitXml.ps1 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index dff45883..0f0ea2d2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -152,7 +152,7 @@ Update-Module -Name PSScriptAnalyzer Once it's installed (or updated), from the root of your enlistment simply call ```powershell -Invoke-ScriptAnalyzer -Path .\ -Recurse +Invoke-ScriptAnalyzer -Settings ./PSScriptAnalyzerSettings.psd1 -Path ./ -Recurse ``` That should return with no output. If you see any output when calling that command, diff --git a/build/scripts/ConvertTo-NUnitXml.ps1 b/build/scripts/ConvertTo-NUnitXml.ps1 index fc65224b..b4321152 100644 --- a/build/scripts/ConvertTo-NUnitXml.ps1 +++ b/build/scripts/ConvertTo-NUnitXml.ps1 @@ -16,7 +16,7 @@ Overwrite the file at Path if it exists. .EXAMPLE - $results = Invoke-ScriptAnalyzer -Path ./ -Recurse + $results = Invoke-ScriptAnalyzer -Settings ./PSScriptAnalyzerSettings.psd1 -Path ./ -Recurse .\ConverTo-NUnitXml.ps1 -ScriptAnalyzerResult $results -Path ./PSScriptAnalyzerFailures.xml #> [CmdletBinding()]