Skip to content

Commit e582cb6

Browse files
bmishnot-an-aardvark
authored andcommitted
Fix: update require-meta-schema rule to allow object schemas (in addition to array schemas) (#90)
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
1 parent 122d67e commit e582cb6

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

lib/rules/require-meta-schema.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ module.exports = {
2828
],
2929
messages: {
3030
missing: '`meta.schema` is required (use [] if rule has no schema).',
31-
wrongType: '`meta.schema` should be an array (use [] if rule has no schema).',
31+
wrongType: '`meta.schema` should be an array or object (use [] if rule has no schema).',
3232
},
3333
},
3434

@@ -56,7 +56,7 @@ module.exports = {
5656
return utils.insertProperty(fixer, metaNode, 'schema: []', sourceCode);
5757
},
5858
});
59-
} else if (schemaNode.value.type !== 'ArrayExpression') {
59+
} else if (!['ArrayExpression', 'ObjectExpression'].includes(schemaNode.value.type)) {
6060
context.report({ node: schemaNode.value, messageId: 'wrongType' });
6161
}
6262
},

tests/lib/rules/require-meta-schema.js

+6
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ ruleTester.run('require-meta-schema', rule, {
2626
create(context) {}
2727
};
2828
`,
29+
`
30+
module.exports = {
31+
meta: { schema: { "enum": ["always", "never"] } },
32+
create(context) {}
33+
};
34+
`,
2935
],
3036

3137
invalid: [

0 commit comments

Comments
 (0)