Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prettier: support read code from stdin and output to stdout #498

Merged
merged 54 commits into from
Jun 30, 2019

Conversation

axetroy
Copy link
Contributor

@axetroy axetroy commented Jun 17, 2019

closes #457

Try it out

run in Linux/MacOS

curl https://raw.githubusercontent.com/denoland/deno_std/master/prettier/testdata/0.ts | deno --reload https://github.com/axetroy/deno_std/raw/prettier_stdin/prettier/main.ts

run in Windows

(iwr https://raw.githubusercontent.com/denoland/deno_std/master/prettier/testdata/0.ts).Content | deno --reload https://github.com/axetroy/deno_std/raw/prettier_stdin/prettier/main.ts

Design goals:

curl https://example.com/test.ts | deno fmt
curl https://example.com/test.js | deno fmt --stdin-parser=babel
curl https://example.com/test.json | deno fmt --stdin-parser=json
curl https://example.com/test.md | deno fmt --stdin-parser=markdown

What it changes?

  1. add --stdin flag to read the code from stdin. only use in the test.
  2. add --stdin-parser to set parser. tell prettier what code it is from stdin. default: typescript
  3. catch error and output to stderr instead of stdout

Why I need this feature

I am writing a formatter for justjavac.vscode-deno.

currently, deno fmt is a file-based formatting tool.

But in the IDE/editor not based on files, it may be a temporary string (if the file is modified, but the file is not maintained).

So this PR is for better-integrated development tools.

prettier/main.ts Outdated Show resolved Hide resolved
prettier/main.ts Outdated Show resolved Hide resolved
@axetroy axetroy changed the title prettier: support read code from stdin and output to stdout [WIP] prettier: support read code from stdin and output to stdout Jun 24, 2019
@axetroy axetroy changed the title [WIP] prettier: support read code from stdin and output to stdout prettier: support read code from stdin and output to stdout Jun 25, 2019
@axetroy
Copy link
Contributor Author

axetroy commented Jun 25, 2019

/cc @ry it's ready for review.

prettier/main.ts Outdated Show resolved Hide resolved
@kt3k
Copy link
Member

kt3k commented Jun 29, 2019

I think we should document --stdin-parser and --stdin options in Options: section of help message of prettier/main.ts

@axetroy
Copy link
Contributor Author

axetroy commented Jun 30, 2019

I think we should document --stdin-parser and --stdin options in Options: section of help message of prettier/main.ts

Can you help me see if the documentation for --stdin-parser and --stdin is correct?

prettier/main_test.ts Outdated Show resolved Hide resolved
prettier/main_test.ts Outdated Show resolved Hide resolved
prettier/main_test.ts Outdated Show resolved Hide resolved
@kt3k
Copy link
Member

kt3k commented Jun 30, 2019

The help message looks good to me.

Copy link
Member

@kt3k kt3k left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

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

LGTM

@ry ry merged commit 85db520 into denoland:master Jun 30, 2019
ry pushed a commit to ry/deno that referenced this pull request Oct 9, 2019
inverted-capital pushed a commit to dreamcatcher-tech/napps that referenced this pull request Oct 24, 2024
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.

[Prettier] read code from stdin and output formatted code to stdout
4 participants