Skip to content

Commit e198d50

Browse files
committed
Small tweaks to the escape-case rule
1 parent 3fda175 commit e198d50

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

rules/escape-case.js

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

@@ -17,8 +17,13 @@ const fix = value => {
1717
const create = context => {
1818
return {
1919
Literal(node) {
20-
let matches;
21-
if (typeof node.value === 'string' && (matches = node.raw.match(escapeWithLowercase)) && matches[0].slice(2).match(hasLowercaseCharacter)) {
20+
if (typeof node.value !== 'string') {
21+
return;
22+
}
23+
24+
const matches = node.raw.match(escapeWithLowercase);
25+
26+
if (matches && matches[0].slice(2).match(hasLowercaseCharacter)) {
2227
context.report({
2328
node,
2429
message,
@@ -27,8 +32,13 @@ const create = context => {
2732
}
2833
},
2934
TemplateElement(node) {
30-
let matches;
31-
if (typeof node.value.raw === 'string' && (matches = node.value.raw.match(escapeWithLowercase)) && matches[0].slice(2).match(hasLowercaseCharacter)) {
35+
if (typeof node.value.raw !== 'string') {
36+
return;
37+
}
38+
39+
const matches = node.value.raw.match(escapeWithLowercase);
40+
41+
if (matches && matches[0].slice(2).match(hasLowercaseCharacter)) {
3242
context.report({
3343
node,
3444
message,

0 commit comments

Comments
 (0)