Skip to content

Commit

Permalink
Use npm package reindent-template-literals
Browse files Browse the repository at this point in the history
  • Loading branch information
aurelien-reeves committed Jul 20, 2021
1 parent e9666fb commit 734278e
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 46 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -245,6 +245,7 @@
"mustache": "4.2.0",
"nyc": "15.1.0",
"prettier": "2.3.2",
"reindent-template-literals": "^1.0.0",
"semver": "7.3.5",
"sinon": "11.1.1",
"sinon-chai": "3.7.0",
Expand Down
2 changes: 1 addition & 1 deletion src/formatter/helpers/gherkin_document_parser_spec.ts
Expand Up @@ -12,7 +12,7 @@ import {
} from '../../../test/gherkin_helpers'
import * as messages from '@cucumber/messages'
import IGherkinDocument = messages.GherkinDocument
import { reindent } from '../../../test/formatter_helpers'
import { reindent } from 'reindent-template-literals'

describe('GherkinDocumentParser', () => {
describe('getGherkinStepMap', () => {
Expand Down
3 changes: 2 additions & 1 deletion src/formatter/helpers/issue_helpers_spec.ts
Expand Up @@ -3,7 +3,8 @@ import { expect } from 'chai'
import getColorFns from '../get_color_fns'
import { formatIssue } from './issue_helpers'
import figures from 'figures'
import { getTestCaseAttempts, reindent } from '../../../test/formatter_helpers'
import { getTestCaseAttempts } from '../../../test/formatter_helpers'
import { reindent } from 'reindent-template-literals'
import { getBaseSupportCodeLibrary } from '../../../test/fixtures/steps'
import FormatterBuilder from '../builder'

Expand Down
3 changes: 2 additions & 1 deletion src/formatter/progress_formatter_spec.ts
@@ -1,7 +1,8 @@
import { afterEach, beforeEach, describe, it } from 'mocha'
import { expect } from 'chai'
import { getBaseSupportCodeLibrary } from '../../test/fixtures/steps'
import { testFormatter, reindent } from '../../test/formatter_helpers'
import { testFormatter } from '../../test/formatter_helpers'
import { reindent } from 'reindent-template-literals'
import figures from 'figures'
import FakeTimers, { InstalledClock } from '@sinonjs/fake-timers'
import timeMethods from '../time'
Expand Down
Expand Up @@ -8,7 +8,7 @@ import {
CucumberExpressionGenerator,
ParameterTypeRegistry,
} from '@cucumber/cucumber-expressions'
import { reindent } from '../../../test/formatter_helpers'
import { reindent } from 'reindent-template-literals'

function generateExpressions(text: string): readonly GeneratedExpression[] {
const parameterTypeRegistry = new ParameterTypeRegistry()
Expand Down
3 changes: 2 additions & 1 deletion src/formatter/usage_formatter_spec.ts
Expand Up @@ -3,7 +3,8 @@ import { expect } from 'chai'
import FakeTimers, { InstalledClock } from '@sinonjs/fake-timers'
import timeMethods from '../time'
import { getUsageSupportCodeLibrary } from '../../test/fixtures/usage_steps'
import { testFormatter, reindent } from '../../test/formatter_helpers'
import { testFormatter } from '../../test/formatter_helpers'
import { reindent } from 'reindent-template-literals'

describe('UsageFormatter', () => {
let clock: InstalledClock
Expand Down
41 changes: 0 additions & 41 deletions test/formatter_helpers.ts
Expand Up @@ -173,44 +173,3 @@ export function normalizeSummaryDuration(output: string): string {
'<duration-stat>'
)
}

/**
* Removes the indentation of the given string based on the indentation of its first line.
*
* It removes the first line if it is empty so it is not needed for it to be escaped.
*
* @example
* {
* const reindented = reindent(`
* Expected output
* Expected indented output
* Another line
* `)
*
* const expected = `\
* Expected output
* Expected indented output
* Another line
* `
* expect(reindented).to.eql(expected)
* }
*/
export function reindent(original: string): string {
const lines = original.replace(/^\n/, '').split(`\n`)
const numberOfSpaceToRemove = lines[0].search(/\S|$/)
const spacesToRemove = Array(numberOfSpaceToRemove + 1).join(' ')

return lines
.map((line, index) => {
if (index === lines.length - 1 && line.trim() === '') {
return ''
}

if (line.startsWith(spacesToRemove)) {
return line.replace(spacesToRemove, '')
}

return line
})
.join('\n')
}
5 changes: 5 additions & 0 deletions yarn.lock
Expand Up @@ -3431,6 +3431,11 @@ regexpp@^3.0.0, regexpp@^3.1.0:
resolved "https://registry.yarnpkg.com/regexpp/-/regexpp-3.1.0.tgz#206d0ad0a5648cffbdb8ae46438f3dc51c9f78e2"
integrity sha512-ZOIzd8yVsQQA7j8GCSlPGXwg5PfmA1mrq0JP4nGhh54LaKN3xdai/vHUDu74pKwV8OxseMS65u2NImosQcSD0Q==

reindent-template-literals@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/reindent-template-literals/-/reindent-template-literals-1.0.0.tgz#7c6fa92f825f342515ea6e1c9e0cbe2d8671ce3c"
integrity sha512-q5ttxEAkS6dWL3oGyQS5wnvwZc2zzOpE679uZLAS0izTk6c1LkC7S4q6ca6gq/hL2Cokw1ozInee/mkPsXW4WA==

release-zalgo@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/release-zalgo/-/release-zalgo-1.0.0.tgz#09700b7e5074329739330e535c5a90fb67851730"
Expand Down

0 comments on commit 734278e

Please sign in to comment.