Skip to content

Commit

Permalink
trim trailing heading spaces with JS
Browse files Browse the repository at this point in the history
  • Loading branch information
kieran-ryan committed Sep 11, 2023
1 parent 71d7ded commit bd19f65
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
- Prevent the introduction of trailing whitespace after headings with JavaScript formatter ([#34](https://github.com/cucumber/gherkin-utils/issues/34))

## [8.0.5] - 2023-06-02
### Changed
Expand Down
11 changes: 9 additions & 2 deletions javascript/src/pretty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ function prettyLanguageHeader(language: string | undefined): string {
return language === 'en' ? '' : `# language: ${language}\n`
}

function semiColumnName(name: string | null): string {
if (name == null || name.length == 0) {
return ':';
} else {
return ': ' + name;
}
}

function prettyKeywordContainer(
stepContainer:
| messages.Feature
Expand All @@ -93,8 +101,7 @@ function prettyKeywordContainer(
.concat(prettyTags(tags, syntax, level))
.concat(keywordPrefix(level, syntax))
.concat(stepContainer.keyword)
.concat(': ')
.concat(stepContainer.name)
.concat(semiColumnName(stepContainer.name))
.concat('\n')
.concat(description)
.concat(description && stepCount > 0 ? '\n' : '')
Expand Down
13 changes: 13 additions & 0 deletions javascript/test/prettyTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,19 @@ Feature: hello
`)
})

it('renders titles without trailing whitespace', () => {
checkGherkinToAstToGherkin(`Feature:
Rule:
Background:
Scenario Outlines:
Examples:
`)
})


const featureFiles = fg.sync(`${__dirname}/../../testdata/good/*.feature`)
for (const featureFile of featureFiles) {
const relativePath = path.relative(__dirname, featureFile)
Expand Down

0 comments on commit bd19f65

Please sign in to comment.