From 4d2ab826b8f5ebfc4f52c6bda86d0483facaefec Mon Sep 17 00:00:00 2001 From: Alois Klink Date: Thu, 24 Mar 2022 01:19:06 +0000 Subject: [PATCH] fix(validation): allow non-object params to remark/rehype plugins (#6977) 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. --- .../__tests__/__snapshots__/validationSchemas.test.ts.snap | 4 ---- .../src/__tests__/validationSchemas.test.ts | 5 ++++- .../docusaurus-utils-validation/src/validationSchemas.ts | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/packages/docusaurus-utils-validation/src/__tests__/__snapshots__/validationSchemas.test.ts.snap b/packages/docusaurus-utils-validation/src/__tests__/__snapshots__/validationSchemas.test.ts.snap index e4882b22b3..56a45cbbc2 100644 --- a/packages/docusaurus-utils-validation/src/__tests__/__snapshots__/validationSchemas.test.ts.snap +++ b/packages/docusaurus-utils-validation/src/__tests__/__snapshots__/validationSchemas.test.ts.snap @@ -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"`; @@ -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"`; diff --git a/packages/docusaurus-utils-validation/src/__tests__/validationSchemas.test.ts b/packages/docusaurus-utils-validation/src/__tests__/validationSchemas.test.ts index 6f6f28f315..534ac218fd 100644 --- a/packages/docusaurus-utils-validation/src/__tests__/validationSchemas.test.ts +++ b/packages/docusaurus-utils-validation/src/__tests__/validationSchemas.test.ts @@ -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); @@ -55,7 +59,6 @@ function testMarkdownPluginSchemas(schema: Joi.Schema) { testFail([3]); testFail([[]]); testFail([[() => {}, undefined]]); - testFail([[() => {}, true]]); } describe('validation schemas', () => { diff --git a/packages/docusaurus-utils-validation/src/validationSchemas.ts b/packages/docusaurus-utils-validation/src/validationSchemas.ts index d7b23b7cc8..bf2bf6826f 100644 --- a/packages/docusaurus-utils-validation/src/validationSchemas.ts +++ b/packages/docusaurus-utils-validation/src/validationSchemas.ts @@ -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(), )