diff --git a/lib/rules/require-meta-schema.js b/lib/rules/require-meta-schema.js index 0789bc6a..1f5b52d9 100644 --- a/lib/rules/require-meta-schema.js +++ b/lib/rules/require-meta-schema.js @@ -104,7 +104,16 @@ module.exports = { hasEmptySchema = true; } - if (!['ArrayExpression', 'ObjectExpression'].includes(value.type)) { + if ( + ![ + 'ArrayExpression', + 'CallExpression', + 'ConditionalExpression', + 'LogicalExpression', + 'MemberExpression', + 'ObjectExpression', + ].includes(value.type) + ) { context.report({ node: value, messageId: 'wrongType' }); } }, diff --git a/tests/lib/rules/require-meta-schema.js b/tests/lib/rules/require-meta-schema.js index a0c2a4d0..8558c7d7 100644 --- a/tests/lib/rules/require-meta-schema.js +++ b/tests/lib/rules/require-meta-schema.js @@ -63,6 +63,7 @@ ruleTester.run('require-meta-schema', rule, { `, parserOptions: { sourceType: 'module' }, }, + // Variable schema with array value. ` const schema = []; module.exports = { @@ -70,6 +71,7 @@ ruleTester.run('require-meta-schema', rule, { create(context) {} }; `, + // Variable schema with object value. ` const foo = {}; module.exports = { @@ -77,6 +79,41 @@ ruleTester.run('require-meta-schema', rule, { create(context) {} }; `, + // Variable schema with no static value. + ` + module.exports = { + meta: { schema }, + create(context) {} + }; + `, + // Variable schema pointing to unknown variable chain. + ` + module.exports = { + meta: { schema: baseRule.meta.schema }, + create(context) {} + }; + `, + // Schema with function call as value. + ` + module.exports = { + meta: { schema: getSchema() }, + create(context) {} + }; + `, + // Schema with ternary (conditional) expression. + ` + module.exports = { + meta: { schema: foo ? [] : {} }, + create(context) {} + }; + `, + // Schema with logical expression. + ` + module.exports = { + meta: { schema: foo || {} }, + create(context) {} + }; + `, ` let schema; schema = foo ? [] : {}; @@ -296,6 +333,28 @@ schema: [] }, output: null, errors: [{ messageId: 'wrongType', type: 'Identifier', suggestions: [] }], }, + { + // Schema with number literal value. + code: ` + module.exports = { + meta: { schema: 123 }, + create(context) {} + }; + `, + output: null, + errors: [{ messageId: 'wrongType', type: 'Literal', suggestions: [] }], + }, + { + // Schema with string literal value. + code: ` + module.exports = { + meta: { schema: 'hello world' }, + create(context) {} + }; + `, + output: null, + errors: [{ messageId: 'wrongType', type: 'Literal', suggestions: [] }], + }, { code: ` const schema = null;