-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathvalidate-yaml.ts
More file actions
45 lines (38 loc) · 1.13 KB
/
validate-yaml.ts
File metadata and controls
45 lines (38 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.
/**
* YAML syntax checker — validates .yml and .yaml files.
*
* @module
*/
import * as yaml from "yaml";
import * as standards from "@eserstack/standards";
import { createFileTool, type FileTool } from "./file-tool.ts";
export const tool: FileTool = createFileTool({
name: "validate-yaml",
description: "Validate YAML syntax",
canFix: false,
stacks: [],
defaults: {},
extensions: ["yml", "yaml"],
checkFile(file, content) {
if (content === undefined) {
return [];
}
try {
yaml.parse(content);
return [];
} catch (error) {
const message = error instanceof Error ? error.message : "invalid YAML";
return [{ path: file.path, message }];
}
},
});
export const run: FileTool["run"] = tool.run;
export const validator: FileTool["validator"] = tool.validator;
export const main: FileTool["main"] = tool.main;
if (import.meta.main) {
const { runCliMain } = await import("./cli-support.ts");
runCliMain(
await main(standards.crossRuntime.runtime.process.args as string[]),
);
}