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

cmd/shfmt: provide a jsonschema for --to-json and --from-json #967

Open
loynoir opened this issue Jan 29, 2023 · 4 comments
Open

cmd/shfmt: provide a jsonschema for --to-json and --from-json #967

loynoir opened this issue Jan 29, 2023 · 4 comments

Comments

@loynoir
Copy link

loynoir commented Jan 29, 2023

feat

shfmt --dump-ast-schema ast.jsonschema.json --dump-ast ast.json

reason

I guess shellcheck and shfmt might be the largest two shellscript-AST-related repos. (Are they?)

Some shellscript AST parser I found seems incomplete.

It would be awesome to re-use shellcheck AST or shfmt AST, from other language.

So no need to workaround some other incomplete shellscript AST parsers.

related

koalaman/shellcheck#2676

@mvdan
Copy link
Owner

mvdan commented Jan 29, 2023

We already have the --to-json flag, for example shfmt --to-json <<<'foo $bar'. There is no jsonschema, but the types are the nodes you can see in https://pkg.go.dev/mvdan.cc/sh/v3/syntax.

There's also --from-json, which ingests the same kind of AST in json form.

@loynoir
Copy link
Author

loynoir commented Jan 29, 2023

@mvdan

The jsonschema request is for generating type definition.

For example, my use case, typescript have great tool to generate type definition from jsonschema.

As swagger and openapi use jsonschema, there should be tools to generate type definition for other language too.

@mvdan mvdan changed the title [feat] shfmt --dump-ast-schema ast.jsonschema.json --dump-ast ast.json cmd/shfmt: provide a jsonschema for --to-json and --from-json Feb 2, 2023
@mvdan
Copy link
Owner

mvdan commented Feb 2, 2023

Sure, I'll look at a jsonschema.

@loynoir
Copy link
Author

loynoir commented Feb 2, 2023

There is https://www.npmjs.com/package/@sinclair/typebox in typescript ecosystem, which write code to get jsonchema and typescript definition at the same time with no need to compile.

I guess there might be something similar within golang system?

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

No branches or pull requests

2 participants