Skip to content
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

Feature: Implement Dual-Validation PSScriptAnalyzer with Standardized Settings #144

Open
11 of 12 tasks
jonnybottles opened this issue Nov 18, 2024 · 3 comments
Open
11 of 12 tasks
Assignees
Labels
status/in-progress Being worked type/feature New feature or request

Comments

@jonnybottles
Copy link
Collaborator

jonnybottles commented Nov 18, 2024

What problem would this feature solve?

Currently, PSScriptAnalyzer in Hawk:

  • Only runs during CI via PSScriptAnalyzer.Tests.ps1
  • Has hardcoded rule exclusions
  • No local validation before commits
  • No standardized settings file

This means:

  • Developers only discover issues after pushing code
  • CI pipeline failures for fixable style issues
  • Inconsistent rule enforcement
  • No documented reasoning for exclusions

Proposed Solution

Implement a dual-validation approach that runs PSScriptAnalyzer:

  • Locally via pre-commit hooks
  • In CI via existing Pester tests

Both using the same standardized settings file to ensure consistency.

Technical Requirements

Settings File Requirements

  • Create standardized PSScriptAnalyzer settings file in .github/psscriptanalyzer/settings.psd1
  • Maintain current rule exclusions (PSAvoidTrailingWhitespace, PSShouldProcess)
  • Document reasoning for each excluded rule
  • Ensure settings file is accessible to both local and CI validation

Test Suite Updates

  • Modify PSScriptAnalyzer.Tests.ps1 to use centralized settings file
  • Remove hardcoded rule exclusions from test file
  • Maintain current test behavior and reporting
  • Ensure test failures provide clear guidance

Pre-commit Hook Requirements

  • Create pre-commit hook configuration file
  • Configure hook to use same settings file as CI
  • Support PS1, PSM1, and PSD1 file validation
  • Provide clear error messages for validation failures

Documentation Requirements

  • Create setup guide for pre-commit hooks

Implementation Approach

Implementation Steps

  • Create settings file with current exclusions
  • Update PSScriptAnalyzer test to use settings file
  • Add pre-commit hook configuration
  • Add documentation and setup instructions
  • Test both local and CI validation

Acceptance Criteria

Acceptance Criteria

  1. Settings File
  • Created with current exclusions
  • Properly referenced by both validations
  • No changes to enforced rules
  1. Pre-commit Hook
  • Configuration file created
  • Works with settings file
  • Clear error messages
  • Easy to set up
  1. CI Test
  • Updated to use settings file
  • Maintains current behavior
  • Consistent with pre-commit
  • Clear test failures
  1. Documentation
  • Pre-commit setup instructions
@jonnybottles jonnybottles added type/feature New feature or request status/in-progress Being worked labels Nov 18, 2024
@jonnybottles jonnybottles self-assigned this Nov 18, 2024
@jonnybottles
Copy link
Collaborator Author

Done:

  • Implemented the PSScriptAnalyzer settings / config file
  • Implemented Github pre-commit hook
  • Updated Confluence page with appropriate documentation for each developer to setup pre-commit hooks and VSCode extension that refernces the PSScriptAnalyzer settings file

To Do:

  • CI workflow integration

@jonnybottles
Copy link
Collaborator Author

Both pre-commit hook and workflow references same PSSA config file. Need to modify ole validate.yml to no longer call PSSA in the PSScriptAnalyzer.Tests.ps1 file and then remove that file.

@jonnybottles
Copy link
Collaborator Author

PSSA config file moved to Hawk/internal/configurations. Both pre-commit hook / workflow is working and ticket tasks are complete. However, the RobustCloudCommand error is now showing back up and needs to be fixed. To allow for pushing to the repo the module build in vsts-prequisites.ps1 is currently commented out to avoid the RobustCloudCommand failure.

Current recommended appraoch is to download the RobustCloudCommand from its GitHub repo and then include it in a Hawk folder Hawk/external, and have the Hawk.psd1 reference that file instead of the external no longer existing module in the PowerShell gallery.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status/in-progress Being worked type/feature New feature or request
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

1 participant