@saasmakers/eslint 1.0.12 → 1.0.16

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.
package/dist/index.cjs CHANGED
@@ -139,6 +139,29 @@ const rule$b = {
139
139
  function collapseBlankLine(text) {
140
140
  return text.replace(/\n[^\S\n]*\n[^\S\n]*/, "\n");
141
141
  }
142
+ function expressionStartsWithIdentifier(node, identifier) {
143
+ if (node.type === index$1.distExports.AST_NODE_TYPES.Identifier && node.name === identifier) {
144
+ return true;
145
+ }
146
+ if (node.type === index$1.distExports.AST_NODE_TYPES.CallExpression || node.type === index$1.distExports.AST_NODE_TYPES.OptionalCallExpression) {
147
+ if (node.callee.type === index$1.distExports.AST_NODE_TYPES.Identifier && node.callee.name === identifier) {
148
+ return true;
149
+ }
150
+ if (node.callee.type === index$1.distExports.AST_NODE_TYPES.MemberExpression || node.callee.type === index$1.distExports.AST_NODE_TYPES.OptionalMemberExpression) {
151
+ return expressionStartsWithIdentifier(node.callee.object, identifier);
152
+ }
153
+ if (node.callee.type === index$1.distExports.AST_NODE_TYPES.ChainExpression) {
154
+ return expressionStartsWithIdentifier(node.callee.expression, identifier);
155
+ }
156
+ }
157
+ if (node.type === index$1.distExports.AST_NODE_TYPES.MemberExpression || node.type === index$1.distExports.AST_NODE_TYPES.OptionalMemberExpression) {
158
+ return expressionStartsWithIdentifier(node.object, identifier);
159
+ }
160
+ if (node.type === index$1.distExports.AST_NODE_TYPES.ChainExpression) {
161
+ return expressionStartsWithIdentifier(node.expression, identifier);
162
+ }
163
+ return false;
164
+ }
142
165
  function expressionUsesThis(expression) {
143
166
  if (expression.type === index$1.distExports.AST_NODE_TYPES.AssignmentExpression) {
144
167
  return isThisReceiver(expression.left);
@@ -206,6 +229,21 @@ function getStatementKind(node) {
206
229
  if (isDirectivePrologue(node)) {
207
230
  return null;
208
231
  }
232
+ if (node.expression.type === index$1.distExports.AST_NODE_TYPES.AssignmentExpression) {
233
+ if (expressionUsesThis(node.expression)) {
234
+ return isSingleLine(node) ? "singleline-this" : "multiline-this";
235
+ }
236
+ return isSingleLine(node) ? "singleline-assignment" : "multiline-assignment";
237
+ }
238
+ if (isExpectExpression(node.expression)) {
239
+ return isSingleLine(node) ? "singleline-expect" : "multiline-expect";
240
+ }
241
+ if (isAssertExpression(node.expression)) {
242
+ return isSingleLine(node) ? "singleline-assert" : "multiline-assert";
243
+ }
244
+ if (isConsoleExpression(node.expression)) {
245
+ return isSingleLine(node) ? "singleline-console" : "multiline-console";
246
+ }
209
247
  if (expressionUsesThis(node.expression)) {
210
248
  return isSingleLine(node) ? "singleline-this" : "multiline-this";
211
249
  }
@@ -229,12 +267,21 @@ function hasLineCommentBetween(prevNode, nextNode, sourceCode) {
229
267
  return comment.range[0] >= prevNode.range[1] && comment.range[1] <= nextNode.range[0];
230
268
  });
231
269
  }
270
+ function isAssertExpression(expression) {
271
+ return expressionStartsWithIdentifier(expression, "assert");
272
+ }
273
+ function isConsoleExpression(expression) {
274
+ return expressionStartsWithIdentifier(expression, "console");
275
+ }
232
276
  function isDirectivePrologue(node) {
233
277
  if (node.expression.type !== index$1.distExports.AST_NODE_TYPES.Literal) {
234
278
  return false;
235
279
  }
236
280
  return typeof node.expression.value === "string";
237
281
  }
282
+ function isExpectExpression(expression) {
283
+ return expressionStartsWithIdentifier(expression, "expect");
284
+ }
238
285
  function isOwnLineComment(comment, sourceCode) {
239
286
  if (comment.type !== "Line") {
240
287
  return false;
package/dist/index.mjs CHANGED
@@ -137,6 +137,29 @@ const rule$b = {
137
137
  function collapseBlankLine(text) {
138
138
  return text.replace(/\n[^\S\n]*\n[^\S\n]*/, "\n");
139
139
  }
140
+ function expressionStartsWithIdentifier(node, identifier) {
141
+ if (node.type === distExports.AST_NODE_TYPES.Identifier && node.name === identifier) {
142
+ return true;
143
+ }
144
+ if (node.type === distExports.AST_NODE_TYPES.CallExpression || node.type === distExports.AST_NODE_TYPES.OptionalCallExpression) {
145
+ if (node.callee.type === distExports.AST_NODE_TYPES.Identifier && node.callee.name === identifier) {
146
+ return true;
147
+ }
148
+ if (node.callee.type === distExports.AST_NODE_TYPES.MemberExpression || node.callee.type === distExports.AST_NODE_TYPES.OptionalMemberExpression) {
149
+ return expressionStartsWithIdentifier(node.callee.object, identifier);
150
+ }
151
+ if (node.callee.type === distExports.AST_NODE_TYPES.ChainExpression) {
152
+ return expressionStartsWithIdentifier(node.callee.expression, identifier);
153
+ }
154
+ }
155
+ if (node.type === distExports.AST_NODE_TYPES.MemberExpression || node.type === distExports.AST_NODE_TYPES.OptionalMemberExpression) {
156
+ return expressionStartsWithIdentifier(node.object, identifier);
157
+ }
158
+ if (node.type === distExports.AST_NODE_TYPES.ChainExpression) {
159
+ return expressionStartsWithIdentifier(node.expression, identifier);
160
+ }
161
+ return false;
162
+ }
140
163
  function expressionUsesThis(expression) {
141
164
  if (expression.type === distExports.AST_NODE_TYPES.AssignmentExpression) {
142
165
  return isThisReceiver(expression.left);
@@ -204,6 +227,21 @@ function getStatementKind(node) {
204
227
  if (isDirectivePrologue(node)) {
205
228
  return null;
206
229
  }
230
+ if (node.expression.type === distExports.AST_NODE_TYPES.AssignmentExpression) {
231
+ if (expressionUsesThis(node.expression)) {
232
+ return isSingleLine(node) ? "singleline-this" : "multiline-this";
233
+ }
234
+ return isSingleLine(node) ? "singleline-assignment" : "multiline-assignment";
235
+ }
236
+ if (isExpectExpression(node.expression)) {
237
+ return isSingleLine(node) ? "singleline-expect" : "multiline-expect";
238
+ }
239
+ if (isAssertExpression(node.expression)) {
240
+ return isSingleLine(node) ? "singleline-assert" : "multiline-assert";
241
+ }
242
+ if (isConsoleExpression(node.expression)) {
243
+ return isSingleLine(node) ? "singleline-console" : "multiline-console";
244
+ }
207
245
  if (expressionUsesThis(node.expression)) {
208
246
  return isSingleLine(node) ? "singleline-this" : "multiline-this";
209
247
  }
@@ -227,12 +265,21 @@ function hasLineCommentBetween(prevNode, nextNode, sourceCode) {
227
265
  return comment.range[0] >= prevNode.range[1] && comment.range[1] <= nextNode.range[0];
228
266
  });
229
267
  }
268
+ function isAssertExpression(expression) {
269
+ return expressionStartsWithIdentifier(expression, "assert");
270
+ }
271
+ function isConsoleExpression(expression) {
272
+ return expressionStartsWithIdentifier(expression, "console");
273
+ }
230
274
  function isDirectivePrologue(node) {
231
275
  if (node.expression.type !== distExports.AST_NODE_TYPES.Literal) {
232
276
  return false;
233
277
  }
234
278
  return typeof node.expression.value === "string";
235
279
  }
280
+ function isExpectExpression(expression) {
281
+ return expressionStartsWithIdentifier(expression, "expect");
282
+ }
236
283
  function isOwnLineComment(comment, sourceCode) {
237
284
  if (comment.type !== "Line") {
238
285
  return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saasmakers/eslint",
3
- "version": "1.0.12",
3
+ "version": "1.0.16",
4
4
  "private": false,
5
5
  "description": "Shared ESLint config and rules for SaaS Makers projects",
6
6
  "license": "MIT",