Skip to content

Get PSScriptAnalyzer clean again #180

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 2 commits into from
May 26, 2020

Conversation

HowardWolosky
Copy link
Member

@HowardWolosky HowardWolosky commented May 26, 2020

Somehow a number of PSScriptAnalyzer issues have snuck in over time. This fixes them all.

The main PSScriptAnalyzer issues needing to be fixed were:

  • PSReviewUnusedParameter - This one came up a lot due to our heavy
    usage of Resolve-RepositoryElements and Resolve-ParameterWithDefaultConfigurationValue
    which both end up referencing their parameters by grabbing them off
    the stack. That means that NoStatus and Uri are frequently
    never directly referenced. So, exceptions were added. There were
    two cases (in GitHubAnalytics) where there was a false positive due
    to ReviewUnusedParameter does not capture parameter usage within a scriptblock PowerShell/PSScriptAnalyzer#1472

  • PSUseProcessBlockForPipelineCommand - We had a number of functions
    that took pipeline input, but didn't actuall use the process block.
    This actually caught a bug with Group-GitHubIssue and
    Group-GitHubPullRequest. Added correct process block usage for
    most of the functions, but removed pipeline support for those where
    it didn't actually make sense anymore.

  • PSUseDeclaredVarsMoreThanAssignments - These are false positives
    in the Pester tests due to the usage of BeforeAll. There wasn't
    an obvious way to use SuppressMessageAttribute in the Pester test,
    so I used a hacky workaround to "use" the variable in the BeforeAll
    block. I could have added the suppression to the top of the file,
    but I still want to catch real issues in those files later.

  • PSAvoidOverwritingBuiltInCmdlets - It turns out that there's a bug
    with PSDesiredStateConfiguration in PS Core 6.1.0 where it was exporting
    internal functions. This was thus a false-postive flag for Write-Log.
    See PSDesiredStateConfiguration exporting internal functions PowerShell/PowerShell#7209 for more info.

Also, it turns out that Group-GitHubPullRequest hadn't actually been
exported, so I fixed that too.

@HowardWolosky HowardWolosky added the technical debt Work that was postponed by a previous change. label May 26, 2020
@HowardWolosky
Copy link
Member Author

/azp run PowerShellForGitHub-CI

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@HowardWolosky
Copy link
Member Author

/azp run PowerShellForGitHub-CI

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@HowardWolosky
Copy link
Member Author

/azp run PowerShellForGitHub-CI

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Somehow a number of PSScriptAnalyzer issues snuck in.  This fixes them.

The main PSScriptAnalyzer issues needing to be fixed were:
 * `PSReviewUnusedParameter` - This one came up a lot due to our heavy
    usage of `Resolve-RepositoryElements` and `Resolve-ParameterWithDefaultConfigurationValue`
    which both end up referencing their parameters by grabbing them off
    the stack.  That means that `NoStatus` and `Uri` are frequently
    never directly referenced.  So, exceptions were added.  There were
    two cases (in GitHubAnalytics) where there was a false positive due
    to PowerShell/PSScriptAnalyzer#1472

 * `PSUseProcessBlockForPipelineCommand` - We had a number of functions
   that took pipeline input, but didn't actuall use the `process` block.
   This actually caught a bug with `Group-GitHubIssue` and
   `Group-GitHubPullRequest`.  Added correct `process` block usage for
   most of the functions, but removed pipeline support for those where
   it didn't actually make sense anymore.

 * `PSUseDeclaredVarsMoreThanAssignments` - These are false positives
   in the Pester tests due to the usage of `BeforeAll`.  There wasn't
   an obvious way to use `SuppressMessageAttribute` in the Pester test,
   so I used a hacky workaround to "use" the variable in the `BeforeAll`
   block.  I could have added the suppression to the top of the file,
   but I still want to catch real issues in those files later.

 * `PSAvoidOverwritingBuiltInCmdlets` - It turns out that there's a bug
   with PSDesiredStateConfiguration in PS Core 6.1.0 where it was exporting
   internal functions.  This was thus a false-postive flag for Write-Log.
   See PowerShell/PowerShell#7209 for more info.

Also, it turns out that `Group-GitHubPullRequest` hadn't actually been
exported, so I fixed that too.
@HowardWolosky
Copy link
Member Author

/azp run PowerShellForGitHub-CI

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@HowardWolosky
Copy link
Member Author

/azp run PowerShellForGitHub-CI

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@HowardWolosky HowardWolosky merged commit b7e1ea1 into microsoft:master May 26, 2020
@HowardWolosky HowardWolosky deleted the scriptAnalyzer branch May 26, 2020 15:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
technical debt Work that was postponed by a previous change.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant