html-eslint
html-eslint copied to clipboard
[Feature Request] Add to each attr a conditionality option for require-attrs rule
Hello, I think that it would be interesting to add to the require-attrs rule the conditionality option for requirement.
For example:
Given the element: <element attr1="v1">
Rule setting:
{
"tag": "element",
"attr": "attr2",
"conditions":[
{
"attr": "attr1"
"value": "v1",
"kind": "present"
}
]
}
This would make the attr2 attribute required for the element tag only if the attr1 attribute is present with value v1. Another possibility could be the reverse: if an attribute is present/not present the following list of attributes are required. I know that the conditions possibilities might escalate quickly but supporting a couple of basic ifs would be very helpful.
What do you think?
Hi! @RPComputer Thanks for the suggestion!. This seems like a nice feature. I think it should check with AND condition when there are multiple conditions. What do you think?
Hi @yeonjuan, yes as default condition logical join AND sounds right! I'm uncertain for the configuration logic order of the conditioned attrs: should the configuration put requirements under a logic condition or each attribute should have its optional condition? For simplicity it might be easier the first option, what do you think?
Hi @RPComputer
each attribute should have its optional condition?
For now, I think the second option is appropriate because the first option would make a breaking change..!
Hi @yeonjuan! Sounds good to avoid breaking changes. Should I try to implement it or you want to take care yourself?
@RPComputer If you'd like to implement it yourself, I'd be very grateful for a PR 👍 , otherwise I'll implement it myself, but it may delay the completion of the implementation a bit.
Hi @yeonjuan, I'll see what can I do and if it works I'll make a PR.