Skip to content

Commit

Permalink
fix(validation): allow string opts to md plugins
Browse files Browse the repository at this point in the history
Remark and Rehype plugins allow having options as a non-object type,
such as a string.

For instance, the official MDX docs even have an example of this:
See https://mdxjs.com/docs/extending-mdx/#using-plugins

The official plugin `remarkjs/remark-frontmatter` allows passing
a string, e.g. `"toml"` as the options arg, instead of an object.
  • Loading branch information
aloisklink committed Mar 23, 2022
1 parent 4b3f568 commit b67185b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ exports[`validation schemas rehypePluginsSchema: for value=[[]] 1`] = `"\\"[0]\\

exports[`validation schemas rehypePluginsSchema: for value=[[null,null]] 1`] = `"\\"[0]\\" does not match any of the allowed types"`;

exports[`validation schemas rehypePluginsSchema: for value=[[null,true]] 1`] = `"\\"[0]\\" does not match any of the allowed types"`;

exports[`validation schemas rehypePluginsSchema: for value=[3] 1`] = `"\\"[0]\\" does not match any of the allowed types"`;

exports[`validation schemas rehypePluginsSchema: for value=[false] 1`] = `"\\"[0]\\" does not match any of the allowed types"`;
Expand All @@ -50,8 +48,6 @@ exports[`validation schemas remarkPluginsSchema: for value=[[]] 1`] = `"\\"[0]\\

exports[`validation schemas remarkPluginsSchema: for value=[[null,null]] 1`] = `"\\"[0]\\" does not match any of the allowed types"`;

exports[`validation schemas remarkPluginsSchema: for value=[[null,true]] 1`] = `"\\"[0]\\" does not match any of the allowed types"`;

exports[`validation schemas remarkPluginsSchema: for value=[3] 1`] = `"\\"[0]\\" does not match any of the allowed types"`;

exports[`validation schemas remarkPluginsSchema: for value=[false] 1`] = `"\\"[0]\\" does not match any of the allowed types"`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ function testMarkdownPluginSchemas(schema: Joi.Schema) {
testOK([() => {}]);
testOK([[() => {}, {attr: 'val'}]]);
testOK([[() => {}, {attr: 'val'}], () => {}, [() => {}, {attr: 'val'}]]);
// cSpell:ignore remarkjs
// official `remarkjs/remark-frontmatter` plugin accepts string options
testOK([[() => {}, 'string-option']]);
testOK([[() => {}, true]]);

testFail(null);
testFail(false);
Expand All @@ -55,7 +59,6 @@ function testMarkdownPluginSchemas(schema: Joi.Schema) {
testFail([3]);
testFail([[]]);
testFail([[() => {}, undefined]]);
testFail([[() => {}, true]]);
}

describe('validation schemas', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const PluginIdSchema = Joi.string()

const MarkdownPluginsSchema = Joi.array()
.items(
Joi.array().ordered(Joi.function().required(), Joi.object().required()),
Joi.array().ordered(Joi.function().required(), Joi.any().required()),
Joi.function(),
Joi.object(),
)
Expand Down

0 comments on commit b67185b

Please sign in to comment.