Skip to content

Commit

Permalink
fix(ruleset-migrator): avoid positive lookbehinds (stoplightio#2349)
Browse files Browse the repository at this point in the history
  • Loading branch information
P0lip authored and PagoNxt-Trade committed Dec 1, 2022
1 parent 03be5cc commit e2a2b49
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions packages/ruleset-migrator/src/transformers/formats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,11 @@ const FORMATS = [

function safeFormat(format: string): string {
return format
.replace(/\.|(?<=[0-9])-(?=[0-9])/g, '_')
.replace(/\.|([0-9])-(?=[0-9])/g, '$1_')
.replace(/-([0-9a-z])/g, (match, char) => String(char).toUpperCase());
}

const REPLACEMENTS = Object.fromEntries(
FORMATS.map(format => [
format,
(ALIASES[format] ?? format)
.replace(/\.|(?<=[0-9])-(?=[0-9])/g, '_')
.replace(/-([0-9a-z])/g, (match, char) => String(char).toUpperCase()),
]),
);
const REPLACEMENTS = Object.fromEntries(FORMATS.map(format => [format, safeFormat(ALIASES[format] ?? format)]));

function transform(input: unknown, ctx: TransformerCtx): namedTypes.ArrayExpression {
assertArray(input);
Expand Down

0 comments on commit e2a2b49

Please sign in to comment.