diff --git a/rules/attr-req-value/README.md b/rules/attr-req-value/README.md index 8c914ca..7d4809a 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 + + + + + + + + + + + + + diff --git a/rules/attr-req-value/index.js b/rules/attr-req-value/index.js index 190d17a..098adec 100644 --- a/rules/attr-req-value/index.js +++ b/rules/attr-req-value/index.js @@ -13,6 +13,17 @@ const matchesIgnoreList = (attributeName, ignoreList) => ignoreList.some((ignore } }); +const isValidOptionValue = (node, name) => { + if (name !== 'value' || !node.parent || node.parent.tagName !== 'select') { + return true; + } + + const emptyOptions = node.parent.children.filter((child) => + child.tagName === 'option' && !has_non_empty_attribute(child, 'value') + ); + + return emptyOptions.length > 1; +}; module.exports = { name: 'htmlacademy/attr-req-value', @@ -24,17 +35,18 @@ module.exports = { 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 (isValidOptionValue(node, name)) { + report({ + code: 'E006', + position: attribute.loc, + meta: { + data: { + attribute: name, + }, }, - }, - }); + }); + } } }); }