Skip to content

Commit

Permalink
Fix prop types of plugins
Browse files Browse the repository at this point in the history
Closes GH-683.
Related-to: remarkjs/remark#945.

Reviewed-by: Christian Murphy <christian.murphy.42@gmail.com>
Reviewed-by: Titus Wormer <tituswormer@gmail.com>
  • Loading branch information
starpit committed Apr 20, 2022
1 parent 8143c12 commit a2fb833
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 2 deletions.
28 changes: 26 additions & 2 deletions lib/react-markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,38 @@ ReactMarkdown.propTypes = {
PropTypes.oneOfType([
PropTypes.object,
PropTypes.func,
PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.object, PropTypes.func]))
PropTypes.arrayOf(
PropTypes.oneOfType([
PropTypes.bool,
PropTypes.string,
PropTypes.object,
PropTypes.func,
PropTypes.arrayOf(
// prettier-ignore
// type-coverage:ignore-next-line
PropTypes.any
)
])
)
])
),
rehypePlugins: PropTypes.arrayOf(
PropTypes.oneOfType([
PropTypes.object,
PropTypes.func,
PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.object, PropTypes.func]))
PropTypes.arrayOf(
PropTypes.oneOfType([
PropTypes.bool,
PropTypes.string,
PropTypes.object,
PropTypes.func,
PropTypes.arrayOf(
// prettier-ignore
// type-coverage:ignore-next-line
PropTypes.any
)
])
)
])
),
// Transform options:
Expand Down
46 changes: 46 additions & 0 deletions test/test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1424,4 +1424,50 @@ test('should crash on a plugin replacing `root`', () => {
}, /Expected a `root` node/)
})

test('should support remark plugins with array parameter', async () => {
const error = console.error
/** @type {string} */
let message = ''

console.error = (/** @type {string} */ d) => {
message = d
}

const input = 'a'
/** @type {import('unified').Plugin<Array<Array<string>>, Root>} */
const plugin = () => () => {}

const actual = asHtml(
<Markdown children={input} remarkPlugins={[[plugin, ['foo', 'bar']]]} />
)
const expected = '<p>a</p>'
assert.equal(actual, expected)

assert.not.match(message, /Warning: Failed/, 'Prop types should be valid')
console.error = error
})

test('should support rehype plugins with array parameter', async () => {
const error = console.error
/** @type {string} */
let message = ''

console.error = (/** @type {string} */ d) => {
message = d
}

const input = 'a'
/** @type {import('unified').Plugin<Array<Array<string>>, Root>} */
const plugin = () => () => {}

const actual = asHtml(
<Markdown children={input} rehypePlugins={[[plugin, ['foo', 'bar']]]} />
)
const expected = '<p>a</p>'
assert.equal(actual, expected)

assert.not.match(message, /Warning: Failed/, 'Prop types should be valid')
console.error = error
})

test.run()

0 comments on commit a2fb833

Please sign in to comment.