Skip to content

feat: add support for formatting code from stdin#390

Merged
taylorotwell merged 2 commits into
laravel:mainfrom
calebdw:calebdw/push-uuoslosvrquu
Aug 12, 2025
Merged

feat: add support for formatting code from stdin#390
taylorotwell merged 2 commits into
laravel:mainfrom
calebdw:calebdw/push-uuoslosvrquu

Conversation

@calebdw

@calebdw calebdw commented Aug 8, 2025

Copy link
Copy Markdown
Contributor

Hello!

Resolves #262, resolves #162

There's tools and editors (e.g., zed, https://jj-vcs.github.io/jj/latest/cli-reference/#jj-fix) that can integrate with formatters if the formatter accepts input on stdin and outputs the changes on stdout. This PR adds that functionality to pint

CC: @TheBlckbird, @bilogic, @serbanrobu, @gabrielbidula

Thanks!

@calebdw calebdw force-pushed the calebdw/push-uuoslosvrquu branch 4 times, most recently from d829949 to 36b8285 Compare August 8, 2025 07:05
@calebdw calebdw marked this pull request as draft August 8, 2025 07:08
@calebdw calebdw force-pushed the calebdw/push-uuoslosvrquu branch 14 times, most recently from 19300d7 to e3070f6 Compare August 8, 2025 16:10
@calebdw calebdw marked this pull request as ready for review August 8, 2025 16:10
@calebdw calebdw force-pushed the calebdw/push-uuoslosvrquu branch from e3070f6 to 94d74e9 Compare August 8, 2025 16:19
@calebdw calebdw force-pushed the calebdw/push-uuoslosvrquu branch from 94d74e9 to 9a6f156 Compare August 8, 2025 16:23
@taylorotwell taylorotwell merged commit 06dca19 into laravel:main Aug 12, 2025
0 of 6 checks passed
@calebdw

calebdw commented Aug 12, 2025

Copy link
Copy Markdown
Contributor Author

Thank you sir!

@saade

saade commented Sep 18, 2025

Copy link
Copy Markdown

This PR somehow breaks the Laravel Pint as well the official Laravel VSCode extensions.

For context:
open-southeners/vscode-laravel-pint#79

@calebdw

calebdw commented Sep 18, 2025

Copy link
Copy Markdown
Contributor Author

@saade, that means that there's input on STDIN when vscode is trying to run pint

@crynobone

Copy link
Copy Markdown
Member

As this is currently breaking for PHPStorm and VSCode I believe we should revert it for now and work to either:

  1. have this integrated in next major release
  2. Use --stdout and optional --no-stdout to avoid breaking changes

@calebdw

calebdw commented Sep 19, 2025

Copy link
Copy Markdown
Contributor Author

There's already a fix on the other side, the problem is that they have stdin open when it should not be

@crynobone

Copy link
Copy Markdown
Member

@calebdw can you share the link to progress on PHPStorm and VSCode?

@calebdw

calebdw commented Sep 19, 2025

Copy link
Copy Markdown
Contributor Author

@crynobone

crynobone commented Sep 19, 2025

Copy link
Copy Markdown
Member

for PHPStorm? This is still a big issue for developers running on PHPStorm

@calebdw

calebdw commented Sep 19, 2025

Copy link
Copy Markdown
Contributor Author

I haven't seen any mention of PHPStorm and no one I know that uses PHPStorm has said anything about pint not working

@crynobone

Copy link
Copy Markdown
Member

See #401

@calebdw

calebdw commented Sep 19, 2025

Copy link
Copy Markdown
Contributor Author

Hmmm, I suppose you could add a --stdin flag but that's really on them---you should not be calling a cli tool with stdin open if you don't want the tool to potential react to that input

crynobone added a commit that referenced this pull request Sep 19, 2025
@crynobone

crynobone commented Sep 19, 2025

Copy link
Copy Markdown
Member

This reverted for now, and as suggested earlier:

  1. Have this integrated in next major release (PR to develop branch)
  2. Use --stdin to enable stdin when available and the optional --no-stdin (default)
  3. Other suggestions that avoid breaking changes are welcomed

This gives IDE and IDE plugins developers time to support the new feature without locking everyone on an old version.

A909M pushed a commit to A909M/fork-pint that referenced this pull request Sep 30, 2025
* feat: add support for formatting code from stdin

* Formatting

---------

Co-authored-by: Taylor Otwell <taylor@laravel.com>
taylorotwell added a commit that referenced this pull request Oct 10, 2025
* feat: add support for formatting code from stdin (#390)

* feat: add support for formatting code from stdin

* Formatting

---------

Co-authored-by: Taylor Otwell <taylor@laravel.com>

* feat: require explicit --stdin flag for stdin input

* feat: add stdin support with dash and stdin-filename option

- 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

* feat(stdin): respect exclusion rules for stdin-filename option

- Add ConfigurationFactory::isPathExcluded() to check file exclusion rules
- Check stdin-filename against default and pint.json exclusions
- Return original code unchanged when path is excluded
- Add comprehensive unit and feature tests for exclusion behavior

* Update DefaultCommand.php

---------

Co-authored-by: Caleb White <cdwhite3@pm.me>
Co-authored-by: Taylor Otwell <taylor@laravel.com>
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.

Format the files using stdio Support for formatter mode

4 participants