eslint-plugin-chai-friendly 1.2.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -148,7 +148,8 @@ module.exports = {
|
|
|
148
148
|
ClassExpression: alwaysTrue,
|
|
149
149
|
ConditionalExpression(node) {
|
|
150
150
|
if (allowTernary) {
|
|
151
|
-
return Checker.isDisallowed(node.consequent)
|
|
151
|
+
return (Checker.isDisallowed(node.consequent) && !isChaiCall(node.consequent)) ||
|
|
152
|
+
(Checker.isDisallowed(node.alternate) && !isChaiCall(node.alternate));
|
|
152
153
|
}
|
|
153
154
|
return true;
|
|
154
155
|
},
|
|
@@ -163,7 +164,7 @@ module.exports = {
|
|
|
163
164
|
},
|
|
164
165
|
LogicalExpression(node) {
|
|
165
166
|
if (allowShortCircuit) {
|
|
166
|
-
return Checker.isDisallowed(node.right);
|
|
167
|
+
return Checker.isDisallowed(node.right) && !isChaiCall(node.right);
|
|
167
168
|
}
|
|
168
169
|
return true;
|
|
169
170
|
},
|
|
@@ -198,16 +199,15 @@ module.exports = {
|
|
|
198
199
|
/**
|
|
199
200
|
* Determines whether or not a given node is a chai's expect statement.
|
|
200
201
|
* e.g. expect(foo).to.eventually.be.true;
|
|
201
|
-
* @param {ASTNode}
|
|
202
|
+
* @param {ASTNode} expressionNode - expression node
|
|
202
203
|
* @returns {boolean} whether the given node is a chai expectation
|
|
203
204
|
*/
|
|
204
|
-
function isChaiExpectCall(
|
|
205
|
-
|
|
206
|
-
if (expression.type !== 'MemberExpression') {
|
|
205
|
+
function isChaiExpectCall(expressionNode) {
|
|
206
|
+
if (expressionNode.type !== 'MemberExpression') {
|
|
207
207
|
return false;
|
|
208
208
|
}
|
|
209
209
|
|
|
210
|
-
return Boolean(findExpectCall(
|
|
210
|
+
return Boolean(findExpectCall(expressionNode.object));
|
|
211
211
|
}
|
|
212
212
|
|
|
213
213
|
/**
|
|
@@ -239,19 +239,18 @@ module.exports = {
|
|
|
239
239
|
/**
|
|
240
240
|
* Determines whether or not a given node is a chai's should statement.
|
|
241
241
|
* e.g. foo.should.eventually.be.true;
|
|
242
|
-
* @param {ASTNode}
|
|
242
|
+
* @param {ASTNode} expressionNode - expression node
|
|
243
243
|
* @returns {boolean} whether the given node is a chai should statement
|
|
244
244
|
*/
|
|
245
|
-
function isChaiShouldCall(
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
expression = expression.expression
|
|
245
|
+
function isChaiShouldCall(expressionNode) {
|
|
246
|
+
if (expressionNode.type === 'ChainExpression') {
|
|
247
|
+
expressionNode = expressionNode.expression
|
|
249
248
|
}
|
|
250
|
-
if (
|
|
249
|
+
if (expressionNode.type !== 'MemberExpression') {
|
|
251
250
|
return false;
|
|
252
251
|
}
|
|
253
252
|
|
|
254
|
-
return Boolean(findShouldCall(
|
|
253
|
+
return Boolean(findShouldCall(expressionNode.object));
|
|
255
254
|
}
|
|
256
255
|
|
|
257
256
|
/**
|
|
@@ -280,13 +279,21 @@ module.exports = {
|
|
|
280
279
|
return null;
|
|
281
280
|
}
|
|
282
281
|
|
|
282
|
+
/**
|
|
283
|
+
* Determines whether or not a given node is a chai call.
|
|
284
|
+
* @param {ASTNode} expressionNode - expression node
|
|
285
|
+
* @returns {boolean} whether the given node is a chai call
|
|
286
|
+
*/
|
|
287
|
+
function isChaiCall(expressionNode) {
|
|
288
|
+
return isChaiExpectCall(expressionNode) || isChaiShouldCall(expressionNode);
|
|
289
|
+
}
|
|
290
|
+
|
|
283
291
|
return {
|
|
284
292
|
ExpressionStatement: function(node) {
|
|
285
293
|
if (Checker.isDisallowed(node.expression)
|
|
286
294
|
&& !isParserDirective(node)
|
|
287
295
|
&& !(ignoreDirectives && isDirective(node))
|
|
288
|
-
&& !
|
|
289
|
-
&& !isChaiShouldCall(node)
|
|
296
|
+
&& !isChaiCall(node.expression)
|
|
290
297
|
) {
|
|
291
298
|
context.report({node, messageId: "unusedExpression"});
|
|
292
299
|
}
|