summaryrefslogtreecommitdiff
path: root/tools/eslint/lib/rules/yoda.js
diff options
context:
space:
mode:
Diffstat (limited to 'tools/eslint/lib/rules/yoda.js')
-rw-r--r--tools/eslint/lib/rules/yoda.js4
1 files changed, 3 insertions, 1 deletions
diff --git a/tools/eslint/lib/rules/yoda.js b/tools/eslint/lib/rules/yoda.js
index ab5e7d04c9..57ac261b95 100644
--- a/tools/eslint/lib/rules/yoda.js
+++ b/tools/eslint/lib/rules/yoda.js
@@ -114,7 +114,7 @@ function same(a, b) {
// Rule Definition
//------------------------------------------------------------------------------
-module.exports = function (context) {
+module.exports = function(context) {
// Default to "never" (!always) if no option
var always = (context.options[0] === "always");
@@ -197,6 +197,7 @@ module.exports = function (context) {
// Comparisons must always be yoda-style: if ("blue" === color)
if (
(node.right.type === "Literal" || looksLikeLiteral(node.right)) &&
+ !(node.left.type === "Literal" || looksLikeLiteral(node.left)) &&
!(!isEqualityOperator(node.operator) && onlyEquality) &&
isComparisonOperator(node.operator) &&
!(exceptRange && isRangeTest(context.getAncestors().pop()))
@@ -209,6 +210,7 @@ module.exports = function (context) {
// Comparisons must never be yoda-style (default)
if (
(node.left.type === "Literal" || looksLikeLiteral(node.left)) &&
+ !(node.right.type === "Literal" || looksLikeLiteral(node.right)) &&
!(!isEqualityOperator(node.operator) && onlyEquality) &&
isComparisonOperator(node.operator) &&
!(exceptRange && isRangeTest(context.getAncestors().pop()))