-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathvalidate-toml.ts
More file actions
45 lines (38 loc) · 1.12 KB
/
validate-toml.ts
File metadata and controls
45 lines (38 loc) · 1.12 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.
/**
* TOML syntax checker — validates .toml files.
*
* @module
*/
import * as toml from "@std/toml";
import * as standards from "@eserstack/standards";
import { createFileTool, type FileTool } from "./file-tool.ts";
export const tool: FileTool = createFileTool({
name: "validate-toml",
description: "Validate TOML syntax",
canFix: false,
stacks: [],
defaults: {},
extensions: ["toml"],
checkFile(file, content) {
if (content === undefined) {
return [];
}
try {
toml.parse(content);
return [];
} catch (error) {
const message = error instanceof Error ? error.message : "invalid TOML";
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[]),
);
}