mapado / prettier-plugin-gherkin

This prettier plugin format your gherkin (`.feature` files) documents.
MIT License
18 stars 5 forks source link

Is there a reason to add a blank line after a given? #15

Closed murdos closed 11 months ago

murdos commented 11 months ago

I was going to apply this plugin to my projects (thanks BTW!), until I noticed that blank lines were added systematically after given phrases, which lead to a strange formatting: why make a separate block for given, but not separate when and then blocks?

Before

  Scenario: Should not add beer as user
    Given I am logged in as "user"
    When I add beer to catalog
      | Name       | Cloak of feathers |
      | Unit price | 8.53              |
    Then I should be forbidden

After

  Scenario: Should not add beer as user
    Given I am logged in as "user"

    When I add beer to catalog
      | Name       | Cloak of feathers |
      | Unit price | 8.53              |
    Then I should be forbidden
jdeniau commented 11 months ago

Hi,

Yes I did that on purpose in order to separate the "fixtures" bloc and the real test bloc.

In your case you do have only one given, but you can have something like that :

Given xxx
And yyy
And zzz

When I do aaa
Then bbb
And ccc

I think it does improve the readability of the test file.

murdos commented 11 months ago

Do you think that it could it could be turned off with a configuration parameter? I understand your POV, but this is still quite unusual and controversial :)

jdeniau commented 11 months ago

It might be yes. I will think about it but it may also become the default value :

It you have more than one line break, it would remove extra line break to be only one. If you do not have line break, then the plug-in would keep "as-it" unless you configure the option lineBreakAfterContext to "force" or something like that. In this case, it will force a line break (as it does now).

jdeniau commented 11 months ago

@murdos this has been released as the default value in version 2.2.1 (2.2.0 + two small fixes when I tested on our stack)

See https://github.com/mapado/prettier-plugin-gherkin/blob/b7ccd8e3634d96e5cc79d82c651f040836c07be5/README.md#forcenewlinebetweenstepblocks-default-false

murdos commented 11 months ago

@jdeniau: thanks! :heart: