cucumber / gherkin-utils

API for working with Gherkin documents
MIT License
9 stars 4 forks source link

Create a static method to pretty print gherkin #4

Closed nddipiazza closed 3 months ago

nddipiazza commented 2 years ago

I find myself wishing there was a simple SDK with the ability to pretty print (format) gherkin files.

Like how intellij cucumber plugin formats them is exactly what I want.

Is there some way to add a simple static method for this?

GherkinFormatter.prettyPrint(gherkinString)

I think there is a way to do this with the library, but it's not as simple.

mpkorstanje commented 2 years ago

I've moved this to the common repo where gherkin is maintained.

aurelien-reeves commented 2 years ago

There is a pretty method implemented in javascript. Would that fit your needs?

There is also https://github.com/cucumber/common/pull/1555 which work in enhancing that pretty method.

nddipiazza commented 2 years ago

I had originally opened this ticket in the cucumber-jvm project. it's there that I really need this. this was moved to the generic cucumber project which loses that fact.

aurelien-reeves commented 2 years ago

I considered the fact that you opened it in cucumber-jvm first. Maybe the javascript version for gherkin-utils would had fit your needs

aurelien-reeves commented 2 years ago

Did you consider the possibility to use cucumber-jvm to get the messages in the form of ndjson to use those as an input in javascript implementation of gherkin and then get the gherkinDocument to use with gherkin-utils?

mpkorstanje commented 2 years ago

@nddipiazza what are you trying to achieve. You've described a solution, but not your problem. What are you trying to achieve by pretty formatting gherkin files?

nddipiazza commented 2 years ago

@mpkorstanje I have a java program that processes gherkin files. A portion of my java program needs to be able to, given a gherkin string, source format that gherkin. Most importantly so that the Test Data table is formatted pretty. Can this be done simply?

mpkorstanje commented 2 years ago

Is there a reason it has to be done in Java?

We currently don't have any such function in Java. We do have a function that does it in Javascript. If it absolutely has to be Java then I guess you could port it. The structure isn't too different.

https://github.com/cucumber/common/blob/main/gherkin-utils/javascript/src/pretty.ts

nddipiazza commented 2 years ago

Yeah unfortunately in my case java is a requirement because my app server is java and there is no js engine available.

aurelien-reeves commented 2 years ago

I think that could be nice to port gherkin-utils to other languages. That's why I've added the "Help wanted" badge :)

nddipiazza commented 2 years ago

I could take a stab at it. there's not much code there. But i'm super weak with ts. So it'll take me a while

laeubi commented 2 years ago

Would be helpfull for IDEs as well!

aurelien-reeves commented 2 years ago

Short reminder: if anyone would need any kind of help, feel free to join our community slack. You'll find plenty of developers ready to help.

If for any reason you would not or can not join slack, we will find other way to provide any kind of help. It can be as part of this issue, or a pull-request, or something else? Are you using some tools which you would keep using? We can certainly join you there. Really, feel free to ask! We're here to help :smiley:

aslakhellesoy commented 2 years ago

We now have a pretty(GherkinDocument) -> string function implemented in TypeScript.

For implementations in other languages, please make a gherkin-utils/[language] implementation based on the same design (using a walkGherkinDocument function).

nddipiazza commented 2 years ago

@aslakhellesoy here you go - https://github.com/cucumber/common/pull/1725 Is there someone who can help me put it in the CircleCI and cover producing a release artifact etc?

aslakhellesoy commented 2 years ago

Great stuff @nddipiazza - let's continue the discussion in cucumber/common#1725

jamietanna commented 2 years ago

FYI we're making good progress with this, but there are still a few areas I think we should improve on before we can say this is done - see cucumber/common#2024 for some Gherkin we'd want to finalise the prety-printing for before saying this is "ready"

This is something that isn't solved by my own library https://gitlab.com/jamietanna/gherkin-formatter/ so this isn't me holding things up - I'd love for us to solve it in here :+1:

kieran-ryan commented 3 months ago

@mpkorstanje, wonder can this be closed? The Java implementation now satisfies the original request, if not mistaken.

https://github.com/cucumber/gherkin-utils/blob/7766139a7e854ecc619dfc5e69448055cafab159/java/src/main/java/io/cucumber/gherkin/utils/pretty/Pretty.java#L8-L28

mpkorstanje commented 3 months ago

Seems good enough to me.