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

Formatter introduces newlines in awkward places with comments #40

Open
xeger opened this issue Oct 15, 2023 · 0 comments
Open

Formatter introduces newlines in awkward places with comments #40

xeger opened this issue Oct 15, 2023 · 0 comments
Labels
🐛 bug Defect / Bug

Comments

@xeger
Copy link
Member

xeger commented Oct 15, 2023

👓 What did you see?

When a scenario block has a comment block above it, the formatter add a newline between the comments and the block, instead of adding it above the comments.

As a result, the comments look like they're associated with the previous Gherkin statement.

Feature: comments
  # This is a leading comment of the scenario

  Scenario: leading comments

✅ What did you expect to see?

When the formatter adds newlines between Gherkin statements, it should be mindful of their associated comments blocks.

Feature: comments

  # This is a leading comment of the scenario
  Scenario: leading comments

There is a chance for semantic ambiguity, because comments could in theory be intended as "trailing" comments.

Feature: comments
# This is a trailing comment associated with the feature.

  # This is a leading comment of the scenario
  Scenario: leading comments

The only way we can tell that line 2 is a trailing feature comment is by examining the indentation of the # character.

There's a similar chance for ambiguity if steps within a container are commented out (which is a common occurrence during debugging).

Feature: comments

  Scenario: commented-out steps
    Given something
    # When I do something
    Then I see something

However, commented-out steps are probably not an issue because the formatter never inserts newlines between a step container and its sub-blocks.

📦 Which tool/library version are you using?

Version 8.0.5 of this package.

🔬 How could we reproduce it?

See the groupedComments branch for a failing test case.

📚 Any additional context?

I understand that the pretty() function in gherkin-utils is considered non-canonical and that we should be using formatters that operate on the JSON representation of gherkin ASTs.

Before putting too much work into fixing this bug, we should consider whether there is a better formatter available in the Cucumber Collective ecosystem, and/or whether to reimplement this formatter using the newer parsing utilities.

@kieran-ryan kieran-ryan added the 🐛 bug Defect / Bug label Jan 22, 2024
@kieran-ryan kieran-ryan mentioned this issue Apr 11, 2024
5 tasks
@kieran-ryan kieran-ryan changed the title Formatter adds newlines in awkward places when comments are used Formatter introduces newlines in awkward places with comments Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Defect / Bug
Projects
None yet
Development

No branches or pull requests

2 participants