• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ota-meshi / eslint-plugin-yml / 7834400087

08 Feb 2024 06:43PM UTC coverage: 90.377%. Remained the same
7834400087

push

github

renovate[bot]
chore(deps): update dependency esbuild to ^0.20.0

1604 of 1853 branches covered (0.0%)

Branch coverage included in aggregate %.

2284 of 2449 relevant lines covered (93.26%)

623.05 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

85.45
/src/rules/no-empty-sequence-entry.ts
1
import type { AST } from "yaml-eslint-parser";
6✔
2
import { createRule } from "../utils";
1✔
3
import { isHyphen } from "../utils/ast-utils";
1✔
4
import { getSourceCode } from "../utils/compat";
1✔
5

6
export default createRule("no-empty-sequence-entry", {
1✔
7
  meta: {
8
    docs: {
9
      description: "disallow empty sequence entries",
10
      categories: ["recommended", "standard"],
11
      extensionRule: false,
12
      layout: false,
13
    },
14
    schema: [],
15
    messages: {
16
      unexpectedEmpty: "Empty sequence entries are forbidden.",
17
    },
18
    type: "suggestion",
19
  },
20
  create(context) {
21
    const sourceCode = getSourceCode(context);
8✔
22
    if (!sourceCode.parserServices.isYAML) {
8✔
23
      return {};
1✔
24
    }
25

26
    /**
27
     * Checks if the given node is empty
28
     */
29
    function isEmptyNode(
30
      node: AST.YAMLContent | AST.YAMLWithMeta | null,
31
    ): boolean {
32
      if (!node) {
32✔
33
        return true;
8✔
34
      }
35
      if (node.type === "YAMLWithMeta") {
24✔
36
        return isEmptyNode(node.value);
4✔
37
      }
38

39
      return false;
20✔
40
    }
41

42
    return {
7✔
43
      YAMLSequence(node: AST.YAMLSequence) {
44
        if (node.style !== "block") {
7!
45
          return;
×
46
        }
47
        node.entries.forEach((entry, index) => {
7✔
48
          if (isEmptyNode(entry)) {
28✔
49
            context.report({
8✔
50
              node: getHyphen(node, index) || node,
8!
51
              messageId: "unexpectedEmpty",
52
            });
53
          }
54
        });
55
      },
56
    };
57

58
    /**
59
     * Get hyphen token from given entry index
60
     */
61
    function getHyphen(
62
      node: AST.YAMLBlockSequence,
63
      index: number,
64
    ): AST.Token | null {
65
      if (index === 0) {
12✔
66
        const token = sourceCode.getFirstToken(node);
5✔
67
        return isHyphen(token) ? token : null;
5!
68
      }
69
      const prev = node.entries[index - 1];
7✔
70
      if (prev) {
7✔
71
        const token = sourceCode.getTokenAfter(prev);
3✔
72
        return isHyphen(token) ? token : null;
3!
73
      }
74
      const prevHyphen = getHyphen(node, index - 1);
4✔
75
      if (prevHyphen) {
4!
76
        const token = sourceCode.getTokenAfter(prevHyphen);
4✔
77
        return isHyphen(token) ? token : null;
4!
78
      }
79
      return null;
×
80
    }
81
  },
82
});
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc