@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
- Program(node) {
16
- const body = node.body;
17
- const index = body.findIndex(
18
- (n) => n.type === "ExportDefaultDeclaration"
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
- const currentToken = body[index];
27
- const previousToken = sourceCode.getTokenBefore(currentToken);
28
-
29
- const isPadded =
30
- currentToken.loc.end.line - previousToken.loc.end.line > 1;
31
-
32
- if (isPadded) {
33
- return;
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: body[index],
50
+ node: targetNode,
38
51
  message: "Expected blank line before the default export.",
39
52
 
40
53
  fix(fixer) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@discourse/lint-configs",
3
- "version": "2.17.0",
3
+ "version": "2.17.2",
4
4
  "description": "Shareable lint configs for Discourse core, plugins, and themes",
5
5
  "author": "Discourse",
6
6
  "license": "MIT",