From b54ed498e9ba2e60bf0554354c15e4a29fbb917e Mon Sep 17 00:00:00 2001 From: Nikolai Shabalin Date: Fri, 12 Jan 2024 22:26:11 +0300 Subject: [PATCH 1/5] Adds a validation condition for htmlacademy/attr-req-value --- rules/attr-req-value/index.js | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/rules/attr-req-value/index.js b/rules/attr-req-value/index.js index 190d17a..d3ddac1 100644 --- a/rules/attr-req-value/index.js +++ b/rules/attr-req-value/index.js @@ -13,28 +13,38 @@ const matchesIgnoreList = (attributeName, ignoreList) => ignoreList.some((ignore } }); +const hasMultipleEmptyOptions = (node) => { + if (node.parent && node.parent.tagName === 'select') { + const emptyOptions = node.parent.children.filter((child) => + child.tagName === 'option' && !has_non_empty_attribute(child, 'value') + ); + return emptyOptions.length > 1; + } + return false; +}; module.exports = { name: 'htmlacademy/attr-req-value', // eslint-disable-next-line camelcase - lint(node, rule_config, { report }) { + lint(node, rule_config, { report }){ if (is_tag_node(node)) { - const attributes = node.attributes.filter(({ name }) => /^¤+$/.test(name.chars) === false); + const attributes = node.attributes.filter(({ name }) => !/^¤+$/.test(name.chars)); attributes.forEach((attribute) => { const name = attribute.name.chars.toLowerCase(); // eslint-disable-next-line camelcase - if (!has_non_empty_attribute(node, name) && !is_boolean_attribute(attribute) && !matchesIgnoreList(name, rule_config.ignore) - ) { - report({ - code: 'E006', - position: attribute.loc, - meta: { - data: { - attribute: name, + if (!has_non_empty_attribute(node, name) && !is_boolean_attribute(attribute) && !matchesIgnoreList(name, rule_config.ignore)) { + if (!(name === 'value' && node.parent && node.parent.tagName === 'select' && !hasMultipleEmptyOptions(node))) { + report({ + code: 'E006', + position: attribute.loc, + meta: { + data: { + attribute: name, + }, }, - }, - }); + }); + } } }); } From 43ca19945cb0fc3bc627e77b63d4f7b6566b67ef Mon Sep 17 00:00:00 2001 From: Nikolai Shabalin Date: Fri, 12 Jan 2024 22:28:51 +0300 Subject: [PATCH 2/5] Update examples --- rules/attr-req-value/README.md | 14 ++++++++++++ rules/attr-req-value/fixture/error.html | 19 +++++++++++++++ rules/attr-req-value/fixture/success.html | 28 +++++++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 rules/attr-req-value/fixture/error.html create mode 100644 rules/attr-req-value/fixture/success.html diff --git a/rules/attr-req-value/README.md b/rules/attr-req-value/README.md index 8c914ca..32ae8a1 100644 --- a/rules/attr-req-value/README.md +++ b/rules/attr-req-value/README.md @@ -51,3 +51,17 @@
``` + +## Исключения +Один ` + + + +``` diff --git a/rules/attr-req-value/fixture/error.html b/rules/attr-req-value/fixture/error.html new file mode 100644 index 0000000..8c2648d --- /dev/null +++ b/rules/attr-req-value/fixture/error.html @@ -0,0 +1,19 @@ + + + + + Document + + + + + + + + + diff --git a/rules/attr-req-value/fixture/success.html b/rules/attr-req-value/fixture/success.html new file mode 100644 index 0000000..1336952 --- /dev/null +++ b/rules/attr-req-value/fixture/success.html @@ -0,0 +1,28 @@ + + + + + Document + + + + + + + + + + + + + From 9adcd3962a578e307ef832b0ebf67dc7de986a88 Mon Sep 17 00:00:00 2001 From: Nikolai Shabalin Date: Fri, 12 Jan 2024 22:35:29 +0300 Subject: [PATCH 3/5] Update description --- rules/attr-req-value/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rules/attr-req-value/README.md b/rules/attr-req-value/README.md index 32ae8a1..7d4809a 100644 --- a/rules/attr-req-value/README.md +++ b/rules/attr-req-value/README.md @@ -53,7 +53,7 @@ ``` ## Исключения -Один `