Skip to content

Commit e0d4379

Browse files
fix: allow underscores in string enum values
1 parent f11cfe0 commit e0d4379

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

Diff for: src/__tests__/markdown-helpers.spec.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def fn():
103103
expect(extractStringEnum('wassup')).toBe(null);
104104
});
105105

106-
describe('with single quotes', () => {
106+
describe('with backticks', () => {
107107
it('should extract an enum of the format "can be x"', () => {
108108
const values = extractStringEnum('Can be `x`')!;
109109
expect(values).not.toBe(null);
@@ -160,9 +160,18 @@ def fn():
160160
expect(values[1].value).toBe('b');
161161
expect(values[2].value).toBe('c');
162162
});
163+
164+
it.only('should extract an enum with underscores in the values', () => {
165+
const values = extractStringEnum('Values includes `a`, `b_c` and `d`')!;
166+
expect(values).not.toBe(null);
167+
expect(values).toHaveLength(3);
168+
expect(values[0].value).toBe('a');
169+
expect(values[1].value).toBe('b_c');
170+
expect(values[2].value).toBe('d');
171+
});
163172
});
164173

165-
describe('with backticks', () => {
174+
describe('with single quotes', () => {
166175
it('should extract an enum of the format "can be x"', () => {
167176
const values = extractStringEnum(`Can be 'x'`)!;
168177
expect(values).not.toBe(null);

Diff for: src/markdown-helpers.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -403,11 +403,11 @@ export enum StripReturnTypeBehavior {
403403
export const extractStringEnum = (description: string): PossibleStringValue[] | null => {
404404
const possibleValues: PossibleStringValue[] = [];
405405

406-
const inlineValuesPattern = /(?:can be|values include) ((?:(?:[`|'][a-zA-Z-]+[`|'])(?:(, | )?))*(?:(?:or|and) [`|'][a-zA-Z-]+[`|'])?)/i;
406+
const inlineValuesPattern = /(?:can be|values? includes?) ((?:(?:[`|'][a-zA-Z-_]+[`|'])(?:(, | )?))*(?:(?:or|and) [`|'][a-zA-Z-_]+[`|'])?)/i;
407407
const inlineMatch = inlineValuesPattern.exec(description);
408408
if (inlineMatch) {
409409
const valueString = inlineMatch[1];
410-
const valuePattern = /[`|']([a-zA-Z-]+)[`|']/g;
410+
const valuePattern = /[`|']([a-zA-Z-_]+)[`|']/g;
411411
let value = valuePattern.exec(valueString);
412412

413413
while (value) {

0 commit comments

Comments
 (0)