Skip to content

Commit

Permalink
jsx-no-literals Find all usages of literals combined with strings
Browse files Browse the repository at this point in the history
  • Loading branch information
jaaberg committed Dec 18, 2017
1 parent f27ebc2 commit 28581df
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions lib/rules/jsx-no-literals.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,24 @@ module.exports = {
});
}

function getValidation(node) {
function getParentIgnoringBinaryExpressions(node) {
let current = node;
while (current.parent.type === 'BinaryExpression') {
current = current.parent;
}
return current.parent;
}

function getValidation(node) {
const parent = getParentIgnoringBinaryExpressions(node);
const standard = !/^[\s]+$/.test(node.value) &&
typeof node.value === 'string' &&
current.parent &&
current.parent.type.indexOf('JSX') !== -1 &&
current.parent.type !== 'JSXAttribute';
parent.type.indexOf('JSX') !== -1 &&
parent.type !== 'JSXAttribute';
if (isNoStrings) {
return standard;
}
return standard && node.parent.type !== 'JSXExpressionContainer';
return standard && parent.type !== 'JSXExpressionContainer';
}

// --------------------------------------------------------------------------
Expand All @@ -71,7 +75,8 @@ module.exports = {
},

TemplateLiteral: function(node) {
if (isNoStrings && node.parent.type === 'JSXExpressionContainer') {
const parent = getParentIgnoringBinaryExpressions(node);
if (isNoStrings && parent.type === 'JSXExpressionContainer') {
reportLiteralNode(node);
}
}
Expand Down

0 comments on commit 28581df

Please sign in to comment.