Skip to content

fix: enforce LF line endings for PowerShell files (#1081)#1092

Merged
rjmurillo merged 8 commits intomainfrom
fix/1081-ps1-line-endings
Apr 5, 2026
Merged

fix: enforce LF line endings for PowerShell files (#1081)#1092
rjmurillo merged 8 commits intomainfrom
fix/1081-ps1-line-endings

Conversation

@rjmurillo
Copy link
Copy Markdown
Owner

@rjmurillo rjmurillo commented Mar 16, 2026

Description

Pre-push hook fails with a PowerShell parse error in Scan-TodoComments.ps1, blocking all pushes. The <# ... #> block comment terminator includes a trailing \r under CRLF, which PowerShell cannot parse when invoked from Git Bash or Unix shells.

Fixes #1081

Motivation and Context

All pushes were blocked unless bypassed with --no-verify. The .gitattributes enforced eol=lf for .githooks/** but PowerShell scripts under build/scripts/ inherited text=auto, producing CRLF on Windows checkouts.

Changes Made

  • Add *.ps1, *.psm1, *.psd1 with text eol=lf to .gitattributes (Scripts section)
  • Add [*.{ps1,psm1,psd1}] section to .editorconfig with end_of_line = lf
  • Add ADR-010 documenting the decision rationale, alternatives considered, and Authenticode signing trade-off
  • Update Serena architecture-decision-records memory index

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Refactoring (no functional changes)
  • Documentation update
  • Build or CI configuration change

Checklist

  • I have met all requirements in CONTRIBUTING.md
  • I have added tests that prove my fix is effective or my feature works
  • I have updated documentation where appropriate

Post-Merge Action

Contributors with existing checkouts should run:

git add --renormalize . && git checkout .

Or perform a fresh clone. This applies the new LF line ending rules to locally cached CRLF copies.

Summary by CodeRabbit

  • Chores

    • Updated repository configuration to enforce LF line endings for PowerShell script files.
    • Improved the pre-commit hook’s handling of collected paths to make repository checks more reliable.
  • Documentation

    • Added an Architecture Decision Record documenting the decision, rationale, and implementation notes for using LF line endings for PowerShell files.

Pre-push hook failed because Scan-TodoComments.ps1 had CRLF line
endings. PowerShell block comment terminators (#>) include a trailing
\r under CRLF, causing parse failures from Git Bash and Unix shells.

Add *.ps1, *.psm1, *.psd1 with text eol=lf to .gitattributes and
a corresponding editorconfig section. Document the decision in
ADR-010.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 16, 2026 04:16
@chatgpt-codex-connector
Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical bug where pre-push hooks failed due to PowerShell parse errors caused by CRLF line endings in scripts when run in non-Windows environments. By enforcing LF line endings for all PowerShell files via .gitattributes and .editorconfig, the change ensures cross-platform compatibility and prevents future parsing issues, thereby unblocking development workflows.

Highlights

  • Enforced LF Line Endings for PowerShell: Configured .gitattributes and .editorconfig to mandate LF (Line Feed) line endings for all PowerShell script files (.ps1, .psm1, .psd1) to resolve cross-platform parsing issues.
  • Documented Decision with ADR-010: Introduced a new Architecture Decision Record (ADR-010) to formally document the rationale, alternatives considered, and consequences of enforcing LF line endings for PowerShell files.
  • Updated ADR Index: The memory index for architecture decision records was updated to include the newly added ADR-010.
Changelog
  • .editorconfig
    • Added a new section [*.{ps1,psm1,psd1}] to enforce end_of_line = lf, indent_size = 4, and insert_final_newline = true for PowerShell files.
  • .gitattributes
    • Added *.ps1 text eol=lf, *.psm1 text eol=lf, and *.psd1 text eol=lf rules to explicitly set Line Feed as the end-of-line character for PowerShell scripts.
  • .serena/memories/architecture-decision-records.md
    • Included an entry for ADR-010 | Use eol=lf for PowerShell Files in .gitattributes with a "Proposed" status.
  • docs/architecture/ADR-010-eol-lf-for-powershell-files.md
    • Created a new Architecture Decision Record (ADR-010) detailing the context, decision, consequences (positive and negative), alternatives considered, and implementation notes for enforcing LF line endings in PowerShell files.
Activity
  • The pull request was created to fix a critical bug related to PowerShell script parsing errors in cross-platform environments.
  • The author provided a detailed description outlining the problem, motivation, changes made, and a post-merge action for contributors.
  • The pull request includes a new Architecture Decision Record (ADR) to document the rationale behind the line ending enforcement.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 16, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: bed1b804-2170-4469-9b7c-4bd88ad5c41a

📥 Commits

Reviewing files that changed from the base of the PR and between 4719073 and 0d3fcc5.

📒 Files selected for processing (2)
  • .githooks/hooks/Invoke-PreCommit.ps1
  • docs/architecture/ADR-010-eol-lf-for-powershell-files.md

📝 Walkthrough

Walkthrough

Adds PowerShell-specific eol and formatting rules to .editorconfig and .gitattributes, documents the decision in ADR-010, and changes array construction in the pre-commit hook script to use explicit array subexpressions (@(...)). No public API or executable logic behavior changed beyond hook input collection and repository file normalization guidance.

Changes

Cohort / File(s) Summary
Config: editorconfig / gitattributes
.editorconfig, .gitattributes
Added PowerShell file patterns (*.ps1, *.psm1, *.psd1) with eol = lf, 4-space indent and final newline settings; added comments explaining rationale.
Docs / ADR
docs/architecture/ADR-010-eol-lf-for-powershell-files.md, .serena/memories/architecture-decision-records.md
Added ADR-010 documenting decision to enforce LF for PowerShell files, rationale, consequences, and implementation/verification notes; updated ADR index.
Git hooks
.githooks/hooks/Invoke-PreCommit.ps1
Replaced implicit array capture with explicit array subexpressions (@(...)) when collecting path lists (e.g., $includePaths, $fullPaths) to ensure arrays are produced consistently.

Sequence Diagram(s)

(omitted — changes are configuration/docs and a small hook data-structure adjustment; no new multi-component control flow requiring visualization)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • MattKotsenas
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: enforcing LF line endings for PowerShell files to fix the parse error.
Description check ✅ Passed The description comprehensively covers all required template sections including motivation, changes made, type of change, and checklist items.
Linked Issues check ✅ Passed The PR successfully addresses all objectives from issue #1081: enforces LF line endings for PowerShell files, fixes the parse error, and provides configuration changes to prevent future CRLF issues.
Out of Scope Changes check ✅ Passed Changes to Invoke-PreCommit.ps1 with explicit array syntax are related to fixing pre-commit hook hang; all changes support the primary objective of resolving hook failures.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/1081-ps1-line-endings
📝 Coding Plan
  • Generate coding plan for human review comments

Comment @coderabbitai help to get the list of available commands and usage tips.

@deepsource-io
Copy link
Copy Markdown

deepsource-io bot commented Mar 16, 2026

DeepSource Code Review

We reviewed changes in 2dbd090...681b435 on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.

See full review on DeepSource ↗

PR Report Card

Overall Grade   Security  

Reliability  

Complexity  

Hygiene  

Code Review Summary

Analyzer Status Updated (UTC) Details
C# Apr 5, 2026 4:52a.m. Review ↗

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly enforces LF line endings for PowerShell scripts by updating .gitattributes and .editorconfig. It also introduces a well-documented Architecture Decision Record (ADR-010) to explain the rationale. My review focuses on ensuring consistency within the new ADR and its corresponding index entry. I've identified a few minor issues: inconsistent status metadata, a future date in the ADR, and a planned documentation update to CONTRIBUTING.md that appears to be missing from this PR.

| ADR-007 | Prefer RegisterOperationAction Over RegisterSyntaxNodeAction | Accepted |
| ADR-008 | BenchmarkDotNet and PerfDiff for Performance Regression Detection | Accepted |
| ADR-009 | xUnit with Roslyn Test Infrastructure | Accepted |
| ADR-010 | Use eol=lf for PowerShell Files in .gitattributes | Proposed |
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.

medium

The status for ADR-010 is Proposed, which is inconsistent with the ADR's frontmatter status of Accepted. Since this PR implements the decision, this should be updated to Accepted for consistency.

Suggested change
| ADR-010 | Use eol=lf for PowerShell Files in .gitattributes | Proposed |
| ADR-010 | Use eol=lf for PowerShell Files in .gitattributes | Accepted |

Comment thread docs/architecture/ADR-010-eol-lf-for-powershell-files.md
Comment thread docs/architecture/ADR-010-eol-lf-for-powershell-files.md Outdated

- **IMP-001**: Add the three glob rules (`*.ps1`, `*.psm1`, `*.psd1`) to `.gitattributes` in the file-type section alongside existing extension-based rules.
- **IMP-001a**: Add a corresponding `[*.{ps1,psm1,psd1}]` section to `.editorconfig` with `end_of_line = lf` so editors enforce LF on save, preventing CRLF from being introduced during editing.
- **IMP-002**: After pulling the merged fix, contributors should run `git add --renormalize . && git checkout .` to apply the new line ending rules. Alternatively, a fresh clone applies the rules automatically. Document this in the PR description and CONTRIBUTING.md.
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.

medium

This implementation note states that CONTRIBUTING.md should be updated to include the git add --renormalize . command for existing contributors. However, CONTRIBUTING.md was not modified in this pull request. Please either update the file as planned or remove this part of the implementation note if it's intended to be handled separately.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a pre-push hook failure (#1081) caused by CRLF line endings in PowerShell scripts breaking block comment parsing when invoked from Git Bash or Unix shells. The fix enforces LF line endings for all PowerShell files via .gitattributes and .editorconfig, and documents the decision in a new ADR.

Changes:

  • Add *.ps1, *.psm1, *.psd1 with text eol=lf to .gitattributes and a matching end_of_line = lf section to .editorconfig
  • Add ADR-010 documenting the rationale, alternatives, and trade-offs for this line-ending policy
  • Update the Serena memory index with the new ADR entry

Reviewed changes

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

File Description
.gitattributes Adds LF line ending enforcement for PowerShell file extensions
.editorconfig Adds PowerShell section with end_of_line = lf and formatting defaults
docs/architecture/ADR-010-eol-lf-for-powershell-files.md New ADR documenting the decision to use LF for PowerShell files
.serena/memories/architecture-decision-records.md Adds ADR-010 to the memory index

You can also share your feedback on Copilot code review. Take the survey.


## Status

Proposed
| ADR-007 | Prefer RegisterOperationAction Over RegisterSyntaxNodeAction | Accepted |
| ADR-008 | BenchmarkDotNet and PerfDiff for Performance Regression Detection | Accepted |
| ADR-009 | xUnit with Roslyn Test Infrastructure | Accepted |
| ADR-010 | Use eol=lf for PowerShell Files in .gitattributes | Proposed |
rjmurillo and others added 2 commits March 15, 2026 23:19
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
The ADR body and Serena memory index both said "Proposed" while the
frontmatter said "Accepted". Align all three to Accepted.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
coderabbitai[bot]
coderabbitai bot previously approved these changes Mar 16, 2026
@MattKotsenas
Copy link
Copy Markdown
Collaborator

This smells fishy to me? If the script uses [Environment]::NewLine it should do the right thing on each platform. I think we're already normalizing to store lf.

That said, I also don't think this breaks anything, I just think forcing lf is working around some other issue rather than fixing the root issue.

If I'm misunderstanding though, please let me know!

PowerShell ForEach-Object returns a scalar string when the pipeline
produces one element. Splatting a string with @variable passes each
character as a separate argument, causing markdownlint-cli2 to hang
at 100% CPU. Wrap all ForEach-Object pipelines in @() to force array
context. Affects md, yaml, workflow, shell, and cs file collections.

Also removes stale CONTRIBUTING.md reference from ADR-010 IMP-002.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@rjmurillo
Copy link
Copy Markdown
Owner Author

This smells fishy to me? If the script uses [Environment]::NewLine it should do the right thing on each platform. I think we're already normalizing to store lf.

That said, I also don't think this breaks anything, I just think forcing lf is working around some other issue rather than fixing the root issue.

If I'm misunderstanding though, please let me know!

This is only failing on Ubuntu when running the git hooks. Will like be fixed with #1097

@rjmurillo-bot rjmurillo-bot enabled auto-merge (squash) March 30, 2026 08:46
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ rjmurillo
❌ rjmurillo-bot
You have signed the CLA already but the status is still pending? Let us recheck it.

@codacy-production
Copy link
Copy Markdown

codacy-production bot commented Mar 31, 2026

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Coverage ∅ diff coverage · +0.00% coverage variation

Metric Results
Coverage variation +0.00% coverage variation (-1.00%)
Diff coverage diff coverage (95.00%)

View coverage diff in Codacy

Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (2dbd090) 2660 2391 89.89%
Head commit (681b435) 2660 (+0) 2391 (+0) 89.89% (+0.00%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#1092) 0 0 ∅ (not applicable)

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

TIP This summary will be updated as you push new changes. Give us feedback

@rjmurillo rjmurillo merged commit 034474c into main Apr 5, 2026
41 of 43 checks passed
@rjmurillo rjmurillo deleted the fix/1081-ps1-line-endings branch April 5, 2026 15:06
@rjmurillo rjmurillo added this to the vNext milestone Apr 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: pre-push hook fails due to Scan-TodoComments.ps1 parse error

5 participants