86 lines
3.0 KiB
TypeScript
86 lines
3.0 KiB
TypeScript
/**
|
|
* @import { DocumentNode, AnyNode } from "@humanwhocodes/momoa";
|
|
* @import { Language, OkParseResult, ParseResult, File } from "@eslint/core";
|
|
* @typedef {OkParseResult<DocumentNode>} JSONOkParseResult
|
|
* @typedef {ParseResult<DocumentNode>} JSONParseResult
|
|
* @typedef {Object} JSONLanguageOptions
|
|
* @property {boolean} [allowTrailingCommas] Whether to allow trailing commas in JSONC mode.
|
|
*/
|
|
/**
|
|
* JSON Language Object
|
|
* @implements {Language<{ LangOptions: JSONLanguageOptions; Code: JSONSourceCode; RootNode: DocumentNode; Node: AnyNode }>}
|
|
*/
|
|
export class JSONLanguage implements Language {
|
|
/**
|
|
* Creates a new instance.
|
|
* @param {Object} options The options to use for this instance.
|
|
* @param {"json"|"jsonc"|"json5"} options.mode The parser mode to use.
|
|
*/
|
|
constructor({ mode }: {
|
|
mode: "json" | "jsonc" | "json5";
|
|
});
|
|
/**
|
|
* The type of file to read.
|
|
* @type {"text"}
|
|
*/
|
|
fileType: "text";
|
|
/**
|
|
* The line number at which the parser starts counting.
|
|
* @type {0|1}
|
|
*/
|
|
lineStart: 0 | 1;
|
|
/**
|
|
* The column number at which the parser starts counting.
|
|
* @type {0|1}
|
|
*/
|
|
columnStart: 0 | 1;
|
|
/**
|
|
* The name of the key that holds the type of the node.
|
|
* @type {string}
|
|
*/
|
|
nodeTypeKey: string;
|
|
/**
|
|
* The visitor keys.
|
|
* @type {Record<string, string[]>}
|
|
*/
|
|
visitorKeys: Record<string, string[]>;
|
|
/**
|
|
* Validates the language options.
|
|
* @param {JSONLanguageOptions} languageOptions The language options to validate.
|
|
* @returns {void}
|
|
* @throws {Error} When the language options are invalid.
|
|
*/
|
|
validateLanguageOptions(languageOptions: JSONLanguageOptions): void;
|
|
/**
|
|
* Parses the given file into an AST.
|
|
* @param {File} file The virtual file to parse.
|
|
* @param {{languageOptions: JSONLanguageOptions}} context The options to use for parsing.
|
|
* @returns {JSONParseResult} The result of parsing.
|
|
*/
|
|
parse(file: File, context: {
|
|
languageOptions: JSONLanguageOptions;
|
|
}): JSONParseResult;
|
|
/**
|
|
* Creates a new `JSONSourceCode` object from the given information.
|
|
* @param {File} file The virtual file to create a `JSONSourceCode` object from.
|
|
* @param {JSONOkParseResult} parseResult The result returned from `parse()`.
|
|
* @returns {JSONSourceCode} The new `JSONSourceCode` object.
|
|
*/
|
|
createSourceCode(file: File, parseResult: JSONOkParseResult): JSONSourceCode;
|
|
#private;
|
|
}
|
|
export type JSONOkParseResult = OkParseResult<DocumentNode>;
|
|
export type JSONParseResult = ParseResult<DocumentNode>;
|
|
export type JSONLanguageOptions = {
|
|
/**
|
|
* Whether to allow trailing commas in JSONC mode.
|
|
*/
|
|
allowTrailingCommas?: boolean;
|
|
};
|
|
import type { Language } from "@eslint/core";
|
|
import type { File } from "@eslint/core";
|
|
import { JSONSourceCode } from "./json-source-code.js";
|
|
import type { DocumentNode } from "@humanwhocodes/momoa";
|
|
import type { OkParseResult } from "@eslint/core";
|
|
import type { ParseResult } from "@eslint/core";
|