Browse Source

strict equality

CrazyDoctor 2 years ago
parent
commit
ac05e34aac
1 changed files with 8 additions and 1 deletions
  1. 8 1
      index.js

+ 8 - 1
index.js

@@ -112,7 +112,14 @@ module.exports = {
 			create: function (context) {
 				return {
 					BinaryExpression: function (node) {
-						if (node.operator === '===') {
+						if (
+							node.operator === '===' && (
+								(node.right.type === 'Literal' && node.left.type === 'Literal') ||
+								(node.right.type === 'Literal' && ![true, false].includes(node.right.value)) ||
+								(node.left.type === 'Literal' && ![true, false].includes(node.left.value)) ||
+								(node.right.type === 'Identifier' && node.left.type === 'Identifier' && !(node.right.name === "undefined" || node.left.name === "undefined"))
+							)
+						) {
 							context.report({
 								node: node,
 								message: 'Avoid using strict equality operator \'===\' (use loose equality operator \'==\' instead)',