eslint-plugin-chai-friendly 1.1.1 → 1.2.0

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.
@@ -51,6 +51,9 @@ module.exports = {
51
51
  enforceForJSX: {
52
52
  type: "boolean",
53
53
  default: false
54
+ },
55
+ ignoreDirectives: {
56
+ type: "boolean"
54
57
  }
55
58
  },
56
59
  additionalProperties: false
@@ -66,7 +69,8 @@ module.exports = {
66
69
  allowShortCircuit = config.allowShortCircuit || false,
67
70
  allowTernary = config.allowTernary || false,
68
71
  allowTaggedTemplates = config.allowTaggedTemplates || false,
69
- enforceForJSX = config.enforceForJSX || false;
72
+ enforceForJSX = config.enforceForJSX || false,
73
+ ignoreDirectives = config.ignoreDirectives || false;
70
74
 
71
75
  /**
72
76
  * @param {ASTNode} node - any node
@@ -101,12 +105,19 @@ module.exports = {
101
105
 
102
106
  /**
103
107
  * @param {ASTNode} node - any node
104
- * @param {ASTNode[]} ancestors - the given node's ancestors
108
+ * @returns {boolean} whether the parser marked this node as a directive
109
+ */
110
+ function isParserDirective(node) {
111
+ return typeof node.directive === "string";
112
+ }
113
+
114
+ /**
115
+ * @param {ASTNode} node - any node
105
116
  * @returns {boolean} whether the given node is considered a directive in its current position
106
117
  */
107
- function isDirective(node, ancestors) {
108
- var parent = ancestors[ancestors.length - 1],
109
- grandparent = ancestors[ancestors.length - 2];
118
+ function isDirective(node) {
119
+ var parent = node.parent,
120
+ grandparent = node.parent.parent;
110
121
 
111
122
  /**
112
123
  * https://tc39.es/ecma262/#directive-prologue
@@ -167,6 +178,20 @@ module.exports = {
167
178
  ThisExpression: alwaysTrue,
168
179
  UnaryExpression(node) {
169
180
  return node.operator !== "void" && node.operator !== "delete";
181
+ },
182
+
183
+ // TypeScript-specific node types
184
+ TSAsExpression(node) {
185
+ return Checker.isDisallowed(node.expression);
186
+ },
187
+ TSTypeAssertion(node) {
188
+ return Checker.isDisallowed(node.expression);
189
+ },
190
+ TSNonNullExpression(node) {
191
+ return Checker.isDisallowed(node.expression);
192
+ },
193
+ TSInstantiationExpression(node) {
194
+ return Checker.isDisallowed(node.expression);
170
195
  }
171
196
  });
172
197
 
@@ -255,18 +280,14 @@ module.exports = {
255
280
  return null;
256
281
  }
257
282
 
258
- const sourceCode = context.sourceCode ?? context.getSourceCode();
259
283
  return {
260
284
  ExpressionStatement: function(node) {
261
- var valid = !Checker.isDisallowed(node.expression)
262
- || isDirective(node,
263
- (sourceCode.getAncestors
264
- ? sourceCode.getAncestors(node)
265
- : context.getAncestors()
266
- ))
267
- || isChaiExpectCall(node)
268
- || isChaiShouldCall(node);
269
- if (!valid) {
285
+ if (Checker.isDisallowed(node.expression)
286
+ && !isParserDirective(node)
287
+ && !(ignoreDirectives && isDirective(node))
288
+ && !isChaiExpectCall(node)
289
+ && !isChaiShouldCall(node)
290
+ ) {
270
291
  context.report({node, messageId: "unusedExpression"});
271
292
  }
272
293
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-chai-friendly",
3
- "version": "1.1.1",
3
+ "version": "1.2.0",
4
4
  "description": "This plugin makes 'no-unused-expressions' rule friendly towards chai expect statements.",
5
5
  "keywords": [
6
6
  "eslint",
@@ -49,8 +49,9 @@
49
49
  "typescript": "^5.8.3"
50
50
  },
51
51
  "overrides": {
52
- "flatted": "3.4.1",
53
- "serialize-javascript": "7.0.4",
52
+ "flatted": "3.4.2",
53
+ "serialize-javascript": "7.0.5",
54
+ "brace-expansion": "5.0.5",
54
55
  "@istanbuljs/load-nyc-config": {
55
56
  "js-yaml": "3.14.2"
56
57
  },