Skip to content

feat(cargo-heather): recognize .psd1 and .psm1 as PowerShell files - #38

Merged
Sander Saares (sandersaares) merged 4 commits into
mainfrom
feat/cargo-heather-psd1-psm1
Jun 9, 2026
Merged

Sander Saares (sandersaares) merged 4 commits into
mainfrom
feat/cargo-heather-psd1-psm1

Conversation

@sandersaares

@sandersaares Sander Saares (sandersaares) commented Jun 8, 2026 •

Copy link
Copy Markdown
Member

Recognize .psd1 (PowerShell data) and .psm1 (PowerShell module) files as PowerShell sources in FileKind::detect so the scanner checks/fixes their license headers instead of silently skipping them.

Motivation

.psd1 and .psm1 use the same # line-comment syntax as .ps1 scripts 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::detect matched only ps1 so these files were silently dropped during scanning. Running cargo heather against a directory containing .psd1 fixtures with no header reports All N file(s) have correct license headers even though those fixtures were never inspected.

This was observed in microsoft/oxidizer#436 (a new Pester scenario suite landed ~25 .psd1 fixtures without license headers and CI did not catch it).

Change

  • FileKind::detect in crates/cargo-heather/src/comment.rs: extend the PowerShell match arm to additionally accept psd1 and psm1 (case-insensitive, matching existing arms).
  • Doc comments on FileKind::PowerShell and lib.rs module docs updated to enumerate the supported PowerShell extensions.
  • crates/cargo-heather/README.md brought up to date — it previously claimed only .rs and .toml were supported (pre-dated even .ps1, .just, and constants.env).

The downstream scanner in src/bin/cargo-heather/scanner.rs filters via CommentStyle::from_path(path).is_some(), which delegates to FileKind::detect; comment-style mapping for FileKind::PowerShell was already CommentStyle::Hash. So extending detect is sufficient — no scanner or fix-mode changes needed.

Tests

  • 4 unit tests added in comment::tests exercising FileKind::detect for .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 includes Settings.psd1 and Module.psm1 fixtures and asserts Checking 6 file(s).
  • 2 new integration tests (scanner_reports_missing_header_in_powershell_data_file and …_module_file) lock in the regression: a missing header on a .psd1 / .psm1 is detected and reported, not silently skipped.

cargo test -p cargo-heather passes (25 unit + 19 integration + 5 ms-mit + 3 toml + 3 script + 7 etc.; no failures). cargo clippy -p cargo-heather --all-targets -- -D warnings clean. just format-check and the workspace cargo heather run both clean.

Backwards compatibility

Purely additive. Existing .ps1, .toml, .rs, justfile, constants.env behaviour is unchanged. Users with .psd1 / .psm1 files in their tree that previously had no header will see new MISSING header diagnostics on their next run — that is the desired behaviour (the previous silent skip was the defect).

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>
@sandersaares
Sander Saares (sandersaares) marked this pull request as ready for review June 8, 2026 06:46
Copilot AI review requested due to automatic review settings June 8, 2026 06:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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::detect to classify .psd1 and .psm1 (case-insensitive) as FileKind::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.

Comment thread crates/cargo-heather/src/comment.rs Outdated
Comment thread crates/cargo-heather/README.md Outdated
…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>
Comment thread crates/cargo-heather/README.md Outdated
…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>
Copilot AI review requested due to automatic review settings June 8, 2026 13:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

@codecov-commenter

Codecov Comments Bot (codecov-commenter) commented Jun 9, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.2%. Comparing base (48e192e) to head (17f9709).

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.
📢 Have feedback on the report? Share it here.

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

@sandersaares
Sander Saares (sandersaares) merged commit 270c4c7 into main Jun 9, 2026
25 checks passed
@sandersaares
Sander Saares (sandersaares) deleted the feat/cargo-heather-psd1-psm1 branch June 9, 2026 13:21
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.

8 participants