Skip to content

Conversation

@littleKitchen
Copy link
Contributor

Summary

Fixes #306

Adds Test-CopyrightHeaders.ps1 script that validates the presence of copyright and SPDX license headers in source files.

Changes

New Files

  • scripts/linting/Test-CopyrightHeaders.ps1 - Main validation script
  • scripts/tests/linting/Test-CopyrightHeaders.Tests.ps1 - Pester tests

Modified Files

  • package.json - Added validate:copyright npm script

Features

  • Scans .ps1, .psm1, .psd1, .sh files by default
  • Checks for # Copyright (c) Microsoft Corporation. line
  • Checks for # SPDX-License-Identifier: MIT line
  • Handles shebang and #Requires statement positioning (checks first 15 lines)
  • Outputs JSON results matching existing format
  • Supports -FailOnMissing flag for CI integration
  • Includes compliance percentage calculation

Testing

Pester tests cover:

  • Files with valid headers
  • Files missing copyright line
  • Files missing SPDX line
  • Files missing both headers
  • Files with #Requires statements
  • Parameter validation
  • Output format validation

Adds Test-CopyrightHeaders.ps1 script that validates the presence of
copyright and SPDX license headers in source files.

Features:
- Scans .ps1, .psm1, .psd1, .sh files by default
- Checks for 'Copyright (c) Microsoft Corporation.' line
- Checks for 'SPDX-License-Identifier: MIT' line
- Handles shebang and #Requires statement positioning
- Outputs JSON results to logs/copyright-header-results.json
- Supports -FailOnMissing for CI integration

Also includes:
- npm script: validate:copyright
- Pester tests for all validation scenarios

Fixes microsoft#306
@littleKitchen littleKitchen requested a review from a team as a code owner January 31, 2026 00:50
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 - this looks good and covers the issue.

@codecov-commenter
Copy link

Codecov Report

❌ Patch coverage is 90.80460% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 53.45%. Comparing base (4bb857d) to head (08070d1).

Files with missing lines Patch % Lines
scripts/linting/Test-CopyrightHeaders.ps1 90.80% 8 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #370      +/-   ##
==========================================
+ Coverage   52.44%   53.45%   +1.01%     
==========================================
  Files          17       18       +1     
  Lines        3110     3197      +87     
==========================================
+ Hits         1631     1709      +78     
- Misses       1479     1488       +9     
Flag Coverage Δ
pester 53.45% <90.80%> (+1.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
scripts/linting/Test-CopyrightHeaders.ps1 90.80% <90.80%> (ø)

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@katriendg
Copy link
Contributor

Can you please review if you can improve code coverage? Thanks

@katriendg katriendg self-requested a review February 3, 2026 10:17
@katriendg
Copy link
Contributor

@littleKitchen please see the PowerShell failed check and review your Tests.
Also there are some improvements your can make to the Tests to follow patterns like in Invoke-PSScriptAnalyzer.Tests.ps1 (create all fixtures once in the top-level BeforeAll, passing glob pattern to -FileExtensions, ...).
You can use the PR-Review agent in the repo and get it to help you address the optimizations.
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.

feat: add PowerShell script to validate copyright headers

3 participants