Skip to content

Commit

Permalink
Fix: update require-meta-schema rule to allow object schemas (in ad…
Browse files Browse the repository at this point in the history
…dition 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
  • Loading branch information
bmish authored and not-an-aardvark committed Jan 17, 2020
1 parent 122d67e commit e582cb6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/rules/require-meta-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -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).',
},
},

Expand Down Expand Up @@ -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' });
}
},
Expand Down
6 changes: 6 additions & 0 deletions tests/lib/rules/require-meta-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ ruleTester.run('require-meta-schema', rule, {
create(context) {}
};
`,
`
module.exports = {
meta: { schema: { "enum": ["always", "never"] } },
create(context) {}
};
`,
],

invalid: [
Expand Down

0 comments on commit e582cb6

Please sign in to comment.