Skip to content

PSScriptAnalyzer and VS Code tooling #224

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

Merged
merged 4 commits into from
Jun 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -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": ""
}
]
}
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,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,
Expand Down
19 changes: 19 additions & 0 deletions PSScriptAnalyzerSettings.psd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# PSScriptAnalyzerSettings.psd1
# Settings for PSScriptAnalyzer invocation.
# All default rules are also enabled.
@{
Rules = @{
PSUseCompatibleSyntax = @{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool!

# 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'
)
}
}
}
2 changes: 1 addition & 1 deletion build/pipelines/templates/run-staticAnalysis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ steps:
displayName: 'Install PSScriptAnalyzer'

- powershell: |
$results = try { Invoke-ScriptAnalyzer -Path ./ –Recurse -ErrorAction Stop } catch { $_.Exception.StackTrace; throw }
$results = try { Invoke-ScriptAnalyzer -Settings ./PSScriptAnalyzerSettings.psd1 -Path ./ –Recurse -ErrorAction Stop } catch { $_.Exception.StackTrace; throw }
$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
Expand Down
2 changes: 1 addition & 1 deletion build/scripts/ConvertTo-NUnitXml.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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()]
Expand Down