You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(scripts): ensure reliable array count operations in linting and security scripts (#395)
## Description
This PR fixes PowerShell array handling issues in linting and security
validation scripts by ensuring array assignments and count operations
use proper array coercion with `@()`. These changes prevent potential
errors when pipeline operations return null or single items instead of
arrays.
- **fix(linting)**: wrapped array assignments in
Invoke-PSScriptAnalyzer, Invoke-YamlLint, and Markdown-Link-Check with
`@()` to ensure consistent array behavior
- Applied to file collection calls from `Get-ChangedFilesFromGit` and
`Get-FilesRecursive`
- Added array coercion to all `.Count` property accesses for reliable
zero-count checks
- **fix(linting)**: added array coercion to count checks in
Validate-MarkdownFrontmatter
- Wrapped `Get-ChangedMarkdownFileGroup` result with `@()` for
consistent array handling
- Applied to count checks to prevent null reference errors
- **fix(security)**: improved array handling in Test-DependencyPinning
script
- Added `@()` wrapping to violation collection and grouping operations
- Applied to measure-object count operations and group-by filtering
- **fix(security)**: enhanced array coercion in Test-SHAStaleness script
- Wrapped all count checks and array operations with `@()` for reliable
behavior
- Added initialization of `$script:StaleDependencies` as empty array
- Applied to tool staleness detection and error collection
## Related Issue(s)
Fixes [#394](#394)
## Type of Change
Select all that apply:
**Code & Documentation:**
- [x] Bug fix (non-breaking change fixing an issue)
- [ ] New feature (non-breaking change adding functionality)
- [ ] Breaking change (fix or feature causing existing functionality to
change)
- [ ] Documentation update
**Infrastructure & Configuration:**
- [ ] GitHub Actions workflow
- [ ] Linting configuration (markdown, PowerShell, etc.)
- [ ] Security configuration
- [ ] DevContainer configuration
- [ ] Dependency update
**AI Artifacts:**
- [ ] Reviewed contribution with `prompt-builder` agent and addressed
all feedback
- [ ] Copilot instructions (`.github/instructions/*.instructions.md`)
- [ ] Copilot prompt (`.github/prompts/*.prompt.md`)
- [ ] Copilot agent (`.github/agents/*.agent.md`)
**Other:**
- [x] Script/automation (`.ps1`, `.sh`, `.py`)
- [ ] Other (please describe):
## Testing
Tested by running the affected scripts with various file count
scenarios:
- Zero files found (empty array handling)
- Single file (automatic array coercion)
- Multiple files (existing array behavior)
All scripts now handle edge cases consistently without null reference
errors.
## Checklist
### Required Checks
- [ ] Documentation is updated (if applicable)
- [x] Files follow existing naming conventions
- [x] Changes are backwards compatible (if applicable)
- [ ] Tests added for new functionality (if applicable)
### AI Artifact Contributions
- [ ] Used `/prompt-analyze` to review contribution
- [ ] Addressed all feedback from `prompt-builder` review
- [ ] Verified contribution follows common standards and type-specific
requirements
### Required Automated Checks
The following validation commands must pass before merging:
- [ ] Markdown linting: `npm run lint:md`
- [x] Spell checking: `npm run spell-check`
- [ ] Frontmatter validation: `npm run lint:frontmatter`
- [ ] Link validation: `npm run lint:md-links`
- [x] PowerShell analysis: `npm run lint:ps`
## Security Considerations
- [x] This PR does not contain any sensitive or NDA information
- [x] Any new dependencies have been reviewed for security issues
- [x] Security-related scripts follow the principle of least privilege
## Additional Notes
These changes follow PowerShell best practices for defensive array
handling. The `@()` operator ensures that pipeline results are always
treated as arrays, even when they return null or single items,
preventing runtime errors in count operations and foreach loops.
🔧 - Generated by Copilot
---------
Co-authored-by: Bill Berry <[email protected]>
0 commit comments