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

4 participants
@axetroy
Copy link
Contributor

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.

Show resolved Hide resolved prettier/main.ts Outdated
Show resolved Hide resolved prettier/main.ts Outdated

axetroy added some commits Jun 20, 2019

@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 added some commits Jun 24, 2019

axetroy added some commits 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

This comment has been minimized.

Copy link
Contributor Author

commented Jun 25, 2019

/cc @ry it's ready for review.

Show resolved Hide resolved prettier/main.ts Outdated
@kt3k

This comment has been minimized.

Copy link
Contributor

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

This comment has been minimized.

Copy link
Contributor Author

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?

Show resolved Hide resolved prettier/main_test.ts Outdated
Show resolved Hide resolved prettier/main_test.ts Outdated
Show resolved Hide resolved prettier/main_test.ts Outdated
@kt3k

This comment has been minimized.

Copy link
Contributor

commented Jun 30, 2019

The help message looks good to me.

axetroy added some commits Jun 30, 2019

@kt3k

kt3k approved these changes Jun 30, 2019

Copy link
Contributor

left a comment

LGTM

@ry

ry approved these changes Jun 30, 2019

Copy link
Contributor

left a comment

LGTM

@ry ry merged commit 85db520 into denoland:master Jun 30, 2019

5 checks passed

denoland.deno_std Build #20190630.9 succeeded
Details
denoland.deno_std (Linux) Linux succeeded
Details
denoland.deno_std (Mac) Mac succeeded
Details
denoland.deno_std (Windows) Windows succeeded
Details
license/cla Contributor License Agreement is signed.
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.