diff --git a/docs/docs/plugins/writing-plugins.md b/docs/docs/plugins/writing-plugins.md index ea33899..545b97c 100644 --- a/docs/docs/plugins/writing-plugins.md +++ b/docs/docs/plugins/writing-plugins.md @@ -22,14 +22,14 @@ There are two patterns used by v8r plugin hooks. ### Register Hooks -- `registerFileParsers` +- `registerInputFileParsers` - `registerOutputFormats` These hooks return an array of strings. Any values returned by these hooks are added to the list of formats v8r can work with. ### Early Return Hooks -- `parseFile` +- `parseInputFile` - `getSingleResultLogMessage` - `getAllResultsLogMessage` diff --git a/src/bootstrap.js b/src/bootstrap.js index c61f37a..f182d8a 100644 --- a/src/bootstrap.js +++ b/src/bootstrap.js @@ -158,7 +158,7 @@ function parseArgs(argv, config, documentFormats, outputFormats) { function getDocumentFormats(loadedPlugins) { let documentFormats = []; for (const plugin of loadedPlugins) { - documentFormats = documentFormats.concat(plugin.registerFileParsers()); + documentFormats = documentFormats.concat(plugin.registerInputFileParsers()); } return documentFormats; } diff --git a/src/parser.js b/src/parser.js index 5a39a85..b6a84c1 100644 --- a/src/parser.js +++ b/src/parser.js @@ -4,11 +4,11 @@ import { Document } from "./plugins.js"; function parseFile(plugins, contents, filename, parser) { for (const plugin of plugins) { - const result = plugin.parseFile(contents, filename, parser); + const result = plugin.parseInputFile(contents, filename, parser); if (result != null) { if (!(result instanceof Document)) { throw new Error( - `Plugin ${plugin.constructor.name} returned an unexpcted type from parseFile hook. Expected Document, got ${typeof result}`, + `Plugin ${plugin.constructor.name} returned an unexpected type from parseInputFile hook. Expected Document, got ${typeof result}`, ); } return result.document; diff --git a/src/plugins.js b/src/plugins.js index a0e52fd..fa2470f 100644 --- a/src/plugins.js +++ b/src/plugins.js @@ -16,22 +16,23 @@ class BasePlugin { static name = "untitled plugin"; /** - * Use the `registerFileParsers` hook to tell v8r about additional file + * Use the `registerInputFileParsers` hook to tell v8r about additional file * formats that can be parsed. Any parsers registered with this hook become * valid values for the `parser` property in custom schemas. * * @returns {string[]} File parsers to register */ - registerFileParsers() { + registerInputFileParsers() { return []; } /** - * Use the `parseFile` hook to tell v8r how to parse files. + * Use the `parseInputFile` hook to tell v8r how to parse files. * - * If `parseFile` returns anything other than undefined, that return value - * will be used and no further plugins will be invoked. If `parseFile` returns - * undefined, v8r will move on to the next plugin in the stack. + * If `parseInputFile` returns anything other than undefined, that return + * value will be used and no further plugins will be invoked. If + * `parseInputFile` returns undefined, v8r will move on to the next plugin in + * the stack. * * @param {string} contents - The unparsed file content. * @param {string} fileLocation - The file path. Filenames are resolved and @@ -40,12 +41,12 @@ class BasePlugin { * will be prefixed with `./` (or `.\` on Windows) even if this was not * present in the input filename or pattern. * @param {string | undefined} parser - If the user has specified a parser to - * use for this file in a custom schema, this will be passed to `parseFile` - * in the `parser` param. + * use for this file in a custom schema, this will be passed to + * `parseInputFile` in the `parser` param. * @returns {Document | undefined} Parsed file contents */ // eslint-disable-next-line no-unused-vars - parseFile(contents, fileLocation, parser) { + parseInputFile(contents, fileLocation, parser) { return undefined; } diff --git a/src/plugins.spec.js b/src/plugins.spec.js index 8331a54..0b5d43b 100644 --- a/src/plugins.spec.js +++ b/src/plugins.spec.js @@ -63,7 +63,7 @@ describe("loadAllPlugins", function () { { name: "Error", message: - "Error loading plugin v8r-plugin-test-invalid-params: registerFileParsers must take exactly 0 arguments", + "Error loading plugin v8r-plugin-test-invalid-params: registerInputFileParsers must take exactly 0 arguments", }, ); }); @@ -85,8 +85,8 @@ describe("resolveUserPlugins", function () { }); }); -describe("parseFile", function () { - it("throws when parseFile returns unexpected type", async function () { +describe("parseInputFile", function () { + it("throws when parseInputFile returns unexpected type", async function () { const plugins = await loadAllPlugins([ "../testfiles/plugins/bad-parse-method.js", ]); @@ -95,7 +95,7 @@ describe("parseFile", function () { { name: "Error", message: - "Plugin v8r-plugin-test-bad-parse-method returned an unexpcted type from parseFile hook. Expected Document, got object", + "Plugin v8r-plugin-test-bad-parse-method returned an unexpected type from parseInputFile hook. Expected Document, got object", }, ); }); diff --git a/src/plugins/parser-json.js b/src/plugins/parser-json.js index 5575831..e8c3e82 100644 --- a/src/plugins/parser-json.js +++ b/src/plugins/parser-json.js @@ -3,11 +3,11 @@ import { BasePlugin, Document } from "../plugins.js"; class JsonParser extends BasePlugin { static name = "v8r-plugin-json-parser"; - registerFileParsers() { + registerInputFileParsers() { return ["json"]; } - parseFile(contents, fileLocation, parser) { + parseInputFile(contents, fileLocation, parser) { if (parser === "json") { return new Document(JSON.parse(contents)); } else if (parser == null) { diff --git a/src/plugins/parser-json5.js b/src/plugins/parser-json5.js index dfda7ae..c37a27f 100644 --- a/src/plugins/parser-json5.js +++ b/src/plugins/parser-json5.js @@ -4,11 +4,11 @@ import { BasePlugin, Document } from "../plugins.js"; class Json5Parser extends BasePlugin { static name = "v8r-plugin-json5-parser"; - registerFileParsers() { + registerInputFileParsers() { return ["json5"]; } - parseFile(contents, fileLocation, parser) { + parseInputFile(contents, fileLocation, parser) { if (parser === "json5") { return new Document(JSON5.parse(contents)); } else if (parser == null) { diff --git a/src/plugins/parser-toml.js b/src/plugins/parser-toml.js index 3b7d256..92efb4f 100644 --- a/src/plugins/parser-toml.js +++ b/src/plugins/parser-toml.js @@ -4,11 +4,11 @@ import { BasePlugin, Document } from "../plugins.js"; class TomlParser extends BasePlugin { static name = "v8r-plugin-toml-parser"; - registerFileParsers() { + registerInputFileParsers() { return ["toml"]; } - parseFile(contents, fileLocation, parser) { + parseInputFile(contents, fileLocation, parser) { if (parser === "toml") { return new Document(parse(contents)); } else if (parser == null) { diff --git a/src/plugins/parser-yaml.js b/src/plugins/parser-yaml.js index 94243af..6d59e71 100644 --- a/src/plugins/parser-yaml.js +++ b/src/plugins/parser-yaml.js @@ -4,11 +4,11 @@ import { BasePlugin, Document } from "../plugins.js"; class YamlParser extends BasePlugin { static name = "v8r-plugin-yaml-parser"; - registerFileParsers() { + registerInputFileParsers() { return ["yaml"]; } - parseFile(contents, fileLocation, parser) { + parseInputFile(contents, fileLocation, parser) { if (parser === "yaml") { return new Document(yaml.load(contents)); } else if (parser == null) { diff --git a/testfiles/plugins/bad-parse-method.js b/testfiles/plugins/bad-parse-method.js index 364b7b7..7966265 100644 --- a/testfiles/plugins/bad-parse-method.js +++ b/testfiles/plugins/bad-parse-method.js @@ -4,7 +4,7 @@ export default class ValidTestPlugin extends BasePlugin { static name = "v8r-plugin-test-bad-parse-method"; // eslint-disable-next-line no-unused-vars - parseFile(contents, fileLocation, parser) { + parseInputFile(contents, fileLocation, parser) { // this method returns something other than a Document object, // which should cause a failure return { foo: "bar" }; diff --git a/testfiles/plugins/invalid-params.js b/testfiles/plugins/invalid-params.js index 1e4f67a..14e46bc 100644 --- a/testfiles/plugins/invalid-params.js +++ b/testfiles/plugins/invalid-params.js @@ -4,7 +4,7 @@ export default class InvalidParamsTestPlugin extends BasePlugin { static name = "v8r-plugin-test-invalid-params"; // eslint-disable-next-line no-unused-vars - registerFileParsers(foo) { + registerInputFileParsers(foo) { return []; } }