From 4b97121b32fb4278ba37e7022456160a6326fcc6 Mon Sep 17 00:00:00 2001 From: chris48s Date: Mon, 19 Aug 2024 13:47:11 +0100 Subject: [PATCH] more renames File --> InputFile --- docs/docs/plugins/writing-plugins.md | 2 +- src/parser.js | 4 ++-- src/plugins.js | 15 ++++++++------- src/plugins.spec.js | 6 +++--- src/plugins/parser-json.js | 2 +- src/plugins/parser-json5.js | 2 +- src/plugins/parser-toml.js | 2 +- src/plugins/parser-yaml.js | 2 +- testfiles/plugins/bad-parse-method.js | 2 +- 9 files changed, 19 insertions(+), 18 deletions(-) diff --git a/docs/docs/plugins/writing-plugins.md b/docs/docs/plugins/writing-plugins.md index a2335f2..545b97c 100644 --- a/docs/docs/plugins/writing-plugins.md +++ b/docs/docs/plugins/writing-plugins.md @@ -29,7 +29,7 @@ These hooks return an array of strings. Any values returned by these hooks are a ### Early Return Hooks -- `parseFile` +- `parseInputFile` - `getSingleResultLogMessage` - `getAllResultsLogMessage` 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 4ede8b1..fa2470f 100644 --- a/src/plugins.js +++ b/src/plugins.js @@ -27,11 +27,12 @@ class BasePlugin { } /** - * 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 1479ab4..0b5d43b 100644 --- a/src/plugins.spec.js +++ b/src/plugins.spec.js @@ -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 4f9457d..e8c3e82 100644 --- a/src/plugins/parser-json.js +++ b/src/plugins/parser-json.js @@ -7,7 +7,7 @@ class JsonParser extends BasePlugin { 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 3586525..c37a27f 100644 --- a/src/plugins/parser-json5.js +++ b/src/plugins/parser-json5.js @@ -8,7 +8,7 @@ class Json5Parser extends BasePlugin { 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 c64188c..92efb4f 100644 --- a/src/plugins/parser-toml.js +++ b/src/plugins/parser-toml.js @@ -8,7 +8,7 @@ class TomlParser extends BasePlugin { 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 ab45936..6d59e71 100644 --- a/src/plugins/parser-yaml.js +++ b/src/plugins/parser-yaml.js @@ -8,7 +8,7 @@ class YamlParser extends BasePlugin { 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" };