antham / ghokin Goto Github PK
View Code? Open in Web Editor NEWParallelized formatter with no external dependencies for gherkin (cucumber, behat...)
License: MIT License
Parallelized formatter with no external dependencies for gherkin (cucumber, behat...)
License: MIT License
Issue:
We want to use latest version of this module as part of toolchain, but the latest version is greater than v0 or v1 and the module name does not specify higher version.
How to reproduce:
execute go get github.com/antham/ghokin
Expected:
require (
github.com/antham/ghokin/v3 v3.1.0
)
Actual:
require (
github.com/antham/ghokin v1.7.0
)
Another option would be do release latest code under v1.8.0 and disregard updating major version in the future and stick to v1
I'd make a PR myself, but the repo doesn't have Makefile
, I am too lazy to launch it myself.
Dependabot couldn't parse the go.mod found at /go.mod
.
The error Dependabot encountered was:
go: github.com/spf13/[email protected] requires
github.com/grpc-ecosystem/[email protected] requires
gopkg.in/[email protected]: invalid version: git fetch -f origin refs/heads/*:refs/heads/* refs/tags/*:refs/tags/* in /opt/go/gopath/pkg/mod/cache/vcs/9241c28341fcedca6a799ab7a465dd6924dc5d94044cbfabb75778817250adfc: exit status 128:
fatal: The remote end hung up unexpectedly
The feature description is indented following indent.tableAndDocString
option which seems strange.
Example of feature file from gherkin reference:
Feature: Multiple site support
Only blog owners can post to a blog, except administrators,
who can post to all blogs.
Background:
Given a global administrator named "Greg"
ghokin fmt stdout:
Feature: Multiple site support
Only blog owners can post to a blog, except administrators,
who can post to all blogs.
Background:
Given a global administrator named "Greg"
I would expect feature description to be indented as much as Background
and Scenario
.
I also suggest to drop separate configuration for indentation and use only a relative indent option:
indent:
level: [0-9]+
character: (space|tab)
Indeed, I am not sure someone will use an asymmetric indentation. However, it will be easier to handle formatting with new feature in gherkin syntax (like the new Rule
keyword):
Feature: Highlander
Rule: There can be only One
Example: Only One -- More than one alive
Given there are 3 ninjas
Also, thank you for this tool!
Thanks for the great formatter!
We faced one issue with removing empty scenarios. Unfortunately, I don't know Go so I can't make PR for this
Feature file:
Feature: A suite 1
Scenario: asdsad asdsad asdsad
Given the user disconnects the water
Scenario: as 123 dsad
Scenario: adsad
Scenario: asds asdsa ad
Result:
Feature: A suite 1
Scenario: asdsad asdsad asdsad
Given the user disconnects the water
Scenario: as 123 dsad
Two backslashes in a table get turned into one. This is annoying as I decode the string and cannot use backslashes this way.
Also this means that running ghokin multiple times gives different results.
Example:
Feature: f
Scenario: s
Given a
| name |
| hello\\\n |
gets formatted into:
Feature: f
Scenario: s
Given a
| name |
| hello\\n |
which in turn gets formatted into
Feature: f
Scenario: s
Given a
| name |
| hello\n |
a feature file with the rule keyword deletes the content of the rule
Rule: Eligible participants must be counted
becomes
Rule
Issue
In tables if we are trying to use special characters, after formatting it will replace special characters to strange ones.
How to reproduce
When I add a comment after a scenario and format it with ghokin, normally it gets indented with 2 spaces (using default config).
But if I add a comment after the last scenario and format it with ghokin, it instead gets indented to the same level as whatever is above it. So if the previous line is a Then indented with 4 spaces, the comment is also indented with 4 spaces. If the previous line is a row in an Examples table indented with 6 spaces, the comment is also indented with 6 spaces.
I've got a situation where I need to use a |
in a table value. Godog accepts a \|
as an escape sequence for the pipe, but Ghokin replaces it with |
, breaking godog and cucumber.js:
Input:
Feature: Test
Scenario: Pipe in table value
Given I have a table:
| a | b \| c |
Output:
Feature: Test
Scenario: Pipe in table value
Given I have a table:
| a | b | c |
Expected:
Feature: Test
Scenario: Pipe in table value
Given I have a table:
| a | b \| c |
Issue
We are trying to format our feature files, but looks like it is not possible if it's encoded with e.g UTF-8 or Unicode.
Update
With further investigations, it turned out that the root of the problem is not the Encoding.
It seems the BOM character is the culprit in this case.
How to reproduce
With BOM
with-bom-character.zip
Without BOM
without-bom-character.zip
$ go version
go version go1.14.9 darwin/amd64
$ go get -v github.com/antham/ghokin
github.com/spf13/cast (download)
github.com/spf13/jwalterweatherman (download)
github.com/subosito/gotenv (download)
get "gopkg.in/ini.v1": found meta tag get.metaImport{Prefix:"gopkg.in/ini.v1", VCS:"git", RepoRoot:"https://gopkg.in/ini.v1"} at //gopkg.in/ini.v1?go-get=1
gopkg.in/ini.v1 (download)
golang.org/x/sys/internal/unsafeheader
github.com/hashicorp/hcl/hcl/strconv
golang.org/x/text/transform
github.com/fatih/color/vendor/github.com/mattn/go-isatty
golang.org/x/sys/unix
github.com/spf13/afero/mem
github.com/mitchellh/go-homedir
github.com/spf13/jwalterweatherman
github.com/subosito/gotenv
gopkg.in/ini.v1
github.com/fatih/color/vendor/github.com/mattn/go-colorable
github.com/hashicorp/hcl/hcl/token
github.com/spf13/cast
github.com/gogo/protobuf/proto
golang.org/x/text/unicode/norm
github.com/pelletier/go-toml
github.com/gofrs/uuid
gopkg.in/yaml.v2
github.com/hashicorp/hcl/hcl/scanner
github.com/hashicorp/hcl/json/token
github.com/hashicorp/hcl/hcl/ast
github.com/fatih/color
github.com/mitchellh/mapstructure
github.com/spf13/pflag
github.com/magiconair/properties
github.com/hashicorp/hcl/json/scanner
github.com/hashicorp/hcl/hcl/parser
github.com/hashicorp/hcl/json/parser
github.com/hashicorp/hcl/hcl/printer
github.com/spf13/afero
github.com/hashicorp/hcl
github.com/fsnotify/fsnotify
github.com/spf13/cobra
github.com/spf13/viper
github.com/gogo/protobuf/io
github.com/cucumber/messages-go
github.com/cucumber/gherkin-go
github.com/antham/ghokin/ghokin
# github.com/antham/ghokin/ghokin
../antham/ghokin/ghokin/transformer.go:41:3: undefined: gherkin.TokenType_FeatureLine
../antham/ghokin/ghokin/transformer.go:42:3: undefined: gherkin.TokenType_BackgroundLine
../antham/ghokin/ghokin/transformer.go:43:3: undefined: gherkin.TokenType_ScenarioLine
../antham/ghokin/ghokin/transformer.go:44:3: undefined: gherkin.TokenType_DocStringSeparator
../antham/ghokin/ghokin/transformer.go:45:3: undefined: gherkin.TokenType_RuleLine
../antham/ghokin/ghokin/transformer.go:46:3: undefined: gherkin.TokenType_StepLine
../antham/ghokin/ghokin/transformer.go:47:3: undefined: gherkin.TokenType_ExamplesLine
../antham/ghokin/ghokin/transformer.go:48:3: undefined: gherkin.TokenType_Other
../antham/ghokin/ghokin/transformer.go:49:3: undefined: gherkin.TokenType_TableRow
../antham/ghokin/ghokin/transformer.go:53:3: undefined: gherkin.TokenType_FeatureLine
../antham/ghokin/ghokin/transformer.go:53:3: too many errors
Is it possible to add a flag that would make the formatter not strip newline characters from the end of the file?
When you format a table that contains \n
, fmt
replaces it with an actual newline instead of outputting the characters \n
again.
Failing testcase: sherter@d6f88c6
--- FAIL: TestTransform (0.00s)
--- FAIL: TestTransform/fixtures/escape-newline.feature (0.00s)
transformer_test.go:471:
Error Trace: /home/simon/repositories/ghokin/ghokin/transformer_test.go:471
Error: Not equal:
expected: "Feature: Test\n\n Scenario: Newline in table value\n Given I have a table:\n | a | b \\n c | \\n d | \\n e \\n |\n | f | g | h | i |\n"
actual : "Feature: Test\n\n Scenario: Newline in table value\n Given I have a table:\n | a | b \n c | \n d | \n e \n |\n | f | g | h | i |\n"
Diff:
--- Expected
+++ Actual
@@ -4,4 +4,8 @@
Given I have a table:
- | a | b \n c | \n d | \n e \n |
- | f | g | h | i |
+ | a | b
+ c |
+ d |
+ e
+ |
+ | f | g | h | i |
Test: TestTransform/fixtures/escape-newline.feature
FAIL
exit status 1
FAIL github.com/antham/ghokin/v3/ghokin 0.113s
According to https://cucumber.io/docs/gherkin/reference/#table-cell-escaping it's valid to use \n
in table cells.
It would be nice if fmt stdout
would accept a directory like fmt replace
does.
It would be an added bonus if there are any changes to be made the tool could exit with a non-zero exit code. This could then be checked when running other tests and fail a build if the files are not correctly formatted.
Showing what would change in the file if replace
was being run instead would also be nice.
Come to think of it, maybe stdout
should stay the same and another option called check
could be introduced.
Let me know if you want me to open separate issues for each thing I mentioned.
Add a command to verify if file/folder are correctly formatted
check
and would take same parameters as replaceDependabot couldn't parse the go.mod found at /go.mod
.
The error Dependabot encountered was:
go: github.com/spf13/[email protected] requires
gopkg.in/[email protected] requires
gopkg.in/[email protected]: invalid version: git fetch -f origin refs/heads/*:refs/heads/* refs/tags/*:refs/tags/* in /opt/go/gopath/pkg/mod/cache/vcs/9241c28341fcedca6a799ab7a465dd6924dc5d94044cbfabb75778817250adfc: exit status 128:
fatal: The remote end hung up unexpectedly
Hey,
would it be possible to add a config parameter to add an extra indentation of AND
?
e.g.:
SCENATRIO ...
GIVEN ....
AND ....
AND ...
WHEN ...
THEN ....
AND ....
Everything are in the title
See sherter@ea0fba4
For each non-ascii character in the table cell, the table column width grows one space larger than it needs to be.
--- FAIL: TestTransform/fixtures/table-with-non-ascii-characters.feature (0.00s)
transformer_test.go:475:
Error Trace: /home/simon/repositories/ghokin/ghokin/transformer_test.go:475
Error: Not equal:
expected: "Feature: A Feature\n Description\n\n Scenario: A scenario to test\n Given a thing\n | äöüûú |\n\n"
actual : "Feature: A Feature\n Description\n\n Scenario: A scenario to test\n Given a thing\n | äöüûú |\n\n"
Diff:
--- Expected
+++ Actual
@@ -5,3 +5,3 @@
Given a thing
- | äöüûú |
+ | äöüûú |
Test: TestTransform/fixtures/table-with-non-ascii-characters.feature
In this example we have 5 non-ascii characters and the column is 5 spaces larger than it needs to be.
Would be much easier to use as a plugin and formatter inside of vim if ghokin could take content from stdin.
I would suggest a max-line-length: 80
option for description. to break long line in multiple lines.
Another idea would be to also add a space-before-description: true
.
With the two options, the file:
Feature: Multiple site support
Only blog owners can post to a blog, except administrators, who can post to all blogs.
Scenario: Dr. Bill tries to post to somebody else's blog, and fails
Given I am logged in as Dr. Bill
would be formatted:
Feature: Multiple site support
Only blog owners can post to a blog, except administrators, who can post to
all blogs.
Scenario: Dr. Bill tries to post to somebody else's blog, and fails
Given I am logged in as Dr. Bill
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.