Skip to content

Commit c1c1799

Browse files
Bebersohlsindresorhus
authored andcommitted
Bug fix for number only escapes in escape-case rule (#86)
1 parent dacf538 commit c1c1799

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

rules/escape-case.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22
const escapeWithLowercase = /\\(x[a-f0-9]{2}|u[a-f0-9]{4}|u\{([0-9a-f]{1,})\}|c[a-z])/;
3+
const hasLowercaseCharacter = /[a-z].*?[a-z]/;
34
const message = 'Use uppercase characters for the value of the escape sequence.';
45

56
const fix = value => {
@@ -16,7 +17,7 @@ const fix = value => {
1617
const create = context => {
1718
return {
1819
Literal(node) {
19-
if (typeof node.value === 'string' && node.raw.match(escapeWithLowercase)) {
20+
if (typeof node.value === 'string' && node.raw.match(escapeWithLowercase) && node.raw.match(hasLowercaseCharacter)) {
2021
context.report({
2122
node,
2223
message,
@@ -25,7 +26,7 @@ const create = context => {
2526
}
2627
},
2728
TemplateElement(node) {
28-
if (typeof node.value.raw === 'string' && node.value.raw.match(escapeWithLowercase)) {
29+
if (typeof node.value.raw === 'string' && node.value.raw.match(escapeWithLowercase) && node.value.raw.match(hasLowercaseCharacter)) {
2930
context.report({
3031
node,
3132
message,

test/escape-case.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ ruleTester.run('escape-case', rule, {
3030
'const foo = `${"\uD834 foo"} \\uD834`;',
3131
'const foo = "\\uD834foo";',
3232
'const foo = "foo\\uD834";',
33-
'const foo = "foo \\uD834";'
33+
'const foo = "foo \\uD834";',
34+
'const foo = "\\u2500";',
35+
'const foo = "\\x46";'
3436
],
3537
invalid: [
3638
{

0 commit comments

Comments
 (0)