Repository navigation
feat(cargo-heather): recognize .psd1 and .psm1 as PowerShell files - #38
Merged
Merged
Conversation
PowerShell data files (.psd1, used for module manifests and configuration hashtables) and PowerShell module files (.psm1) share the same `#` line-comment syntax as `.ps1` scripts but were silently skipped by the scanner because `FileKind::detect` only recognized the `.ps1` extension. This was visible downstream in microsoft/oxidizer#436, where a new suite of `.psd1` Pester scenario fixtures had to be hand-headered after a reviewer noticed they were missing MIT headers — `cargo heather` itself never flagged them because it never saw them. Extend `FileKind::detect` to classify `.psd1` and `.psm1` as `PowerShell`. Comment-style detection, header insertion, and fix logic all key off `FileKind::PowerShell` and need no other changes — the addition is purely an extension allowlist update. Also refresh `README.md` to list the currently-supported file kinds (this brought `.ps1`, Just, and `constants.env` along too — the README had drifted behind the implementation). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Expands cargo-heather’s PowerShell support so .psd1 (data/module manifests) and .psm1 (modules) are treated as PowerShell sources during scanning, ensuring license headers are validated/fixed rather than silently skipped.
Changes:
- Extend
FileKind::detectto classify.psd1and.psm1(case-insensitive) asFileKind::PowerShell. - Add unit + integration test coverage to prevent regressions and to assert the scanner reports missing headers for these file types.
- Update crate docs/README to reflect the broader set of supported source file kinds.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| crates/cargo-heather/tests/cli.rs | Extends integration tests to include .psd1/.psm1 scanning and missing-header reporting. |
| crates/cargo-heather/src/lib.rs | Updates library docs to enumerate supported PowerShell extensions. |
| crates/cargo-heather/src/comment.rs | Updates PowerShell detection logic and adds unit tests for new extensions. |
| crates/cargo-heather/README.md | Updates README to list supported file kinds and scanning behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Evgenii (Vaiz)
approved these changes
Jun 8, 2026
martintmk
approved these changes
Jun 8, 2026
Sergey Galkin (sgalkin)
approved these changes
Jun 8, 2026
…d header extraction Address PR #38 review feedback: - `FileKind::PowerShell` doc: note that the `#` header is placed at the top OR after a leading `#!` shebang. Implementation (`checker::header_after_optional_shebang`) handles all three PowerShell extensions identically. - `README.md` 'How it works' step rewritten to describe header extraction per file kind (top-of-file for Rust/TOML/Just/env, after-shebang for PowerShell, inside frontmatter for cargo-script) instead of the misleading 'first comment block, `//` for Rust, `#` for the rest' shorthand. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
martin-kolinek
approved these changes
Jun 8, 2026
Ralf Biedert (ralfbiedert)
approved these changes
Jun 8, 2026
martintmk
approved these changes
Jun 8, 2026
…orted-kinds table Address PR #38 review feedback (ralfbiedert): the previous wrapped paragraph reading 'a // block at the top for Rust sources, a # block at the top for TOML / Just / constants.env, a # block after an optional #! shebang for PowerShell, and a # block inside the --- frontmatter for Rust cargo-scripts' was too dense for an at-a-glance description. Shortened the 'How it works' steps to one-liners and moved the per-file-kind comment style and header placement details into a new 'Supported file kinds' table, which doubles as a reference users can jump to. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #38 +/- ##
=======================================
+ Coverage 93.1% 93.2% +0.1%
=======================================
Files 28 28
Lines 1241 1262 +21
=======================================
+ Hits 1156 1177 +21
Misses 85 85 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Evgenii (Vaiz)
approved these changes
Jun 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Recognize
.psd1(PowerShell data) and.psm1(PowerShell module) files as PowerShell sources inFileKind::detectso the scanner checks/fixes their license headers instead of silently skipping them.Motivation
.psd1and.psm1use the same#line-comment syntax as.ps1scripts and routinely appear alongside them — module manifests (MyMod.psd1), data files driving PowerShell-based tooling (e.g. Pester scenario fixtures), and module implementations (MyMod.psm1). Pre-fix,FileKind::detectmatched onlyps1so these files were silently dropped during scanning. Runningcargo heatheragainst a directory containing.psd1fixtures with no header reportsAll N file(s) have correct license headerseven though those fixtures were never inspected.This was observed in microsoft/oxidizer#436 (a new Pester scenario suite landed ~25
.psd1fixtures without license headers and CI did not catch it).Change
FileKind::detectincrates/cargo-heather/src/comment.rs: extend the PowerShell match arm to additionally acceptpsd1andpsm1(case-insensitive, matching existing arms).FileKind::PowerShellandlib.rsmodule docs updated to enumerate the supported PowerShell extensions.crates/cargo-heather/README.mdbrought up to date — it previously claimed only.rsand.tomlwere supported (pre-dated even.ps1,.just, andconstants.env).The downstream scanner in
src/bin/cargo-heather/scanner.rsfilters viaCommentStyle::from_path(path).is_some(), which delegates toFileKind::detect; comment-style mapping forFileKind::PowerShellwas alreadyCommentStyle::Hash. So extendingdetectis sufficient — no scanner or fix-mode changes needed.Tests
comment::testsexercisingFileKind::detectfor.ps1,.psd1,.psm1(mixed case), plus a negative test asserting we did not start matching on substrings like.ps,.psd,.psm.scanner_includes_legacy_hash_comment_file_types(integration) now includesSettings.psd1andModule.psm1fixtures and assertsChecking 6 file(s).scanner_reports_missing_header_in_powershell_data_fileand…_module_file) lock in the regression: a missing header on a.psd1/.psm1is detected and reported, not silently skipped.cargo test -p cargo-heatherpasses (25 unit + 19 integration + 5 ms-mit + 3 toml + 3 script + 7 etc.; no failures).cargo clippy -p cargo-heather --all-targets -- -D warningsclean.just format-checkand the workspacecargo heatherrun both clean.Backwards compatibility
Purely additive. Existing
.ps1,.toml,.rs,justfile,constants.envbehaviour is unchanged. Users with.psd1/.psm1files in their tree that previously had no header will see newMISSING headerdiagnostics on their next run — that is the desired behaviour (the previous silent skip was the defect).