PowerShell / PSScriptAnalyzer

Download ScriptAnalyzer from PowerShellGallery
https://www.powershellgallery.com/packages/PSScriptAnalyzer/
MIT License
1.87k stars 378 forks source link

PSProvideCommentHelp should also warn on script param blocks #1363

Open TylerLeonhardt opened 5 years ago

TylerLeonhardt commented 5 years ago

Summary of the new feature

As a user, I want the ## comment generation feature in the PowerShell extension for VSCode to also generate comment based help for param blocks at the top of scripts. The PowerShell extension leverages the PSProvideCommentHelp rule to do this.

Proposed technical implementation details (optional)

Invoke-ScriptAnalyzer -ScriptDefinition 'param($foo)' -Settings @{ 
  Rules = @{
      PSProvideCommentHelp = @{
          Enable = $true
          ExportedOnly = $false
          BlockComment = $true
          VSCodeSnippetCorrection = $false
          Placement = "before"
      }
  }
  }

This should yield a diagnostic record just like this does:

Invoke-ScriptAnalyzer -ScriptDefinition 'function asdf { param($foo) }' -Settings @{
  Rules = @{
      PSProvideCommentHelp = @{
          Enable = $true
          ExportedOnly = $false
          BlockComment = $true
          VSCodeSnippetCorrection = $false
          Placement = "before"
      }
  }
  }

RuleName                            Severity     ScriptName Line  Message
--------                            --------     ---------- ----  -------
PSProvideCommentHelp                Information             1     The cmdlet 'asdf' does not have a help comment.

What is the latest version of PSScriptAnalyzer at the point of writing

1.18.3

bergmeister commented 5 years ago

Interesting, I didn't know that the code snippets rely on PSSA, I thought PSES would do that or is it a mix between the two? This looks like a low hanging fruit, we just have to be careful to check that the param block is not inside a function ast.

TylerLeonhardt commented 5 years ago

I didn't either. It's pretty odd. We run PSSA just for this rule and get its quick fix.