Skip to content

Commit 713df13

Browse files
committed
implement
1 parent c3dd876 commit 713df13

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

packages/eslint-plugin/lib/rules/use-standard-html/check-content-model.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ function checkContentModel(context, spec, node, children) {
6262
};
6363
let result = CONTINUE;
6464
while (result && state.contentModels && !!getContentModel(state)) {
65+
debugger;
6566
const contentModel = getContentModel(state);
6667
if (!contentModel) {
6768
return;
@@ -80,7 +81,7 @@ function checkContentModel(context, spec, node, children) {
8081
break;
8182
}
8283
case "optional": {
83-
result = optional(state);
84+
result = optional(contentModel, state);
8485
break;
8586
}
8687
case "either": {
@@ -204,17 +205,22 @@ function oneOrMore(model, context, state, node) {
204205
}
205206

206207
/**
208+
* @param {ContentModel & {type: "optional"}} model
207209
* @param {State} state
208210
* @returns {boolean}
209211
*/
210-
function optional(state) {
212+
function optional(model, state) {
211213
let child = getChild(state);
212214
if (!child) {
213215
state.childIndex++;
214216
state.contentModelIndex++;
215217
return CONTINUE;
216218
}
217-
state.childIndex++;
219+
const name = getNodeName(child);
220+
if (model.contents.has(name)) {
221+
state.childIndex++;
222+
}
223+
218224
state.contentModelIndex++;
219225
return CONTINUE;
220226
}

packages/eslint-plugin/tests/rules/use-standard-html.test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ ruleTester.run("use-standard-html", rule, {
2929
{
3030
code: `<mark>text<br/></mark>`,
3131
},
32+
{
33+
code: `<fieldset><legend></legend></fieldset>`,
34+
},
3235
],
3336
invalid: [
3437
// required
@@ -66,5 +69,13 @@ ruleTester.run("use-standard-html", rule, {
6669
},
6770
],
6871
},
72+
{
73+
code: `<fieldset><base></base></fieldset>`,
74+
errors: [
75+
{
76+
messageId: "required",
77+
},
78+
],
79+
},
6980
],
7081
});

0 commit comments

Comments
 (0)