Skip to content

Commit f37edaa

Browse files
authored
debt: replace use of Dictionary with Record (cucumber#1662)
* replace use of Dictionary with Record * change this one too * data table cells are always strings
1 parent 511b81d commit f37edaa

File tree

12 files changed

+52
-52
lines changed

12 files changed

+52
-52
lines changed

src/cli/profile_loader.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import _, { Dictionary } from 'lodash'
1+
import _ from 'lodash'
22
import fs from 'mz/fs'
33
import path from 'path'
44
import stringArgv from 'string-argv'
@@ -11,7 +11,7 @@ export default class ProfileLoader {
1111
this.directory = directory
1212
}
1313

14-
async getDefinitions(): Promise<Dictionary<string>> {
14+
async getDefinitions(): Promise<Record<string, string>> {
1515
const definitionsFilePath = path.join(this.directory, 'cucumber.js')
1616
const exists = await fs.exists(definitionsFilePath)
1717
if (!exists) {

src/formatter/helpers/event_data_collector.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import _, { Dictionary, values } from 'lodash'
1+
import _, { values } from 'lodash'
22
import { messages } from '@cucumber/messages'
33
import { doesHaveValue, doesNotHaveValue } from '../../value_checker'
44
import { EventEmitter } from 'events'
@@ -7,26 +7,26 @@ import { Query } from '@cucumber/query'
77
interface ITestCaseAttemptData {
88
attempt: number
99
testCaseId: string
10-
stepAttachments: Dictionary<messages.IAttachment[]>
11-
stepResults: Dictionary<messages.TestStepFinished.ITestStepResult>
10+
stepAttachments: Record<string, messages.IAttachment[]>
11+
stepResults: Record<string, messages.TestStepFinished.ITestStepResult>
1212
worstTestStepResult: messages.TestStepFinished.ITestStepResult
1313
}
1414

1515
export interface ITestCaseAttempt {
1616
attempt: number
1717
gherkinDocument: messages.IGherkinDocument
1818
pickle: messages.IPickle
19-
stepAttachments: Dictionary<messages.IAttachment[]>
20-
stepResults: Dictionary<messages.TestStepFinished.ITestStepResult>
19+
stepAttachments: Record<string, messages.IAttachment[]>
20+
stepResults: Record<string, messages.TestStepFinished.ITestStepResult>
2121
testCase: messages.ITestCase
2222
worstTestStepResult: messages.TestStepFinished.ITestStepResult
2323
}
2424

2525
export default class EventDataCollector {
26-
private gherkinDocumentMap: Dictionary<messages.IGherkinDocument> = {}
27-
private pickleMap: Dictionary<messages.IPickle> = {}
28-
private testCaseMap: Dictionary<messages.ITestCase> = {}
29-
private testCaseAttemptDataMap: Dictionary<ITestCaseAttemptData> = {}
26+
private gherkinDocumentMap: Record<string, messages.IGherkinDocument> = {}
27+
private pickleMap: Record<string, messages.IPickle> = {}
28+
private testCaseMap: Record<string, messages.ITestCase> = {}
29+
private testCaseAttemptDataMap: Record<string, ITestCaseAttemptData> = {}
3030
readonly undefinedParameterTypes: messages.IUndefinedParameterType[] = []
3131
readonly query = new Query()
3232

src/formatter/helpers/gherkin_document_parser.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import _, { Dictionary } from 'lodash'
1+
import _ from 'lodash'
22
import { messages } from '@cucumber/messages'
33
import { doesHaveValue } from '../../value_checker'
44

55
export function getGherkinStepMap(
66
gherkinDocument: messages.IGherkinDocument
7-
): Dictionary<messages.GherkinDocument.Feature.IStep> {
7+
): Record<string, messages.GherkinDocument.Feature.IStep> {
88
return _.chain(gherkinDocument.feature.children)
99
.map(extractStepContainers)
1010
.flatten()
@@ -35,7 +35,7 @@ function extractStepContainers(
3535

3636
export function getGherkinScenarioMap(
3737
gherkinDocument: messages.IGherkinDocument
38-
): Dictionary<messages.GherkinDocument.Feature.IScenario> {
38+
): Record<string, messages.GherkinDocument.Feature.IScenario> {
3939
return _.chain(gherkinDocument.feature.children)
4040
.map((child: messages.GherkinDocument.Feature.IFeatureChild) => {
4141
if (doesHaveValue(child.rule)) {
@@ -56,7 +56,7 @@ export function getGherkinScenarioMap(
5656

5757
export function getGherkinExampleRuleMap(
5858
gherkinDocument: messages.IGherkinDocument
59-
): Dictionary<messages.GherkinDocument.Feature.FeatureChild.IRule> {
59+
): Record<string, messages.GherkinDocument.Feature.FeatureChild.IRule> {
6060
return _.chain(gherkinDocument.feature.children)
6161
.filter('rule')
6262
.map('rule')
@@ -72,11 +72,12 @@ export function getGherkinExampleRuleMap(
7272

7373
export function getGherkinScenarioLocationMap(
7474
gherkinDocument: messages.IGherkinDocument
75-
): Dictionary<messages.ILocation> {
76-
const locationMap: Dictionary<messages.ILocation> = {}
77-
const scenarioMap: Dictionary<messages.GherkinDocument.Feature.IScenario> = getGherkinScenarioMap(
78-
gherkinDocument
79-
)
75+
): Record<string, messages.ILocation> {
76+
const locationMap: Record<string, messages.ILocation> = {}
77+
const scenarioMap: Record<
78+
string,
79+
messages.GherkinDocument.Feature.IScenario
80+
> = getGherkinScenarioMap(gherkinDocument)
8081
_.entries<messages.GherkinDocument.Feature.IScenario>(scenarioMap).forEach(
8182
([id, scenario]) => {
8283
locationMap[id] = scenario.location

src/formatter/helpers/issue_helpers.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { IColorFns } from '../get_color_fns'
66
import StepDefinitionSnippetBuilder from '../step_definition_snippet_builder'
77
import { ISupportCodeLibrary } from '../../support_code_library_builder/types'
88
import { ITestCaseAttempt } from './event_data_collector'
9-
import { Dictionary } from 'lodash'
109

1110
export function isFailure(
1211
result: messages.TestStepFinished.ITestStepResult
@@ -72,7 +71,7 @@ export function formatUndefinedParameterTypes(
7271
undefinedParameterTypes: messages.IUndefinedParameterType[]
7372
): string {
7473
const output = [`Undefined parameter types:\n\n`]
75-
const withLatest: Dictionary<messages.IUndefinedParameterType> = {}
74+
const withLatest: Record<string, messages.IUndefinedParameterType> = {}
7675
undefinedParameterTypes.forEach((parameterType) => {
7776
withLatest[parameterType.name] = parameterType
7877
})

src/formatter/helpers/pickle_parser.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import _, { Dictionary } from 'lodash'
1+
import _ from 'lodash'
22
import { getGherkinScenarioLocationMap } from './gherkin_document_parser'
33
import { messages } from '@cucumber/messages'
44

@@ -9,12 +9,12 @@ export interface IGetPickleLocationRequest {
99

1010
export interface IGetStepKeywordRequest {
1111
pickleStep: messages.Pickle.IPickleStep
12-
gherkinStepMap: Dictionary<messages.GherkinDocument.Feature.IStep>
12+
gherkinStepMap: Record<string, messages.GherkinDocument.Feature.IStep>
1313
}
1414

1515
export interface IGetScenarioDescriptionRequest {
1616
pickle: messages.IPickle
17-
gherkinScenarioMap: Dictionary<messages.GherkinDocument.Feature.IScenario>
17+
gherkinScenarioMap: Record<string, messages.GherkinDocument.Feature.IScenario>
1818
}
1919

2020
export function getScenarioDescription({
@@ -41,7 +41,7 @@ export function getStepKeyword({
4141

4242
export function getPickleStepMap(
4343
pickle: messages.IPickle
44-
): Dictionary<messages.Pickle.IPickleStep> {
44+
): Record<string, messages.Pickle.IPickleStep> {
4545
return _.chain(pickle.steps)
4646
.map((pickleStep) => [pickleStep.id, pickleStep])
4747
.fromPairs()

src/formatter/helpers/test_case_attempt_parser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import _, { Dictionary } from 'lodash'
1+
import _ from 'lodash'
22
import Status from '../../status'
33
import { getStepKeywordType, KeywordType } from './keyword_type'
44
import {
@@ -40,7 +40,7 @@ export interface IParsedTestCaseAttempt {
4040

4141
interface IParseStepRequest {
4242
isBeforeHook: boolean
43-
gherkinStepMap: Dictionary<messages.GherkinDocument.Feature.IStep>
43+
gherkinStepMap: Record<string, messages.GherkinDocument.Feature.IStep>
4444
keyword: string
4545
keywordType: KeywordType
4646
pickleStep: messages.Pickle.IPickleStep

src/formatter/helpers/usage_helpers/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import _, { Dictionary } from 'lodash'
1+
import _ from 'lodash'
22
import { getPickleStepMap } from '../pickle_parser'
33
import path from 'path'
44
import { getGherkinStepMap } from '../gherkin_document_parser'
@@ -33,8 +33,8 @@ export interface IGetUsageRequest {
3333

3434
function buildEmptyMapping(
3535
stepDefinitions: StepDefinition[]
36-
): Dictionary<IUsage> {
37-
const mapping: Dictionary<IUsage> = {}
36+
): Record<string, IUsage> {
37+
const mapping: Record<string, IUsage> = {}
3838
stepDefinitions.forEach((stepDefinition) => {
3939
mapping[stepDefinition.id] = {
4040
code: stepDefinition.unwrappedCode.toString(),
@@ -52,7 +52,7 @@ function buildMapping({
5252
cwd,
5353
stepDefinitions,
5454
eventDataCollector,
55-
}: IGetUsageRequest): Dictionary<IUsage> {
55+
}: IGetUsageRequest): Record<string, IUsage> {
5656
const mapping = buildEmptyMapping(stepDefinitions)
5757
_.each(eventDataCollector.getTestCaseAttempts(), (testCaseAttempt) => {
5858
const pickleStepMap = getPickleStepMap(testCaseAttempt.pickle)
@@ -97,7 +97,7 @@ function invertDuration(duration: messages.IDuration): number {
9797
return 1
9898
}
9999

100-
function buildResult(mapping: Dictionary<IUsage>): IUsage[] {
100+
function buildResult(mapping: Record<string, IUsage>): IUsage[] {
101101
return _.chain(mapping)
102102
.map(({ matches, ...rest }: IUsage) => {
103103
const sortedMatches = _.sortBy(matches, [

src/formatter/json_formatter.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import _, { Dictionary } from 'lodash'
1+
import _ from 'lodash'
22
import Formatter, { IFormatterOptions } from './'
33
import Status from '../status'
44
import { formatLocation, GherkinDocumentParser, PickleParser } from './helpers'
@@ -74,17 +74,17 @@ interface IBuildJsonFeatureOptions {
7474

7575
interface IBuildJsonScenarioOptions {
7676
feature: messages.GherkinDocument.IFeature
77-
gherkinScenarioMap: Dictionary<IScenario>
78-
gherkinExampleRuleMap: Dictionary<IRule>
79-
gherkinScenarioLocationMap: Dictionary<messages.ILocation>
77+
gherkinScenarioMap: Record<string, IScenario>
78+
gherkinExampleRuleMap: Record<string, IRule>
79+
gherkinScenarioLocationMap: Record<string, messages.ILocation>
8080
pickle: messages.IPickle
8181
steps: IJsonStep[]
8282
}
8383

8484
interface IBuildJsonStepOptions {
8585
isBeforeHook: boolean
86-
gherkinStepMap: Dictionary<messages.GherkinDocument.Feature.IStep>
87-
pickleStepMap: Dictionary<messages.Pickle.IPickleStep>
86+
gherkinStepMap: Record<string, messages.GherkinDocument.Feature.IStep>
87+
pickleStepMap: Record<string, messages.Pickle.IPickleStep>
8888
testStep: messages.TestCase.ITestStep
8989
testStepAttachments: messages.IAttachment[]
9090
testStepResult: messages.TestStepFinished.ITestStepResult
@@ -242,7 +242,7 @@ export default class JsonFormatter extends Formatter {
242242
}: {
243243
feature: IFeature
244244
pickle: IPickle
245-
gherkinExampleRuleMap: Dictionary<IRule>
245+
gherkinExampleRuleMap: Record<string, IRule>
246246
}): string {
247247
let parts: any[]
248248
const rule = gherkinExampleRuleMap[pickle.astNodeIds[0]]
@@ -313,7 +313,7 @@ export default class JsonFormatter extends Formatter {
313313
}: {
314314
feature: IFeature
315315
pickle: IPickle
316-
gherkinScenarioMap: { [id: string]: IScenario }
316+
gherkinScenarioMap: Record<string, IScenario>
317317
}): IJsonTag[] {
318318
const scenario = gherkinScenarioMap[pickle.astNodeIds[0]]
319319

src/models/data_table.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import _, { Dictionary } from 'lodash'
1+
import _ from 'lodash'
22
import { messages } from '@cucumber/messages'
33

44
export default class DataTable {
@@ -33,7 +33,7 @@ export default class DataTable {
3333
return copy
3434
}
3535

36-
rowsHash(): Dictionary<any> {
36+
rowsHash(): Record<string, string> {
3737
const rows = this.raw()
3838
const everyRowHasTwoColumns = _.every(rows, (row) => row.length === 2)
3939
if (!everyRowHasTwoColumns) {

src/pickle_filter.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import _, { Dictionary } from 'lodash'
1+
import _ from 'lodash'
22
import path from 'path'
33
import parse from '@cucumber/tag-expressions'
44
import { getGherkinScenarioLocationMap } from './formatter/helpers/gherkin_document_parser'
@@ -53,7 +53,7 @@ export default class PickleFilter {
5353
}
5454

5555
export class PickleLineFilter {
56-
private readonly featureUriToLinesMapping: Dictionary<number[]>
56+
private readonly featureUriToLinesMapping: Record<string, number[]>
5757

5858
constructor(cwd: string, featurePaths: string[] = []) {
5959
this.featureUriToLinesMapping = this.getFeatureUriToLinesMapping({
@@ -68,8 +68,8 @@ export class PickleLineFilter {
6868
}: {
6969
cwd: string
7070
featurePaths: string[]
71-
}): Dictionary<number[]> {
72-
const mapping: Dictionary<number[]> = {}
71+
}): Record<string, number[]> {
72+
const mapping: Record<string, number[]> = {}
7373
featurePaths.forEach((featurePath) => {
7474
const match = FEATURE_LINENUM_REGEXP.exec(featurePath)
7575
if (doesHaveValue(match)) {

0 commit comments

Comments
 (0)