Skip to content

feat: add PowerShell script to validate copyright headers #306

@WilliamBerryiii

Description

@WilliamBerryiii

Description

Create a PowerShell script that validates the presence of copyright and SPDX license headers in source files. This script integrates with the existing linting infrastructure and follows PSScriptAnalyzer patterns established in the codebase.

Acceptance Criteria

  • Create scripts/linting/Test-CopyrightHeaders.ps1
  • Script detects missing or malformed headers
  • Output follows existing JSON result format
  • Results written to logs/copyright-header-results.json
  • Add npm run script for easy execution
  • Include comment-based help following codebase conventions
  • Pass PSScriptAnalyzer validation
  • Create Pester tests in scripts/tests/linting/

Implementation Steps

  1. Create scripts/linting/Test-CopyrightHeaders.ps1 with these features:

    • Accept path parameter for target directory
    • Support file type filtering (.ps1, .psm1, .psd1, .sh)
    • Check for copyright line pattern: # Copyright (c) Microsoft Corporation.
    • Check for SPDX line pattern: # SPDX-License-Identifier: MIT
    • Handle shebang and #Requires statement positioning
  2. Output format (matching existing patterns):

    {
      "timestamp": "2026-01-26T12:00:00Z",
      "totalFiles": 38,
      "filesWithHeaders": 38,
      "filesMissingHeaders": 0,
      "results": [
        {
          "file": "scripts/lib/Get-VerifiedDownload.ps1",
          "hasCopyright": true,
          "hasSpdx": true,
          "valid": true
        }
      ]
    }
  3. Add npm script to package.json:

    "validate:copyright": "pwsh scripts/linting/Test-CopyrightHeaders.ps1"
  4. Create Pester tests covering:

    • Files with valid headers
    • Files missing copyright line
    • Files missing SPDX line
    • Files with incorrect line positions

Reference Implementation

Follow patterns from:

  • scripts/linting/Invoke-PSScriptAnalyzer.ps1
  • scripts/security/Test-DependencyPinning.ps1

Time Estimate

2-3 hours

Dependencies

Metadata

Metadata

Assignees

No one assigned

    Labels

    automationCI/CD and automation improvementsenhancementNew feature or request

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions