Skip to content

Commit

Permalink
fix: crash on empty yaml (#348)
Browse files Browse the repository at this point in the history
* fix: crash on empty yaml

* Create giant-wolves-tie.md
  • Loading branch information
ota-meshi authored Sep 14, 2024
1 parent b52c7e3 commit dab937c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/giant-wolves-tie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"eslint-plugin-json-schema-validator": patch
---

fix: crash on empty yaml
7 changes: 4 additions & 3 deletions src/utils/ast/yaml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,13 @@ export function getYAMLNodeFromPath(
): NodeData<YAML.YAMLNode> {
let data: NodeData<YAML.YAMLNode> = {
key: (sourceCode) => {
const doc = node.body[0];
if (node.body.length > 1) {
return sourceCode.getFirstToken(node.body[0]).range!;
return (sourceCode.getFirstToken(doc) || doc).range!;
}
const dataNode = node.body[0].content;
const dataNode = doc.content;
if (dataNode == null) {
return sourceCode.getFirstToken(node.body[0]).range!;
return (sourceCode.getFirstToken(doc) || doc).range!;
}
if (dataNode.type === "YAMLMapping" || dataNode.type === "YAMLSequence") {
return sourceCode.getFirstToken(dataNode).range!;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[
{
"message": "Root must be object.",
"line": 1,
"column": 1,
"endLine": 2,
"endColumn": 8
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# empty

0 comments on commit dab937c

Please sign in to comment.