-
-
Notifications
You must be signed in to change notification settings - Fork 5
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
Pretty comments #75
base: main
Are you sure you want to change the base?
Pretty comments #75
Conversation
Didn't look at the code (yet).
No clue unfortunately. Markdown was an experimental feature. I don't think it is used much. I would leave it out of scope.
Good question. If the API didn't change, it would be an added feature going by Semver.
I think the following would be a reasonable guideline: Comments should be indented at the level of the next named element in the AST. If there is no next element, then no indentation. This keeps the left margin consistently clear, so visually everything looks nice. Any space extra whitespace after the comment symbol should be preserved. So we don't destroy any ascii art. |
It might also be good to check how comments around tags are handled. I think this is one of the few places where comments can be trailing. |
Interesting! Hadn't considered. Currently trailing comments on tags are stripped - they are 'lost' by the parser, before reaching the formatter. Is this something we should be looking to preserve? We have
Awesome, sounds good - will see if we can apply this in all or some cases. Initial attempt looked promising, though not yet sure how to deal with the following case where commenting a scenario would be scoped to the previous scenario/background. Will take a look at the Java implementation once we've defined how this should be handled. |
Mmh. I'm not sure I understand. What is the diff comparing? |
For the comments on tags, looks like it's still an open issue cucumber/gherkin#43. Never got around to fixing it. |
With the following gherkin: Feature: Levers
Background:
Given a lever long enough
And a fulcrum on which to place it
Scenario:
When I apply force to the lever
Then I shall move the world If I was to comment-out the scenario (perhaps I temporarily wish to avoid running it), the commented scenario would be treated as trailing comments of the background (which a user could otherwise have). This occurs for comments as the formatter inherits the indentation from the previous header and adds 1 to it - which is the 'Background' header in this case - thus following the same formatting as its steps. Feature: Levers
Background:
Given a lever long enough
And a fulcrum on which to place it
# Scenario:
# When I apply force to the lever
# Then I shall move the world Possibly falls into the territory of #40? |
I'll come back with a reply. This isn't trivial. |
There are, that I can think of, three uses for comments:
But aside from our own language and encoding pragmas, I don't want to give any consideration to the third. We may as well not consider it Gherkin. So the first and second have different irreconcilable requirements. For example: Feature: minimal
Scenario: example
Given a condition
# When an action
# Then an effect
# This is a scenario comment
Scenario: other example
Given a condition
When an action
Then an effect The commented out steps can either be aligned to the next named element. Or the scenario comment can be aligned with the previous named element. And neither is quite right. The "correct" action depends on the context of the comment. Which we can't access with the parser. So fundamentally anything we pick will be imperfect. So given that we must make a trade off, I think it would be best to support comments as an explanation rather than comments as a means to disable parts of the scenario.
Okay. Gotcha. So this should change from using the indentation of the previous named element, to using the indentation of the next element. Or 0 if there is no next element. So your example should look like this: Feature: Levers
Background:
Given a lever long enough
And a fulcrum on which to place it
# Scenario:
# When I apply force to the lever
# Then I shall move the world But feel free to differ if you find a case where this doesn't work. |
🤔 What's changed?
#content
-># content
)⚡️ What's your motivation?
#language: <key>
-># language: <key>
🏷️ What kind of change is this?
♻️ Anything particular you want feedback on?
Changed
in changelog?📋 Checklist:
This text was originally generated from a template, then edited by hand. You can modify the template here.