From 9f2f1091ede9bd45f7838598612b7adf4c2c9ce0 Mon Sep 17 00:00:00 2001 From: Bryan Mishkin <698306+bmish@users.noreply.github.com> Date: Wed, 15 Jan 2020 20:48:15 -0800 Subject: [PATCH] fix: update `require-meta-schema` rule to allow object schemas (in addition to array schemas) Turns out that eslint supports both array and object schemas. eslint itself has a handful of rules that use objects schemas, although array schemas are much more common. https://eslint.org/docs/developer-guide/working-with-rules#options-schemas --- lib/rules/require-meta-schema.js | 4 ++-- tests/lib/rules/require-meta-schema.js | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/rules/require-meta-schema.js b/lib/rules/require-meta-schema.js index a4d5def9..01510520 100644 --- a/lib/rules/require-meta-schema.js +++ b/lib/rules/require-meta-schema.js @@ -28,7 +28,7 @@ module.exports = { ], messages: { missing: '`meta.schema` is required (use [] if rule has no schema).', - wrongType: '`meta.schema` should be an array (use [] if rule has no schema).', + wrongType: '`meta.schema` should be an array or object (use [] if rule has no schema).', }, }, @@ -56,7 +56,7 @@ module.exports = { return utils.insertProperty(fixer, metaNode, 'schema: []', sourceCode); }, }); - } else if (schemaNode.value.type !== 'ArrayExpression') { + } else if (!['ArrayExpression', 'ObjectExpression'].includes(schemaNode.value.type)) { context.report({ node: schemaNode.value, messageId: 'wrongType' }); } }, diff --git a/tests/lib/rules/require-meta-schema.js b/tests/lib/rules/require-meta-schema.js index 21acd912..db79efba 100644 --- a/tests/lib/rules/require-meta-schema.js +++ b/tests/lib/rules/require-meta-schema.js @@ -26,6 +26,12 @@ ruleTester.run('require-meta-schema', rule, { create(context) {} }; `, + ` + module.exports = { + meta: { schema: { "enum": ["always", "never"] } }, + create(context) {} + }; + `, ], invalid: [