@so1ve/eslint-plugin 3.23.0 → 3.25.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.
- package/dist/index.mjs +33 -23
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -259,23 +259,26 @@ const rule$7 = createEslintRule({
|
|
|
259
259
|
function checkExport(node) {
|
|
260
260
|
exportNodes.push(node);
|
|
261
261
|
}
|
|
262
|
-
function
|
|
262
|
+
function checkNewline(node, direction) {
|
|
263
263
|
let token;
|
|
264
|
-
let commentLine;
|
|
265
264
|
let expectedLine;
|
|
266
265
|
let tokenLine;
|
|
267
266
|
if (direction === "after") {
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
267
|
+
const endNode = sourceCode.getCommentsAfter(node).find((c) => c.loc.start.line === node.loc.end.line) ?? node;
|
|
268
|
+
token = sourceCode.getTokenAfter(endNode);
|
|
269
|
+
const nextComment = sourceCode.getCommentsAfter(endNode)[0];
|
|
270
|
+
expectedLine = endNode.loc.end.line + 1;
|
|
271
271
|
tokenLine = token?.loc.start.line;
|
|
272
|
-
|
|
273
|
-
token
|
|
274
|
-
|
|
275
|
-
expectedLine = node.loc.start.line - 1;
|
|
276
|
-
tokenLine = token?.loc.end.line;
|
|
272
|
+
const commentLine = nextComment?.loc.start.line;
|
|
273
|
+
if (token && (expectedLine === tokenLine || expectedLine === commentLine || tokenLine === endNode.loc.end.line) && token.value !== "}" && token.value !== "<\/script>") return endNode;
|
|
274
|
+
return null;
|
|
277
275
|
}
|
|
278
|
-
|
|
276
|
+
const startNode = sourceCode.getCommentsBefore(node)[0] || node;
|
|
277
|
+
token = sourceCode.getTokenBefore(startNode);
|
|
278
|
+
expectedLine = startNode.loc.start.line - 1;
|
|
279
|
+
tokenLine = token?.loc.end.line;
|
|
280
|
+
if (token && expectedLine === tokenLine) return startNode;
|
|
281
|
+
return null;
|
|
279
282
|
}
|
|
280
283
|
return {
|
|
281
284
|
ImportDeclaration(node) {
|
|
@@ -285,24 +288,31 @@ const rule$7 = createEslintRule({
|
|
|
285
288
|
ExportDefaultDeclaration: checkExport,
|
|
286
289
|
ExportAllDeclaration: checkExport,
|
|
287
290
|
"Program:exit"() {
|
|
288
|
-
|
|
291
|
+
const lastImportFixNode = lastImportNode ? checkNewline(lastImportNode, "after") : null;
|
|
292
|
+
if (lastImportNode && lastImportFixNode) context.report({
|
|
289
293
|
node: lastImportNode,
|
|
290
294
|
messageId: "newlineAfterLastImport",
|
|
291
|
-
fix: (fixer) => fixer.insertTextAfter(
|
|
295
|
+
fix: (fixer) => fixer.insertTextAfter(lastImportFixNode, "\n")
|
|
292
296
|
});
|
|
293
297
|
for (const node of exportNodes) {
|
|
294
298
|
const prevNode = getPreviousNode(node);
|
|
295
|
-
if ((!prevNode || !isExportDeclaration(prevNode)) && !
|
|
296
|
-
node,
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
299
|
+
if ((!prevNode || !isExportDeclaration(prevNode)) && (!lastImportNode || prevNode !== lastImportNode)) {
|
|
300
|
+
const beforeFixNode = checkNewline(node, "before");
|
|
301
|
+
if (beforeFixNode) context.report({
|
|
302
|
+
node,
|
|
303
|
+
messageId: "newlineBeforeExport",
|
|
304
|
+
fix: (fixer) => fixer.insertTextBefore(beforeFixNode, "\n")
|
|
305
|
+
});
|
|
306
|
+
}
|
|
300
307
|
const nextNode = getNextNode(node);
|
|
301
|
-
if (nextNode && !isExportDeclaration(nextNode)
|
|
302
|
-
node,
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
308
|
+
if (nextNode && !isExportDeclaration(nextNode)) {
|
|
309
|
+
const afterFixNode = checkNewline(node, "after");
|
|
310
|
+
if (afterFixNode) context.report({
|
|
311
|
+
node,
|
|
312
|
+
messageId: "newlineAfterExport",
|
|
313
|
+
fix: (fixer) => fixer.insertTextAfter(afterFixNode, "\n")
|
|
314
|
+
});
|
|
315
|
+
}
|
|
306
316
|
}
|
|
307
317
|
}
|
|
308
318
|
};
|