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

Create a static method to pretty print gherkin #4

Closed
nddipiazza opened this issue Jul 16, 2021 · 19 comments
Closed

Create a static method to pretty print gherkin #4

nddipiazza opened this issue Jul 16, 2021 · 19 comments
Labels
⚡ enhancement Request for new functionality

Comments

@nddipiazza
Copy link
Contributor

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 mpkorstanje transferred this issue from cucumber/cucumber-jvm Jul 16, 2021
@mpkorstanje
Copy link
Contributor

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

@aurelien-reeves
Copy link
Contributor

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

There is also cucumber/common#1555 which work in enhancing that pretty method.

@nddipiazza
Copy link
Contributor Author

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

mpkorstanje commented Jul 20, 2021

@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
Copy link
Contributor Author

@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
Copy link
Contributor

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
Copy link
Contributor Author

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

@aurelien-reeves
Copy link
Contributor

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

@nddipiazza
Copy link
Contributor Author

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
Copy link

laeubi commented Jul 21, 2021

Would be helpfull for IDEs as well!

@aurelien-reeves
Copy link
Contributor

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 😃

@aslakhellesoy
Copy link
Contributor

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
Copy link
Contributor Author

nddipiazza commented Sep 3, 2021

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

@aslakhellesoy
Copy link
Contributor

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

aslakhellesoy referenced this issue in cucumber/common May 23, 2022
* some initial commits towards https://github.com/cucumber/common/issues/1662

* finish the Pretty document stuff.

* add some gitignores

* code formatting.

* maven-itize the project
do my best at trying to add the make and gherkin-ish stuff

* add more of the other files

* javadoc

* add comments.

* the formatting of numbers on the left side caused differences with intellij's auto formatter which is not good.
fixed a couple other differences between IntelliJ's auto formatter
fixed some comment formatting issues.

* pr review

* handle end of file comments.

* fix broken test

* fix ci issue

* add entry for gherkin-util/java in ci config.yaml

* try to fix config error

* try to fix config error

* try removing it

* Revert "fix ci issue"

This reverts commit a9a30cb.

* more fixes

* fix typo in name

* add commited files for ci

* push untracked files

* fix gherkin patch m2

* fix package names to match project

* push source

* fix remaining issues with make

* push source

* push untracked files

* push untracked files

* Update dependencies and refactor

* Refactor

* Limit API surface area

* Add dependency on gherkin-java

Co-authored-by: Nicholas DiPiazza <nicholas.dipiazza@gmail.com>
Co-authored-by: Nicholas DiPiazza <nicholas.dipiazza@lucidworks.com>
Co-authored-by: Nicholas DiPiazza <nicholas.dipiazza@wpsic.com>
Co-authored-by: Jamie Tanna <github@jamietanna.co.uk>
cukebot referenced this issue in cucumber/gherkin-java May 23, 2022
* some initial commits towards https://github.com/cucumber/common/issues/1662

* finish the Pretty document stuff.

* add some gitignores

* code formatting.

* maven-itize the project
do my best at trying to add the make and gherkin-ish stuff

* add more of the other files

* javadoc

* add comments.

* the formatting of numbers on the left side caused differences with intellij's auto formatter which is not good.
fixed a couple other differences between IntelliJ's auto formatter
fixed some comment formatting issues.

* pr review

* handle end of file comments.

* fix broken test

* fix ci issue

* add entry for gherkin-util/java in ci config.yaml

* try to fix config error

* try to fix config error

* try removing it

* Revert "fix ci issue"

This reverts commit a9a30cb01f60abb6ba572ed8a7f29705554bf936.

* more fixes

* fix typo in name

* add commited files for ci

* push untracked files

* fix gherkin patch m2

* fix package names to match project

* push source

* fix remaining issues with make

* push source

* push untracked files

* push untracked files

* Update dependencies and refactor

* Refactor

* Limit API surface area

* Add dependency on gherkin-java

Co-authored-by: Nicholas DiPiazza <nicholas.dipiazza@gmail.com>
Co-authored-by: Nicholas DiPiazza <nicholas.dipiazza@lucidworks.com>
Co-authored-by: Nicholas DiPiazza <nicholas.dipiazza@wpsic.com>
Co-authored-by: Jamie Tanna <github@jamietanna.co.uk>
cukebot referenced this issue in cucumber/messages-java May 23, 2022
* some initial commits towards https://github.com/cucumber/common/issues/1662

* finish the Pretty document stuff.

* add some gitignores

* code formatting.

* maven-itize the project
do my best at trying to add the make and gherkin-ish stuff

* add more of the other files

* javadoc

* add comments.

* the formatting of numbers on the left side caused differences with intellij's auto formatter which is not good.
fixed a couple other differences between IntelliJ's auto formatter
fixed some comment formatting issues.

* pr review

* handle end of file comments.

* fix broken test

* fix ci issue

* add entry for gherkin-util/java in ci config.yaml

* try to fix config error

* try to fix config error

* try removing it

* Revert "fix ci issue"

This reverts commit a9a30cb01f60abb6ba572ed8a7f29705554bf936.

* more fixes

* fix typo in name

* add commited files for ci

* push untracked files

* fix gherkin patch m2

* fix package names to match project

* push source

* fix remaining issues with make

* push source

* push untracked files

* push untracked files

* Update dependencies and refactor

* Refactor

* Limit API surface area

* Add dependency on gherkin-java

Co-authored-by: Nicholas DiPiazza <nicholas.dipiazza@gmail.com>
Co-authored-by: Nicholas DiPiazza <nicholas.dipiazza@lucidworks.com>
Co-authored-by: Nicholas DiPiazza <nicholas.dipiazza@wpsic.com>
Co-authored-by: Jamie Tanna <github@jamietanna.co.uk>
@jamietanna
Copy link
Contributor

