Skip to content

Conversation

A909M
Copy link

@A909M A909M commented Sep 29, 2025

Hey team,

This brings back stdin support from #390, but with an explicit --stdin flag to avoid the
breaking changes that caused the revert.

The Problem

The original implementation would automatically read from stdin if it was available, which
broke VSCode and PHPStorm extensions since they were inadvertently leaving stdin open when
calling pint.

What Changed

Now you need to explicitly pass --stdin to enable stdin mode. This means existing tools
won't break, and editors can opt-in when they're ready.

You can also pass a file path along with --stdin for better config resolution:

# Basic usage
cat file.php | pint --stdin
# With file path (useful for editors like Zed)
pint app/Models/User.php --stdin < app/Models/User.php

In stdin mode, pint outputs only the formatted code to stdout (no summary), which is what
editors expect.

Testing

Added comprehensive tests covering:

  • Basic stdin formatting
  • Works with --silent, --test, --format flags
  • Path argument for config resolution
  • Empty stdin handling

All existing tests still pass.

Zed Integration Example

"languages": {
    "PHP": {
      "format_on_save": "on",
      "formatter": {
        "external": {
          "command": "vendor/bin/pint",
          "arguments": ["{buffer_path}", "--stdin"]
        }
      }
    }
  }

Fixes the issues raised in #402 and implements the solution suggested in #390.

@A909M
Copy link
Author

A909M commented Sep 30, 2025

@crynobone

@taylorotwell
Copy link
Member

Why is there so much more code than the original PR?

@taylorotwell taylorotwell marked this pull request as draft September 30, 2025 10:24
calebdw and others added 2 commits September 30, 2025 16:26
* feat: add support for formatting code from stdin

* Formatting

---------

Co-authored-by: Taylor Otwell <[email protected]>
@A909M A909M force-pushed the feat/stdin-support branch from 90ee57a to 02096d4 Compare September 30, 2025 13:50
@A909M A909M changed the base branch from develop to main September 30, 2025 14:00
@A909M
Copy link
Author

A909M commented Sep 30, 2025

Why is there so much more code than the original PR?

Ha, yeah... I definitely over-engineered that. My bad.

Started fresh with the original PR and just swapped the auto-detection for the flag check.
Kept it simple this time - added the --stdin option and updated tests to use it.

Ready for review!

@A909M A909M marked this pull request as ready for review September 30, 2025 14:18
@taylorotwell
Copy link
Member

@calebdw any feedback on this? 🙏

@calebdw
Copy link
Contributor

calebdw commented Sep 30, 2025

This is fine I suppose, there's many ways to go about this.

It's also pretty standard to read from STDIN when - is passed as the filename. Black also allows a --stdin-filename to allow passing what the filename should be (to respect any ignores) when passing in the data on stdin

Not saying we have to do all that, just food for thought.

@taylorotwell
Copy link
Member

I like the idea of using stdin if - is passed as the file name. cc @A909M

@taylorotwell taylorotwell marked this pull request as draft October 8, 2025 21:20
@calebdw
Copy link
Contributor

calebdw commented Oct 8, 2025

If we're going with - for stdin, then likely need --stdin-filename so that files that should be ignored will be ignored

@A909M
Copy link
Author

A909M commented Oct 8, 2025

Sounds good! I'll update it to use - for stdin and add --stdin-filename for the path
context. Working on it now.

@A909M
Copy link
Author

A909M commented Oct 9, 2025

@calebdw @taylorotwell Done! Using - for stdin with --stdin-filename option as suggested.

Re: exclusions - Stdin input is formatted regardless of exclusion patterns (like
Black/Prettier). --stdin-filename provides context for config and error messages, which is
what editors need.

Zed editor example:

{
  "languages": {
    "PHP": {
      "formatter": {
        "external": {
          "command": "vendor/bin/pint",
          "arguments": ["--stdin-filename", "{buffer_path}"]
        }
      }
    }
  }
}

@A909M A909M marked this pull request as ready for review October 9, 2025 03:09
@A909M A909M force-pushed the feat/stdin-support branch from 123b3fa to efff729 Compare October 9, 2025 03:18
- Replace --stdin flag with Unix-standard dash (-) for stdin input
- Add --stdin-filename option for editor integration and context
- Support both 'pint -' and 'pint --stdin-filename' patterns
- Add comprehensive tests for stdin formatting scenarios
@A909M A909M force-pushed the feat/stdin-support branch from efff729 to e9e318d Compare October 9, 2025 03:22
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.

3 participants