From 665b681e197d3fbd178f852d42e54205dfe18c7a Mon Sep 17 00:00:00 2001 From: YeonJuan Date: Wed, 1 Jan 2025 19:30:05 +0900 Subject: [PATCH] implement --- docs/rules/no-nested-interactive.md | 15 +++++++++++++++ .../lib/rules/no-nested-interactive.js | 12 ++++++++++-- .../tests/rules/no-nested-interactive.test.js | 14 ++++++++++++++ 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/docs/rules/no-nested-interactive.md b/docs/rules/no-nested-interactive.md index ecfd60d..1e243e2 100644 --- a/docs/rules/no-nested-interactive.md +++ b/docs/rules/no-nested-interactive.md @@ -19,3 +19,18 @@ module.exports = { ``` ## Rule Details + +Examples of **incorrect** code for this rule: + +```html,incorrect + + + +``` + +Examples of **correct** code for this rule: + +```html,correct + +
+``` diff --git a/packages/eslint-plugin/lib/rules/no-nested-interactive.js b/packages/eslint-plugin/lib/rules/no-nested-interactive.js index 0a48916..5628bbe 100644 --- a/packages/eslint-plugin/lib/rules/no-nested-interactive.js +++ b/packages/eslint-plugin/lib/rules/no-nested-interactive.js @@ -90,12 +90,20 @@ module.exports = { return; } if (interactiveStack.length) { - const parent = interactiveStack[interactiveStack.length - 1]; + if (interactiveStack.length === 1) { + const parentLabel = interactiveStack.find( + (tag) => tag.name.toLowerCase() === "label" + ); + if (parentLabel && node.name.toLowerCase() !== "label") { + return; + } + } + context.report({ node, messageId: MESSAGE_IDS.UNEXPECTED, data: { - tag: parent.name, + tag: interactiveStack[interactiveStack.length - 1].name, }, }); } diff --git a/packages/eslint-plugin/tests/rules/no-nested-interactive.test.js b/packages/eslint-plugin/tests/rules/no-nested-interactive.test.js index c7dc0a8..4006e98 100644 --- a/packages/eslint-plugin/tests/rules/no-nested-interactive.test.js +++ b/packages/eslint-plugin/tests/rules/no-nested-interactive.test.js @@ -27,6 +27,9 @@ ruleTester.run("no-nested-interactive", rule, { { code: "", }, + { + code: "", + }, ], invalid: [ { @@ -62,6 +65,17 @@ ruleTester.run("no-nested-interactive", rule, { }, ], }, + { + code: "", + errors: [ + { + messageId: "unexpected", + data: { + tag: "button", + }, + }, + ], + }, ], });