Skip to content

Commit 28581df

Browse files
committed
jsx-no-literals Find all usages of literals combined with strings
1 parent f27ebc2 commit 28581df

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

lib/rules/jsx-no-literals.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,24 @@ module.exports = {
4242
});
4343
}
4444

45-
function getValidation(node) {
45+
function getParentIgnoringBinaryExpressions(node) {
4646
let current = node;
4747
while (current.parent.type === 'BinaryExpression') {
4848
current = current.parent;
4949
}
50+
return current.parent;
51+
}
52+
53+
function getValidation(node) {
54+
const parent = getParentIgnoringBinaryExpressions(node);
5055
const standard = !/^[\s]+$/.test(node.value) &&
5156
typeof node.value === 'string' &&
52-
current.parent &&
53-
current.parent.type.indexOf('JSX') !== -1 &&
54-
current.parent.type !== 'JSXAttribute';
57+
parent.type.indexOf('JSX') !== -1 &&
58+
parent.type !== 'JSXAttribute';
5559
if (isNoStrings) {
5660
return standard;
5761
}
58-
return standard && node.parent.type !== 'JSXExpressionContainer';
62+
return standard && parent.type !== 'JSXExpressionContainer';
5963
}
6064

6165
// --------------------------------------------------------------------------
@@ -71,7 +75,8 @@ module.exports = {
7175
},
7276

7377
TemplateLiteral: function(node) {
74-
if (isNoStrings && node.parent.type === 'JSXExpressionContainer') {
78+
const parent = getParentIgnoringBinaryExpressions(node);
79+
if (isNoStrings && parent.type === 'JSXExpressionContainer') {
7580
reportLiteralNode(node);
7681
}
7782
}

0 commit comments

Comments
 (0)