Skip to content

Commit

Permalink
more renames
Browse files Browse the repository at this point in the history
File --> InputFile
  • Loading branch information
chris48s committed Aug 19, 2024
1 parent e85d156 commit 4b97121
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 18 deletions.
2 changes: 1 addition & 1 deletion docs/docs/plugins/writing-plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down
4 changes: 2 additions & 2 deletions src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 8 additions & 7 deletions src/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}

Expand Down
6 changes: 3 additions & 3 deletions src/plugins.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]);
Expand All @@ -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",
},
);
});
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/parser-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/parser-json5.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/parser-toml.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/parser-yaml.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion testfiles/plugins/bad-parse-method.js
Original file line number Diff line number Diff line change
Expand Up @@ -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" };
Expand Down

0 comments on commit 4b97121

Please sign in to comment.