Skip to content

Commit 8d9f8d3

Browse files
committed
Apply PR Feedback
1 parent b63b79d commit 8d9f8d3

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

lib/rules/template-no-forbidden-elements.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,17 @@ module.exports = {
1414
},
1515
schema: [
1616
{
17-
oneOf: [{ type: 'array', items: { type: 'string' } }, { type: 'boolean' }],
17+
oneOf: [
18+
{ type: 'array', items: { type: 'string' } },
19+
{ type: 'boolean' },
20+
{
21+
type: 'object',
22+
properties: {
23+
forbidden: { type: 'array', items: { type: 'string' } },
24+
},
25+
additionalProperties: false,
26+
},
27+
],
1828
},
1929
],
2030
messages: { forbidden: 'Use of forbidden element <{{element}}>' },
@@ -33,6 +43,8 @@ module.exports = {
3343
forbiddenList = DEFAULT_FORBIDDEN;
3444
} else if (Array.isArray(rawConfig)) {
3545
forbiddenList = rawConfig;
46+
} else if (rawConfig && typeof rawConfig === 'object') {
47+
forbiddenList = rawConfig.forbidden ?? DEFAULT_FORBIDDEN;
3648
} else {
3749
forbiddenList = [];
3850
}

tests/lib/rules/template-no-forbidden-elements.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,21 @@ const ruleTester = new RuleTester({
88
ruleTester.run('template-no-forbidden-elements', rule, {
99
valid: [
1010
{ code: '<template><div></div></template>', options: [['script']] },
11+
// Object config form
12+
{ code: '<template><div></div></template>', options: [{ forbidden: ['script'] }] },
13+
{ code: '<template><script></script></template>', options: [{ forbidden: ['html'] }] },
1114
'<template><header></header></template>',
1215
'<template><footer></footer></template>',
1316
'<template><p></p></template>',
1417
'<template><head><meta charset="utf-8"></head></template>',
1518
],
1619
invalid: [
20+
{
21+
code: '<template><script></script></template>',
22+
output: null,
23+
options: [{ forbidden: ['script'] }],
24+
errors: [{ messageId: 'forbidden' }],
25+
},
1726
{
1827
code: '<template><script></script></template>',
1928
output: null,
@@ -70,6 +79,11 @@ hbsRuleTester.run('template-no-forbidden-elements', rule, {
7079
code: '<script></script>',
7180
options: [['html', 'meta', 'style']],
7281
},
82+
// Object config form.
83+
{
84+
code: '<script></script>',
85+
options: [{ forbidden: ['html', 'meta', 'style'] }],
86+
},
7387
],
7488
invalid: [
7589
// Default config.

0 commit comments

Comments
 (0)