html-eslint icon indicating copy to clipboard operation
html-eslint copied to clipboard

[Feature Request] Add to each attr a conditionality option for require-attrs rule

Open RPComputer opened this issue 1 year ago • 6 comments

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?

RPComputer avatar Dec 12 '23 11:12 RPComputer

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?

yeonjuan avatar Dec 12 '23 13:12 yeonjuan

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?

RPComputer avatar Dec 12 '23 16:12 RPComputer

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..!

yeonjuan avatar Dec 13 '23 11:12 yeonjuan

Hi @yeonjuan! Sounds good to avoid breaking changes. Should I try to implement it or you want to take care yourself?

RPComputer avatar Dec 13 '23 15:12 RPComputer

@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.

yeonjuan avatar Dec 13 '23 15:12 yeonjuan

Hi @yeonjuan, I'll see what can I do and if it works I'll make a PR.

RPComputer avatar Dec 15 '23 09:12 RPComputer