From 5fdd21a1726fb6928098c4152aec55a30df960d4 Mon Sep 17 00:00:00 2001 From: Pete Gonzalez <4673363+octogonz@users.noreply.github.com> Date: Wed, 24 Jun 2020 01:40:46 -0700 Subject: [PATCH] fix(eslint-plugin): [naming-convention] support unicode in regex (#2241) --- packages/eslint-plugin/src/rules/naming-convention.ts | 6 +++--- .../tests/rules/naming-convention.test.ts | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/eslint-plugin/src/rules/naming-convention.ts b/packages/eslint-plugin/src/rules/naming-convention.ts index bdbedc625ea..f28454916ad 100644 --- a/packages/eslint-plugin/src/rules/naming-convention.ts +++ b/packages/eslint-plugin/src/rules/naming-convention.ts @@ -1213,7 +1213,7 @@ function normalizeOption(option: Selector): NormalizedSelector { format: option.format ? option.format.map(f => PredefinedFormats[f]) : null, custom: option.custom ? { - regex: new RegExp(option.custom.regex), + regex: new RegExp(option.custom.regex, 'u'), match: option.custom.match, } : null, @@ -1236,9 +1236,9 @@ function normalizeOption(option: Selector): NormalizedSelector { filter: option.filter !== undefined ? typeof option.filter === 'string' - ? { regex: new RegExp(option.filter), match: true } + ? { regex: new RegExp(option.filter, 'u'), match: true } : { - regex: new RegExp(option.filter.regex), + regex: new RegExp(option.filter.regex, 'u'), match: option.filter.match, } : null, diff --git a/packages/eslint-plugin/tests/rules/naming-convention.test.ts b/packages/eslint-plugin/tests/rules/naming-convention.test.ts index e907f26e8a6..206979dcb5a 100644 --- a/packages/eslint-plugin/tests/rules/naming-convention.test.ts +++ b/packages/eslint-plugin/tests/rules/naming-convention.test.ts @@ -963,7 +963,7 @@ ruleTester.run('naming-convention', rule, { data: { type: 'Variable', name: 'unused_foo', - regex: '/^unused_\\w/', + regex: '/^unused_\\w/u', regexMatch: 'not match', }, }, @@ -973,7 +973,7 @@ ruleTester.run('naming-convention', rule, { data: { type: 'Variable', name: '_unused_foo', - regex: '/^unused_\\w/', + regex: '/^unused_\\w/u', regexMatch: 'not match', }, }, @@ -983,7 +983,7 @@ ruleTester.run('naming-convention', rule, { data: { type: 'Interface', name: 'IFoo', - regex: '/^I[A-Z]/', + regex: '/^I[A-Z]/u', regexMatch: 'not match', }, }, @@ -993,7 +993,7 @@ ruleTester.run('naming-convention', rule, { data: { type: 'Class', name: 'IBar', - regex: '/^I[A-Z]/', + regex: '/^I[A-Z]/u', regexMatch: 'not match', }, }, @@ -1003,7 +1003,7 @@ ruleTester.run('naming-convention', rule, { data: { type: 'Function', name: 'fooBar', - regex: '/function/', + regex: '/function/u', regexMatch: 'match', }, },