@discourse/lint-configs 2.17.1 → 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",
@@ -13,23 +17,33 @@ export default {
13
17
 
14
18
  return {
15
19
  ExportDefaultDeclaration(node) {
16
- const declaration = node.declaration;
17
- const decorators = declaration?.decorators || [];
18
- const targetNode = decorators.length > 0 ? decorators[0] : node;
19
-
20
- const previousToken = sourceCode.getTokenBefore(targetNode, {
21
- includeComments: true,
22
- });
23
-
24
- if (!previousToken) {
25
- return;
20
+ let targetNode = node;
21
+ if (node.declaration?.decorators?.length) {
22
+ targetNode = node.declaration.decorators[0];
26
23
  }
27
24
 
28
- const isPadded =
29
- targetNode.loc.start.line - previousToken.loc.end.line > 1;
30
-
31
- if (isPadded) {
32
- 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;
33
47
  }
34
48
 
35
49
  context.report({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@discourse/lint-configs",
3
- "version": "2.17.1",
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",