@saasmakers/eslint 1.0.6 → 1.0.7

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
@@ -163,26 +163,8 @@ function getBlankLineRequirement(prevNode, nextNode) {
163
163
  }
164
164
  return "always";
165
165
  }
166
- function getPaddingLineSequences(prevNode, nextNode, sourceCode) {
167
- const pairs = [];
168
- const prevToken = getActualLastToken(prevNode, sourceCode);
169
- if (!prevToken) {
170
- return pairs;
171
- }
172
- if (nextNode.loc.start.line - prevToken.loc.end.line >= 2) {
173
- let currentToken = prevToken;
174
- while (currentToken.range[0] < nextNode.range[0]) {
175
- const token = sourceCode.getTokenAfter(currentToken, { includeComments: true });
176
- if (!token || token.range[0] >= nextNode.range[0]) {
177
- break;
178
- }
179
- if (token.loc.start.line - currentToken.loc.end.line >= 2) {
180
- pairs.push([currentToken, token]);
181
- }
182
- currentToken = token;
183
- }
184
- }
185
- return pairs;
166
+ function hasBlankLineBetween(prevNode, nextNode) {
167
+ return nextNode.loc.start.line - prevNode.loc.end.line > 1;
186
168
  }
187
169
  function isAwaitStatement(node) {
188
170
  return node.type === index$1.distExports.AST_NODE_TYPES.ExpressionStatement && node.expression.type === index$1.distExports.AST_NODE_TYPES.AwaitExpression;
@@ -231,42 +213,31 @@ const rule$a = {
231
213
  if (prevNode) {
232
214
  const requirement = getBlankLineRequirement(prevNode, node);
233
215
  if (requirement) {
234
- const paddingLines = getPaddingLineSequences(prevNode, node, sourceCode);
235
- if (requirement === "never" && paddingLines.length > 0) {
216
+ const hasBlank = hasBlankLineBetween(prevNode, node);
217
+ if (requirement === "never" && hasBlank) {
236
218
  context.report({
237
219
  fix(fixer) {
238
- if (paddingLines.length >= 2) {
220
+ const lastToken = getActualLastToken(prevNode, sourceCode);
221
+ const firstToken = sourceCode.getFirstToken(node);
222
+ if (!lastToken || !firstToken) {
239
223
  return null;
240
224
  }
241
- const [prevToken, nextToken] = paddingLines[0];
242
- const start = prevToken.range[1];
243
- const end = nextToken.range[0];
225
+ const start = lastToken.range[1];
226
+ const end = firstToken.range[0];
244
227
  const text = collapseBlankLine(sourceCode.text.slice(start, end));
245
228
  return fixer.replaceTextRange([start, end], text);
246
229
  },
247
230
  messageId: "unexpectedBlankLine",
248
231
  node
249
232
  });
250
- } else if (requirement === "always" && paddingLines.length === 0) {
233
+ } else if (requirement === "always" && !hasBlank) {
251
234
  context.report({
252
235
  fix(fixer) {
253
236
  const lastToken = getActualLastToken(prevNode, sourceCode);
254
237
  if (!lastToken) {
255
238
  return null;
256
239
  }
257
- let currentPrevToken = lastToken;
258
- const nextToken = sourceCode.getFirstTokenBetween(currentPrevToken, node, {
259
- filter(token) {
260
- if (token.loc.start.line === currentPrevToken.loc.start.line) {
261
- currentPrevToken = token;
262
- return false;
263
- }
264
- return true;
265
- },
266
- includeComments: true
267
- }) || node;
268
- const insertText = currentPrevToken.loc.end.line === nextToken.loc.start.line ? "\n\n" : "\n";
269
- return fixer.insertTextAfter(currentPrevToken, insertText);
240
+ return fixer.insertTextAfter(lastToken, "\n");
270
241
  },
271
242
  messageId: "expectedBlankLine",
272
243
  node
package/dist/index.mjs CHANGED
@@ -161,26 +161,8 @@ function getBlankLineRequirement(prevNode, nextNode) {
161
161
  }
162
162
  return "always";
163
163
  }
164
- function getPaddingLineSequences(prevNode, nextNode, sourceCode) {
165
- const pairs = [];
166
- const prevToken = getActualLastToken(prevNode, sourceCode);
167
- if (!prevToken) {
168
- return pairs;
169
- }
170
- if (nextNode.loc.start.line - prevToken.loc.end.line >= 2) {
171
- let currentToken = prevToken;
172
- while (currentToken.range[0] < nextNode.range[0]) {
173
- const token = sourceCode.getTokenAfter(currentToken, { includeComments: true });
174
- if (!token || token.range[0] >= nextNode.range[0]) {
175
- break;
176
- }
177
- if (token.loc.start.line - currentToken.loc.end.line >= 2) {
178
- pairs.push([currentToken, token]);
179
- }
180
- currentToken = token;
181
- }
182
- }
183
- return pairs;
164
+ function hasBlankLineBetween(prevNode, nextNode) {
165
+ return nextNode.loc.start.line - prevNode.loc.end.line > 1;
184
166
  }
185
167
  function isAwaitStatement(node) {
186
168
  return node.type === distExports.AST_NODE_TYPES.ExpressionStatement && node.expression.type === distExports.AST_NODE_TYPES.AwaitExpression;
@@ -229,42 +211,31 @@ const rule$a = {
229
211
  if (prevNode) {
230
212
  const requirement = getBlankLineRequirement(prevNode, node);
231
213
  if (requirement) {
232
- const paddingLines = getPaddingLineSequences(prevNode, node, sourceCode);
233
- if (requirement === "never" && paddingLines.length > 0) {
214
+ const hasBlank = hasBlankLineBetween(prevNode, node);
215
+ if (requirement === "never" && hasBlank) {
234
216
  context.report({
235
217
  fix(fixer) {
236
- if (paddingLines.length >= 2) {
218
+ const lastToken = getActualLastToken(prevNode, sourceCode);
219
+ const firstToken = sourceCode.getFirstToken(node);
220
+ if (!lastToken || !firstToken) {
237
221
  return null;
238
222
  }
239
- const [prevToken, nextToken] = paddingLines[0];
240
- const start = prevToken.range[1];
241
- const end = nextToken.range[0];
223
+ const start = lastToken.range[1];
224
+ const end = firstToken.range[0];
242
225
  const text = collapseBlankLine(sourceCode.text.slice(start, end));
243
226
  return fixer.replaceTextRange([start, end], text);
244
227
  },
245
228
  messageId: "unexpectedBlankLine",
246
229
  node
247
230
  });
248
- } else if (requirement === "always" && paddingLines.length === 0) {
231
+ } else if (requirement === "always" && !hasBlank) {
249
232
  context.report({
250
233
  fix(fixer) {
251
234
  const lastToken = getActualLastToken(prevNode, sourceCode);
252
235
  if (!lastToken) {
253
236
  return null;
254
237
  }
255
- let currentPrevToken = lastToken;
256
- const nextToken = sourceCode.getFirstTokenBetween(currentPrevToken, node, {
257
- filter(token) {
258
- if (token.loc.start.line === currentPrevToken.loc.start.line) {
259
- currentPrevToken = token;
260
- return false;
261
- }
262
- return true;
263
- },
264
- includeComments: true
265
- }) || node;
266
- const insertText = currentPrevToken.loc.end.line === nextToken.loc.start.line ? "\n\n" : "\n";
267
- return fixer.insertTextAfter(currentPrevToken, insertText);
238
+ return fixer.insertTextAfter(lastToken, "\n");
268
239
  },
269
240
  messageId: "expectedBlankLine",
270
241
  node
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saasmakers/eslint",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "private": false,
5
5
  "description": "Shared ESLint config and rules for SaaS Makers projects",
6
6
  "license": "MIT",