@discourse/lint-configs 2.17.0 → 2.17.2
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.
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
function isCommentNode(node) {
|
|
2
|
+
return node.type === "Line" || node.type === "Block";
|
|
3
|
+
}
|
|
4
|
+
|
|
1
5
|
export default {
|
|
2
6
|
meta: {
|
|
3
7
|
type: "layout",
|
|
@@ -12,29 +16,38 @@ export default {
|
|
|
12
16
|
const sourceCode = context.sourceCode;
|
|
13
17
|
|
|
14
18
|
return {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
);
|
|
20
|
-
|
|
21
|
-
if (index === -1 || index === 0) {
|
|
22
|
-
// No default export or starts with the export
|
|
23
|
-
return;
|
|
19
|
+
ExportDefaultDeclaration(node) {
|
|
20
|
+
let targetNode = node;
|
|
21
|
+
if (node.declaration?.decorators?.length) {
|
|
22
|
+
targetNode = node.declaration.decorators[0];
|
|
24
23
|
}
|
|
25
24
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
25
|
+
let previousToken;
|
|
26
|
+
while (true) {
|
|
27
|
+
previousToken = sourceCode.getTokenBefore(targetNode, {
|
|
28
|
+
includeComments: true,
|
|
29
|
+
});
|
|
30
|
+
if (!previousToken) {
|
|
31
|
+
// Top of file, no need for newline
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const isPadded =
|
|
36
|
+
targetNode.loc.start.line - previousToken.loc.end.line > 1;
|
|
37
|
+
if (isPadded) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (isCommentNode(previousToken)) {
|
|
42
|
+
targetNode = previousToken;
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
break;
|
|
34
47
|
}
|
|
35
48
|
|
|
36
49
|
context.report({
|
|
37
|
-
node:
|
|
50
|
+
node: targetNode,
|
|
38
51
|
message: "Expected blank line before the default export.",
|
|
39
52
|
|
|
40
53
|
fix(fixer) {
|