feat: use go tool
This commit is contained in:
+22
@@ -0,0 +1,22 @@
|
||||
// @ts-check
|
||||
|
||||
import { parse, printParseErrorCode } from "jsonc-parser";
|
||||
|
||||
/**
|
||||
* Parses a JSONC string, returning the corresponding object.
|
||||
* @type {import("markdownlint").ConfigurationParser}
|
||||
*/
|
||||
const jsoncParse = (text) => {
|
||||
/** @type {import("jsonc-parser").ParseError[]} */
|
||||
const errors = [];
|
||||
const result = parse(text, errors, { "allowTrailingComma": true });
|
||||
if (errors.length > 0) {
|
||||
const aggregate = errors.map(
|
||||
(error) => `${printParseErrorCode(error.error)} (offset ${error.offset}, length ${error.length})`
|
||||
).join(", ");
|
||||
throw new Error(`Unable to parse JSONC content, ${aggregate}`);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
export default jsoncParse;
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// @ts-check
|
||||
|
||||
import jsoncParse from "./jsonc-parse.mjs";
|
||||
import tomlParse from "./toml-parse.mjs";
|
||||
import yamlParse from "./yaml-parse.mjs";
|
||||
|
||||
/**
|
||||
* Array of parser objects ordered by priority.
|
||||
* @type {import("markdownlint").ConfigurationParser[]}
|
||||
*/
|
||||
const parsers = [
|
||||
jsoncParse,
|
||||
tomlParse,
|
||||
yamlParse
|
||||
];
|
||||
|
||||
export default parsers;
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// @ts-check
|
||||
|
||||
import { parse } from "smol-toml";
|
||||
|
||||
/**
|
||||
* Parses a TOML string, returning the corresponding object.
|
||||
* @type {import("markdownlint").ConfigurationParser}
|
||||
*/
|
||||
const tomlParse = (text) => parse(text);
|
||||
|
||||
export default tomlParse;
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// @ts-check
|
||||
|
||||
import yaml from "js-yaml";
|
||||
|
||||
/* eslint-disable arrow-body-style */
|
||||
|
||||
/**
|
||||
* Parses a YAML string, returning the corresponding object.
|
||||
* @type {import("markdownlint").ConfigurationParser}
|
||||
*/
|
||||
const yamlParse = (text) => {
|
||||
// @ts-ignore
|
||||
return yaml.load(text);
|
||||
};
|
||||
|
||||
export default yamlParse;
|
||||
Reference in New Issue
Block a user