Skip to content

Conversation

@littleKitchen
Copy link
Contributor

@littleKitchen littleKitchen commented Jan 31, 2026

Summary

Resolves #323

Extracts common boilerplate from linting wrapper scripts into shared helper functions.

Changes

New functions in LintingHelpers.psm1:

  • New-LintingContext - Primary function that creates a standardized context object for linting operations, implementing the core refactoring
  • Test-LintingFilesExist - Handles common "no files found" pattern with standardized messaging
  • Write-LintingHeader - Standardized header output for linting scripts

Updated scripts:

  • Invoke-PSScriptAnalyzer.ps1 - Uses Test-LintingFilesExist
  • Invoke-YamlLint.ps1 - Uses Test-LintingFilesExist

Testing

Notes

This is a minimal refactoring that extracts the most common boilerplate while maintaining backward compatibility.

Resolves microsoft#323

Add shared helper functions to LintingHelpers.psm1:
- Test-LintingFilesExist: Common file existence check and messaging
- Write-LintingHeader: Standardized header output

Update Invoke-PSScriptAnalyzer.ps1 and Invoke-YamlLint.ps1 to use
the shared helpers, reducing ~15 lines of duplicate boilerplate each.

Note: Some unit tests may need mock scope updates (-ModuleName) due
to the helper functions being called from within the module.
@littleKitchen littleKitchen requested a review from a team as a code owner January 31, 2026 07:00
Copy link
Contributor

@katriendg katriendg left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution!
The basis of this PR is looking good, but it's not yet complete. There is no function named New-LintingContext as described in the Issue.

You have added a new function but it's never called.
Can you update the references to replace Write-Host header calls with Write-LintingHeader in Invoke-YamlLint.ps1 and Invoke-PSScriptAnalyzer.ps1?

Idea: have you evaluated using the rpi-agent and point it at the issue to have it implement all requirements? Also explicitly ask the agent to help you update any of the Tests which are related to the changed files.

WilliamBerryiii and others added 3 commits February 2, 2026 09:37
- Add New-LintingContext function that handles common file discovery
  and changes-only filtering as requested in microsoft#323
- Update Invoke-PSScriptAnalyzer.ps1 to use New-LintingContext
- Update Invoke-YamlLint.ps1 to use New-LintingContext
- Write-LintingHeader is now called via New-LintingContext
…der, New-LintingContext

Updates LintingHelpers.Tests.ps1 with comprehensive tests for the new
helper functions as requested in code review.
@littleKitchen
Copy link
Contributor Author

Thanks for the review!

Copy link
Contributor

@katriendg katriendg left a comment

Choose a reason for hiding this comment

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

Looks good now, but please make sure you update the PR description to document that New-LintingContext is the primary function that implements the refactoring. It's missing from the overview.

@katriendg
Copy link
Contributor

Sharing here the backlog to address the unit test mock updates #396

@littleKitchen
Copy link
Contributor Author

Description updated; maybe work on #396 later.

@WilliamBerryiii
Copy link
Member

@littleKitchen - I'll resolve the branch conflicts shortly. If you could, hold off on more work in this space as I'm trying to get your other PRs merged and some testing improvements (from my own branch) landed later today.

@littleKitchen
Copy link
Contributor Author

@littleKitchen - I'll resolve the branch conflicts shortly. If you could, hold off on more work in this space as I'm trying to get your other PRs merged and some testing improvements (from my own branch) landed later today.

sure, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Issue]: Extract shared boilerplate from linting wrapper scripts

3 participants