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

ota-meshi / eslint-plugin-json-schema-validator / 21107667783

18 Jan 2026 06:54AM UTC coverage: 35.082% (-52.3%) from 87.363%
21107667783

Pull #452

github

web-flow
Merge c9b05d9ff into bb8e97af5
Pull Request #452: Bundle using tsdown

177 of 507 branches covered (34.91%)

Branch coverage included in aggregate %.

8 of 20 new or added lines in 4 files covered. (40.0%)

518 existing lines in 13 files now uncovered.

338 of 961 relevant lines covered (35.17%)

9.52 hits per line

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

16.42
/src/utils/ast/json.ts
1
import type { AST as JSON } from "jsonc-eslint-parser";
21!
2
import type { GetNodeFromPath, NodeData } from "./common";
3

4
type TraverseTarget =
5
  | JSON.JSONProgram
6
  | JSON.JSONExpressionStatement
7
  | JSON.JSONObjectExpression
8
  | JSON.JSONArrayExpression;
9

10
const TRAVERSE_TARGET_TYPE: Set<string> = new Set([
1✔
11
  "Program",
12
  "JSONExpressionStatement",
13
  "JSONObjectExpression",
14
  "JSONArrayExpression",
15
] as TraverseTarget["type"][]);
16

17
const GET_JSON_NODES: Record<
18
  TraverseTarget["type"],
19
  GetNodeFromPath<JSON.JSONNode>
20
> = {
1✔
21
  Program(node: JSON.JSONProgram, _paths: string[]) {
UNCOV
22
    return { value: node.body[0] };
×
23
  },
24
  JSONExpressionStatement(
25
    node: JSON.JSONExpressionStatement,
26
    _paths: string[],
27
  ) {
UNCOV
28
    return { value: node.expression };
×
29
  },
30
  JSONObjectExpression(node: JSON.JSONObjectExpression, paths: string[]) {
UNCOV
31
    const path = String(paths.shift());
×
UNCOV
32
    for (const prop of node.properties) {
×
UNCOV
33
      if (prop.key.type === "JSONIdentifier") {
×
UNCOV
34
        if (prop.key.name === path) {
×
UNCOV
35
          return { key: () => prop.key.range, value: prop.value };
×
36
        }
37
      } else {
UNCOV
38
        if (String(prop.key.value) === path) {
×
UNCOV
39
          return { key: () => prop.key.range, value: prop.value };
×
40
        }
41
      }
42
    }
43
    throw new Error(`${"Unexpected state: ["}${[path, ...paths].join(", ")}]`);
×
44
  },
45
  JSONArrayExpression(node: JSON.JSONArrayExpression, paths: string[]) {
UNCOV
46
    const path = String(paths.shift());
×
UNCOV
47
    for (let index = 0; index < node.elements.length; index++) {
×
UNCOV
48
      if (String(index) !== path) {
×
UNCOV
49
        continue;
×
50
      }
UNCOV
51
      const element = node.elements[index];
×
52

UNCOV
53
      if (element) {
×
UNCOV
54
        return { value: element };
×
55
      }
UNCOV
56
      return {
×
57
        key: (sourceCode) => {
UNCOV
58
          const before = node.elements
×
59
            .slice(0, index)
60
            .reverse()
UNCOV
61
            .find((n) => n != null);
×
UNCOV
62
          let tokenIndex = before ? node.elements.indexOf(before) : -1;
×
UNCOV
63
          let token = before
×
64
            ? sourceCode.getTokenAfter(before)!
65
            : sourceCode.getFirstToken(node);
UNCOV
66
          while (tokenIndex < index) {
×
UNCOV
67
            tokenIndex++;
×
UNCOV
68
            token = sourceCode.getTokenAfter(token)!;
×
69
          }
70

UNCOV
71
          return [sourceCode.getTokenBefore(token)!.range![1], token.range![0]];
×
72
        },
73
        value: null,
74
      };
75
    }
76
    throw new Error(`${"Unexpected state: ["}${[path, ...paths].join(", ")}]`);
×
77
  },
78
};
79
/**
80
 * Get node from path
81
 */
82
export function getJSONNodeFromPath(
1✔
83
  node: JSON.JSONProgram,
84
  [...paths]: string[],
85
): NodeData<JSON.JSONNode> {
UNCOV
86
  let data: NodeData<JSON.JSONNode> = {
×
87
    key: (sourceCode) => {
UNCOV
88
      const dataNode = node.body[0].expression;
×
UNCOV
89
      if (
×
90
        dataNode.type === "JSONObjectExpression" ||
×
91
        dataNode.type === "JSONArrayExpression"
92
      ) {
UNCOV
93
        return sourceCode.getFirstToken(dataNode).range!;
×
94
      }
UNCOV
95
      return dataNode.range;
×
96
    },
97
    value: node,
98
  };
UNCOV
99
  while (paths.length && data.value) {
×
UNCOV
100
    if (!isTraverseTarget(data.value)) {
×
101
      throw new Error(`Unexpected node type: ${data.value.type}`);
×
102
    }
UNCOV
103
    data = GET_JSON_NODES[data.value.type](data.value as never, paths);
×
104
  }
UNCOV
105
  return data;
×
106
}
107

108
/**
109
 * Checks whether given node is traverse target.
110
 */
111
function isTraverseTarget(node: JSON.JSONNode): node is TraverseTarget {
2!
UNCOV
112
  return TRAVERSE_TARGET_TYPE.has(node.type);
×
113
}
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

© 2026 Coveralls, Inc