jamietanna commented Jun 26, 2022

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 👍

aurelien-reeves referenced this issue in cucumber-attic/json-to-messages Jun 28, 2022
* some initial commits towards https://github.com/cucumber/common/issues/1662

* finish the Pretty document stuff.

* add some gitignores

* code formatting.

* maven-itize the project
do my best at trying to add the make and gherkin-ish stuff

* add more of the other files

* javadoc

* add comments.

* the formatting of numbers on the left side caused differences with intellij's auto formatter which is not good.
fixed a couple other differences between IntelliJ's auto formatter
fixed some comment formatting issues.

* pr review

* handle end of file comments.

* fix broken test

* fix ci issue

* add entry for gherkin-util/java in ci config.yaml

* try to fix config error

* try to fix config error

* try removing it

* Revert "fix ci issue"

This reverts commit a9a30cb01f60abb6ba572ed8a7f29705554bf936.

* more fixes

* fix typo in name

* add commited files for ci

* push untracked files

* fix gherkin patch m2

* fix package names to match project

* push source

* fix remaining issues with make

* push source

* push untracked files

* push untracked files

* Update dependencies and refactor

* Refactor

* Limit API surface area

* Add dependency on gherkin-java

Co-authored-by: Nicholas DiPiazza <nicholas.dipiazza@gmail.com>
Co-authored-by: Nicholas DiPiazza <nicholas.dipiazza@lucidworks.com>
Co-authored-by: Nicholas DiPiazza <nicholas.dipiazza@wpsic.com>
Co-authored-by: Jamie Tanna <github@jamietanna.co.uk>
aurelien-reeves referenced this issue in cucumber/messages Jun 29, 2022
* some initial commits towards https://github.com/cucumber/common/issues/1662

* finish the Pretty document stuff.

* add some gitignores

* code formatting.

* maven-itize the project
do my best at trying to add the make and gherkin-ish stuff

* add more of the other files

* javadoc

* add comments.

* the formatting of numbers on the left side caused differences with intellij's auto formatter which is not good.
fixed a couple other differences between IntelliJ's auto formatter
fixed some comment formatting issues.

* pr review

* handle end of file comments.

* fix broken test

* fix ci issue

* add entry for gherkin-util/java in ci config.yaml

* try to fix config error

* try to fix config error

* try removing it

* Revert "fix ci issue"

This reverts commit a9a30cb01f60abb6ba572ed8a7f29705554bf936.

* more fixes

* fix typo in name

* add commited files for ci

* push untracked files

* fix gherkin patch m2

* fix package names to match project

* push source

* fix remaining issues with make

* push source

* push untracked files

* push untracked files

* Update dependencies and refactor

* Refactor

* Limit API surface area

* Add dependency on gherkin-java

Co-authored-by: Nicholas DiPiazza <nicholas.dipiazza@gmail.com>
Co-authored-by: Nicholas DiPiazza <nicholas.dipiazza@lucidworks.com>
Co-authored-by: Nicholas DiPiazza <nicholas.dipiazza@wpsic.com>
Co-authored-by: Jamie Tanna <github@jamietanna.co.uk>
mattwynne referenced this issue Nov 19, 2022
* some initial commits towards https://github.com/cucumber/common/issues/1662

* finish the Pretty document stuff.

* add some gitignores

* code formatting.

* maven-itize the project
do my best at trying to add the make and gherkin-ish stuff

* add more of the other files

* javadoc

* add comments.

* the formatting of numbers on the left side caused differences with intellij's auto formatter which is not good.
fixed a couple other differences between IntelliJ's auto formatter
fixed some comment formatting issues.

* pr review

* handle end of file comments.

* fix broken test

* fix ci issue

* add entry for gherkin-util/java in ci config.yaml

* try to fix config error

* try to fix config error

* try removing it

* Revert "fix ci issue"

This reverts commit a9a30cb01f60abb6ba572ed8a7f29705554bf936.

* more fixes

* fix typo in name

* add commited files for ci

* push untracked files

* fix gherkin patch m2

* fix package names to match project

* push source

* fix remaining issues with make

* push source

* push untracked files

* push untracked files

* Update dependencies and refactor

* Refactor

* Limit API surface area

* Add dependency on gherkin-java

Co-authored-by: Nicholas DiPiazza <nicholas.dipiazza@gmail.com>
Co-authored-by: Nicholas DiPiazza <nicholas.dipiazza@lucidworks.com>
Co-authored-by: Nicholas DiPiazza <nicholas.dipiazza@wpsic.com>
Co-authored-by: Jamie Tanna <github@jamietanna.co.uk>
@mattwynne mattwynne transferred this issue from cucumber/common Nov 20, 2022
@kieran-ryan kieran-ryan added the ⚡ enhancement Request for new functionality label Jan 22, 2024
@kieran-ryan
Copy link
Member

kieran-ryan commented Mar 23, 2024

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

public class Pretty {
/**
* Pretty print a GherkinDocument as either markdown or gherkin.
*
* @param gherkinDocument The GherkinDocument object.
* @param syntax What syntax do you want to format to?
* @return The pretty printed string representation of the Gherkin doc in the syntax indicated.
*/
public static String prettyPrint(GherkinDocument gherkinDocument, Syntax syntax) {
WalkGherkinDocument<Result> walker = new WalkGherkinDocument<>();
Result result = walker.walkGherkinDocument(
gherkinDocument,
new Result(),
new PrettyHandlers(new ArrayList<>(gherkinDocument.getComments()), syntax)
);
return result.toString();
}
private Pretty() {
}
}

@mpkorstanje
Copy link
Contributor

Seems good enough to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⚡ enhancement Request for new functionality
Projects
None yet
Development

No branches or pull requests

7 participants